-
Notifications
You must be signed in to change notification settings - Fork 17
/
app.mock.spec.ts
51 lines (43 loc) · 1.24 KB
/
app.mock.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
import type { User } from '@prisma/client'
import { asClass } from 'awilix'
import { afterAll, beforeAll, describe, expect, it } from 'vitest'
import { createRequestContext } from '../test/requestUtils.js'
import type { AppInstance } from './app.js'
import { getApp } from './app.js'
import type { Dependencies } from './infrastructure/parentDiConfig.js'
import { SINGLETON_CONFIG } from './infrastructure/parentDiConfig.js'
import { UserService } from './modules/users/services/UserService.js'
class FakeUserService extends UserService {
constructor() {
super({} as Dependencies)
}
override getUser(): Promise<User> {
return Promise.resolve({
id: '-1',
age: null,
email: 'dummy',
name: 'dummy',
})
}
}
describe('dependency mocking', () => {
let app: AppInstance
beforeAll(async () => {
app = await getApp(
{
jobsEnabled: false,
},
{
userService: asClass(FakeUserService, SINGLETON_CONFIG),
},
)
})
afterAll(async () => {
await app.close()
})
it('uses mock implementation', async () => {
const { userService } = app.diContainer.cradle
const result = await userService.getUser(createRequestContext(), '1')
expect(result.id).toBe('-1')
})
})