Skip to content

Commit

Permalink
Add UsersService tests
Browse files Browse the repository at this point in the history
  • Loading branch information
MrBartusek committed Apr 14, 2024
1 parent 236b7e3 commit 87a049c
Showing 1 changed file with 29 additions and 0 deletions.
29 changes: 29 additions & 0 deletions apps/api/src/models/users/users.service.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Check warning on line 9 in apps/api/src/models/users/users.service.spec.ts

View workflow job for this annotation

GitHub Actions / Lint

'UpdateUserDto' is defined but never used

describe('UsersService', () => {
let service: UsersService;
Expand All @@ -14,6 +15,7 @@ describe('UsersService', () => {

const mockImagesService = {
uploadImage: jest.fn(() => 'key'),
handleImageDtoAndGetKey: jest.fn(() => 'key'),
deleteImage: jest.fn(),
};

Expand Down Expand Up @@ -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));
});
});

0 comments on commit 87a049c

Please sign in to comment.