-
Notifications
You must be signed in to change notification settings - Fork 49
/
auth.service.spec.ts
53 lines (43 loc) · 1.25 KB
/
auth.service.spec.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
import { Test } from '@nestjs/testing';
import { AuthModule } from '../auth.module';
import { AuthService } from '../auth.service';
import { getModelToken } from '@nestjs/mongoose';
import mongoose from 'mongoose';
describe('auth', () => {
let authService: AuthService;
const mockRepository = {
findOne() {
return { username: 'jkchao' };
},
create() {
return { username: 'jkchao' };
},
findOneAndUpdate() {
return { username: 'jkchao' };
}
};
beforeAll(async () => {
const module = await Test.createTestingModule({
imports: [AuthModule]
})
.overrideProvider(getModelToken('Auth'))
.useValue(mockRepository)
.compile();
authService = module.get<AuthService>(AuthService);
});
it('findOne', async () => {
const res = await authService.findOne();
expect(res).toMatchObject(mockRepository.findOne());
});
it('findOne', async () => {
const res = await authService.create({ username: '', password: '' });
expect(res).toMatchObject(mockRepository.create());
});
it('findOne', async () => {
const res = await authService.update({});
expect(res).toMatchObject(mockRepository.findOne());
});
afterAll(async () => {
await mongoose.disconnect();
});
});