Skip to content

Commit

Permalink
handle no new netki codes in a page
Browse files Browse the repository at this point in the history
  • Loading branch information
polymath-eric committed Jul 8, 2024
1 parent 045328a commit 6150013
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 2 deletions.
28 changes: 28 additions & 0 deletions apps/cdd-backend/src/netki/netki.service.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,34 @@ describe('NetkiService', () => {
]);
});

it('should not call redis if no new codes are added', async () => {
const mockResponse = {
data: {
results: [
{
id: '345',
code: 'def',
created: new Date().toISOString(),
parent_code: null,
},
],
},
} as AxiosResponse;

jest.spyOn(mockHttp, 'get').mockImplementation(() => of(mockResponse));
jest
.spyOn(mockHttp, 'post')
.mockImplementation(() => of(mockAccessResponse));

mockRedis.getAllocatedNetkiCodes.mockResolvedValue(new Set(['def']));
mockRedis.pushNetkiCodes.mockResolvedValue(1);

const result = await service.fetchAccessCodes();

expect(result).toEqual({ added: 0, total: 2 });
expect(mockRedis.pushNetkiCodes).not.toHaveBeenCalled();
});

it('should loop through all of the pages', async () => {
const mockPageOne = {
data: {
Expand Down
6 changes: 4 additions & 2 deletions apps/cdd-backend/src/netki/netki.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -153,8 +153,10 @@ export class NetkiService {
isActive,
}));

const codesAdded = await this.redis.pushNetkiCodes(newLinks);
added += codesAdded;
if (newLinks.length) {
const codesAdded = await this.redis.pushNetkiCodes(newLinks);
added += codesAdded;
}

if (codeResponse.data.next) {
url = codeResponse.data.next;
Expand Down

0 comments on commit 6150013

Please sign in to comment.