Skip to content

Commit

Permalink
covered token creation failure case
Browse files Browse the repository at this point in the history
  • Loading branch information
Pavangbhat committed Mar 5, 2024
1 parent fc6c42a commit 63fda8f
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions src/tests/utils/apiCaller.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { RDS_BASE_DEVELOPMENT_API_URL } from '../../constants/urls';
import { env } from '../../types/global.types';
import { apiCaller } from '../../utils/apiCaller';
import { generateJwt } from '../../utils/generateJwt';
import * as generateJwtModule from '../../utils/generateJwt';

jest.mock('../../utils/generateJwt', () => ({
generateJwt: jest.fn().mockResolvedValue('mocked-token'),
Expand Down Expand Up @@ -67,4 +68,11 @@ describe('apiCaller', () => {

consoleErrorSpy.mockRestore();
});

it('should handle the case where generateJwt returns undefined and throw an error', async () => {
const generateJwtMock = jest.spyOn(generateJwtModule, 'generateJwt');
generateJwtMock.mockImplementationOnce(() => Promise.reject(new Error('Generate JWT error')));

await expect(apiCaller(mockEnv, 'someEndpoint', 'GET')).rejects.toThrow('Generate JWT error');
});
});

0 comments on commit 63fda8f

Please sign in to comment.