/
profileService.test.ts
55 lines (43 loc) · 1.65 KB
/
profileService.test.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
54
55
import ProfileService from '../../src/services/ProfileService'
import S3Service from '../../src/services/external/s3'
import typeorm from 'typeorm'
import { Profile } from '../../src/models/Profile'
jest.mock('../../src/services/external/s3')
const mockedS3Service = S3Service as jest.Mocked<typeof S3Service>
const mockedTypeorm = typeorm as jest.Mocked<typeof typeorm>
describe('Profile Service', () => {
it('should create new profile', async () => {
const options = {
file: 'file',
name: 'name',
bio: 'bio',
birthDate: 'birthdate',
location: 'location'
}
await ProfileService.create(options)
expect(mockedS3Service.uploadFile).toBeCalledTimes(1)
expect(mockedS3Service.uploadFile).toBeCalledWith(options.file);
expect(mockedTypeorm.getRepository(Profile).create).toBeCalledTimes(1)
expect(mockedTypeorm.getRepository(Profile).save).toBeCalledTimes(1)
})
it('should return a profile', async () => {
const param = 1;
(mockedTypeorm.getRepository(Profile).findOne as jest.Mock).mockResolvedValue({picture: '123'});
await ProfileService.get(param);
expect(mockedTypeorm.getRepository(Profile).findOne).toBeCalledWith(param)
})
it('should update profile', async () => {
const options = {
file: 'file',
name: 'name',
bio: 'bio',
birthDate: 'birthdate',
location: 'location',
user: {id: '1'}
}
await ProfileService.update(options)
expect(mockedS3Service.uploadFile).toBeCalledTimes(1)
expect(mockedS3Service.uploadFile).toBeCalledWith("file");
expect(mockedTypeorm.getRepository(Profile).update).toBeCalledTimes(1)
})
})