Skip to content

Commit 5acbd89

Browse files
committed
add authUtils createTokens tests
1 parent af96d44 commit 5acbd89

File tree

1 file changed

+25
-2
lines changed

1 file changed

+25
-2
lines changed

tests/auth/authUtils/index.test.ts

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,17 @@
1-
import { ACCESS_TOKEN_KEY } from './mock';
2-
import { validateTokenData } from '../../../src/auth/authUtils';
1+
import { ACCESS_TOKEN_KEY, REFRESH_TOKEN_KEY } from './mock';
2+
import { validateTokenData, createTokens } from '../../../src/auth/authUtils';
33
import { JwtPayload } from '../../../src/core/JWT';
44
import { tokenInfo } from '../../../src/config';
55
import { Types } from 'mongoose';
66
import { AuthFailureError } from '../../../src/core/ApiError';
7+
import { IUser } from '../../../src/database/model/User';
78

89
describe('authUtils validateTokenData tests', () => {
910

11+
beforeAll(() => {
12+
jest.resetAllMocks();
13+
});
14+
1015
it('Should throw error when user is different', async () => {
1116

1217
const userId = new Types.ObjectId(); // Random Key
@@ -62,3 +67,21 @@ describe('authUtils validateTokenData tests', () => {
6267
expect(validatedPayload).toMatchObject(payload);
6368
});
6469
});
70+
71+
72+
describe('authUtils createTokens function', () => {
73+
74+
beforeAll(() => {
75+
jest.resetAllMocks();
76+
});
77+
78+
it('Should process and return accessToken and refreshToken', async () => {
79+
80+
const userId = new Types.ObjectId('553f8a4286f5c759f36f8e5b'); // Random Key
81+
82+
const tokens = await createTokens(<IUser>{ _id: userId }, ACCESS_TOKEN_KEY, REFRESH_TOKEN_KEY);
83+
84+
expect(tokens).toHaveProperty('accessToken');
85+
expect(tokens).toHaveProperty('refreshToken');
86+
});
87+
});

0 commit comments

Comments
 (0)