|
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'; |
3 | 3 | import { JwtPayload } from '../../../src/core/JWT';
|
4 | 4 | import { tokenInfo } from '../../../src/config';
|
5 | 5 | import { Types } from 'mongoose';
|
6 | 6 | import { AuthFailureError } from '../../../src/core/ApiError';
|
| 7 | +import { IUser } from '../../../src/database/model/User'; |
7 | 8 |
|
8 | 9 | describe('authUtils validateTokenData tests', () => {
|
9 | 10 |
|
| 11 | + beforeAll(() => { |
| 12 | + jest.resetAllMocks(); |
| 13 | + }); |
| 14 | + |
10 | 15 | it('Should throw error when user is different', async () => {
|
11 | 16 |
|
12 | 17 | const userId = new Types.ObjectId(); // Random Key
|
@@ -62,3 +67,21 @@ describe('authUtils validateTokenData tests', () => {
|
62 | 67 | expect(validatedPayload).toMatchObject(payload);
|
63 | 68 | });
|
64 | 69 | });
|
| 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