From d9b42149a08c848e2a0bae468623bcf933ac5d53 Mon Sep 17 00:00:00 2001 From: Usame Algan Date: Fri, 22 Nov 2024 14:56:36 +0100 Subject: [PATCH] Add more unit tests for fingerprint-api service --- .../fingerprint-api.service.spec.ts | 66 +++++++++++++++++++ 1 file changed, 66 insertions(+) diff --git a/src/datasources/locking-api/fingerprint-api.service.spec.ts b/src/datasources/locking-api/fingerprint-api.service.spec.ts index fa1c16f626..d4e2b1658f 100644 --- a/src/datasources/locking-api/fingerprint-api.service.spec.ts +++ b/src/datasources/locking-api/fingerprint-api.service.spec.ts @@ -211,5 +211,71 @@ describe('FingerprintApiService', () => { isVpn: vpn.data?.result, }); }); + + it('should return isVpn:false for a low confidence score', async () => { + const eligibilityRequest = eligibilityRequestBuilder().build(); + const unsealedData = fingerprintUnsealedDataBuilder() + .with('products', { + ipInfo: null, + locationSpoofing: fingerprintLocationSpoofingBuilder().build(), + vpn: fingerprintVpnBuilder() + .with('data', { result: true, confidence: 'low' }) + .build(), + }) + .build(); + (unsealEventsResponse as jest.Mock).mockResolvedValue(unsealedData); + + const result = await service.checkEligibility(eligibilityRequest); + + expect(result).toEqual({ + requestId: eligibilityRequest.requestId, + isAllowed: expect.anything(), + isVpn: false, + }); + }); + + it('should return isVpn:false for a medium confidence score', async () => { + const eligibilityRequest = eligibilityRequestBuilder().build(); + const unsealedData = fingerprintUnsealedDataBuilder() + .with('products', { + ipInfo: null, + locationSpoofing: fingerprintLocationSpoofingBuilder().build(), + vpn: fingerprintVpnBuilder() + .with('data', { result: true, confidence: 'medium' }) + .build(), + }) + .build(); + (unsealEventsResponse as jest.Mock).mockResolvedValue(unsealedData); + + const result = await service.checkEligibility(eligibilityRequest); + + expect(result).toEqual({ + requestId: eligibilityRequest.requestId, + isAllowed: expect.anything(), + isVpn: false, + }); + }); + + it('should return isVpn:true for a high confidence score', async () => { + const eligibilityRequest = eligibilityRequestBuilder().build(); + const unsealedData = fingerprintUnsealedDataBuilder() + .with('products', { + ipInfo: null, + locationSpoofing: fingerprintLocationSpoofingBuilder().build(), + vpn: fingerprintVpnBuilder() + .with('data', { result: true, confidence: 'high' }) + .build(), + }) + .build(); + (unsealEventsResponse as jest.Mock).mockResolvedValue(unsealedData); + + const result = await service.checkEligibility(eligibilityRequest); + + expect(result).toEqual({ + requestId: eligibilityRequest.requestId, + isAllowed: expect.anything(), + isVpn: true, + }); + }); }); });