Skip to content

Commit cf8ac58

Browse files
committed
chore: add test
1 parent 267ac54 commit cf8ac58

File tree

1 file changed

+41
-0
lines changed

1 file changed

+41
-0
lines changed

packages/connectivity/src/scp-cf/destination/destination-accessor-provider-subscriber-lookup.spec.ts

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -368,6 +368,7 @@ describe('call getAllDestinations with and without subscriber token', () => {
368368
});
369369

370370
expect(allDestinations).toEqual([parsedSubscriberDestination]);
371+
expect(retrieveSpy).toHaveBeenCalled();
371372
expect(cacheSpy).toHaveBeenCalled();
372373
expect(debugSpy).toHaveBeenCalledWith(
373374
'Retrieving all destinations for account: "subscriber" from destination service.'
@@ -389,6 +390,46 @@ describe('call getAllDestinations with and without subscriber token', () => {
389390
expect(cacheSpy).not.toHaveBeenCalled(); // Should not cache again
390391
});
391392

393+
it('should fetch all subscriber destinations and not cache destinations', async () => {
394+
mockGetAllSubscriber();
395+
mockGetAllProvider();
396+
397+
const cacheSpy = jest.spyOn(
398+
destinationServiceCache,
399+
'cacheRetrievedDestinations'
400+
);
401+
402+
const retrieveSpy = jest.spyOn(
403+
destinationServiceCache,
404+
'retrieveDestinationsFromCache'
405+
);
406+
407+
let allDestinations = await getAllDestinationsFromDestinationService({
408+
jwt: subscriberUserToken,
409+
useCache: false
410+
});
411+
412+
expect(allDestinations).toEqual([parsedSubscriberDestination]);
413+
expect(cacheSpy).not.toHaveBeenCalled();
414+
expect(retrieveSpy).not.toHaveBeenCalled();
415+
416+
// Reset spies and mocks for second call
417+
jest.clearAllMocks();
418+
nock.cleanAll();
419+
mockGetAllSubscriber();
420+
mockGetAllProvider();
421+
422+
// Second call - should fetch again since cache was not used previously
423+
allDestinations = await getAllDestinationsFromDestinationService({
424+
jwt: subscriberUserToken,
425+
useCache: false
426+
});
427+
428+
expect(allDestinations).toEqual([parsedSubscriberDestination]);
429+
expect(cacheSpy).not.toHaveBeenCalled();
430+
expect(retrieveSpy).not.toHaveBeenCalled();
431+
});
432+
392433
it('should fetch all provider destinations when called without passing a JWT', async () => {
393434
mockGetAllSubscriber();
394435
mockGetAllProvider();

0 commit comments

Comments
 (0)