From 87a049c6d15e928e239fb547e7589e881f9bb12b Mon Sep 17 00:00:00 2001 From: Bartosz Dokurno Date: Sun, 14 Apr 2024 14:23:02 +0200 Subject: [PATCH] Add `UsersService` tests --- .../src/models/users/users.service.spec.ts | 29 +++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/apps/api/src/models/users/users.service.spec.ts b/apps/api/src/models/users/users.service.spec.ts index 251bc8f..d7c21d9 100644 --- a/apps/api/src/models/users/users.service.spec.ts +++ b/apps/api/src/models/users/users.service.spec.ts @@ -6,6 +6,7 @@ import { ImagesService } from '../../images/images.service'; import { MockUserRepository } from './mocks/mock-user-repository'; import { UserRepository } from './users.repository'; import { UsersService } from './users.service'; +import { UpdateUserDto } from './dto/update-user.dto'; describe('UsersService', () => { let service: UsersService; @@ -14,6 +15,7 @@ describe('UsersService', () => { const mockImagesService = { uploadImage: jest.fn(() => 'key'), + handleImageDtoAndGetKey: jest.fn(() => 'key'), deleteImage: jest.fn(), }; @@ -106,4 +108,31 @@ describe('UsersService', () => { ); expect(emitSpy).toBeCalledWith('user.deleted', expect.anything()); }); + + it('should find user by email', async () => { + const user = await service.findByEmail('test@dokurno.dev'); + + expect(user.profile.username).toStrictEqual(expect.any(String)); + }); + + it('should find user', async () => { + const users = await service.find({ username: 'test' }); + + expect(users[0].profile.username).toStrictEqual(expect.any(String)); + }); + + it('should check if email is taken', async () => { + const taken = await service.isEmailTaken('test@dokurno.dev'); + expect(taken).toBe(true); + }); + + it('should check if username is taken', async () => { + const taken = await service.isUsernameTaken('test'); + expect(taken).toBe(true); + }); + + it('should activate account', async () => { + const user = await service.setConfirmed(new Types.ObjectId(), true); + expect(user.profile.username).toStrictEqual(expect.any(String)); + }); });