From 374d7958bbb94f08478d36c559c427074819fac2 Mon Sep 17 00:00:00 2001 From: Olavio Date: Fri, 1 Mar 2024 17:07:54 -0300 Subject: [PATCH] test: add unit testing for helpers --- .../providers/helpers/auth.helper.spec.ts | 37 +++++++++++++++++++ .../providers/services/users.service.spec.ts | 4 ++ 2 files changed, 41 insertions(+) create mode 100644 test/unit/providers/helpers/auth.helper.spec.ts diff --git a/test/unit/providers/helpers/auth.helper.spec.ts b/test/unit/providers/helpers/auth.helper.spec.ts new file mode 100644 index 0000000..cb2dbba --- /dev/null +++ b/test/unit/providers/helpers/auth.helper.spec.ts @@ -0,0 +1,37 @@ +import { AuthHelper } from '../../../../src/core/providers/helpers/auth.helper'; + +jest.mock('bcrypt', () => ({ + async hashSync(): Promise { + return 'hash'; + }, +})); + +jest.mock('crypto', () => ({ + createHash: jest.fn().mockReturnValue({ + update: jest.fn().mockReturnThis(), + digest: jest.fn(), + }), +})); + +describe('AuthHelper', () => { + let helper: AuthHelper; + + beforeEach(async () => { + helper = new AuthHelper(); + }); + + afterEach(() => { + jest.clearAllMocks(); + }); + + it('should be defined', () => { + expect(helper).toBeDefined(); + }); + + it('should hash token', async () => { + const refreshToken = 'refreshToken'; + const hashedToken = await helper.hashToken(refreshToken); + + expect(hashedToken).toBe('hash'); + }); +}); diff --git a/test/unit/providers/services/users.service.spec.ts b/test/unit/providers/services/users.service.spec.ts index 62e338f..3314f93 100644 --- a/test/unit/providers/services/users.service.spec.ts +++ b/test/unit/providers/services/users.service.spec.ts @@ -27,6 +27,10 @@ describe('UsersService', () => { repository = module.get(getRepositoryToken(User)); }); + afterEach(() => { + jest.clearAllMocks(); + }); + it('should be defined', () => { expect(service).toBeDefined(); });