Skip to content

Commit

Permalink
Add more unit tests for fingerprint-api service
Browse files Browse the repository at this point in the history
  • Loading branch information
usame-algan committed Nov 22, 2024
1 parent 9c5d9f3 commit d9b4214
Showing 1 changed file with 66 additions and 0 deletions.
66 changes: 66 additions & 0 deletions src/datasources/locking-api/fingerprint-api.service.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
});
});
});
});

0 comments on commit d9b4214

Please sign in to comment.