Skip to content

Commit 84ece10

Browse files
vip-gitVipin
authored andcommitted
fix: unit tests
1 parent fde9c6d commit 84ece10

File tree

3 files changed

+30
-26
lines changed

3 files changed

+30
-26
lines changed

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@
4141
"@tsed/common": "^4.20.0",
4242
"@tsed/core": "^4.20.0",
4343
"@tsed/swagger": "^4.20.0",
44+
"@tsed/testing": "^4.20.2",
4445
"ajv": "^6.5.0",
4546
"bcrypt-nodejs": "^0.0.3",
4647
"body-parser": "^1.18.3",
Lines changed: 29 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,36 @@
1+
import { ParseService } from "@tsed/common";
2+
import {inject} from "@tsed/testing";
13
import { UserRepositoryToken } from '../../../api/show/show.model';
2-
import { getInjectionService } from '../../utils/tests/injectors';
34
import { TvMazeService } from './tvmaze.service';
45

56
describe('UserService', () => {
6-
it('should fetch user by id', async () => {
7-
const inject = await getInjectionService(this);
8-
const locals = new Map();
9-
const userData = { name: 'test' };
10-
const findSpy = jest.fn().mockReturnValue(Promise.resolve(userData));
11-
locals.set(UserRepositoryToken, {
12-
findById: findSpy
13-
});
7+
let service;
148

15-
const service = inject.invoke<TvMazeService>(TvMazeService, locals);
16-
const foundUser = await service.getShowById('123');
9+
beforeEach(inject([TvMazeService], (_tvmazeService_: TvMazeService) => {
10+
service = _tvmazeService_;
11+
}));
1712

18-
expect(foundUser).toBeDefined();
19-
// expect(foundUser).toEqual(userData);
20-
// expect(findSpy).toHaveBeenCalledTimes(1);
21-
// expect(findSpy.mock.calls[0][0]).toBe('123');
13+
it('should fetch show by id', async () => {
14+
const foundShow = await service.getShowById('123');
15+
expect(foundShow).toHaveProperty('id');
16+
expect(foundShow).toHaveProperty('url');
17+
expect(foundShow).toHaveProperty('name');
18+
expect(foundShow).toHaveProperty('type');
19+
expect(foundShow).toHaveProperty('language');
20+
expect(foundShow).toHaveProperty('genres');
21+
expect(foundShow).toHaveProperty('status');
22+
expect(foundShow).toHaveProperty('runtime');
23+
expect(foundShow).toHaveProperty('premiered');
24+
expect(foundShow).toHaveProperty('officialSite');
25+
expect(foundShow).toHaveProperty('schedule');
26+
expect(foundShow).toHaveProperty('rating');
27+
expect(foundShow).toHaveProperty('weight');
28+
expect(foundShow).toHaveProperty('network');
29+
expect(foundShow).toHaveProperty('webChannel');
30+
expect(foundShow).toHaveProperty('externals');
31+
expect(foundShow).toHaveProperty('image');
32+
expect(foundShow).toHaveProperty('summary');
33+
expect(foundShow).toHaveProperty('updated');
34+
expect(foundShow).toHaveProperty('_links');
2235
});
23-
});
36+
});

src/common/utils/tests/injectors.ts

Lines changed: 0 additions & 10 deletions
This file was deleted.

0 commit comments

Comments
 (0)