Skip to content

Commit

Permalink
fix: unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
vip-git authored and Vipin committed Jun 5, 2018
1 parent fde9c6d commit 84ece10
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 26 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
"@tsed/common": "^4.20.0",
"@tsed/core": "^4.20.0",
"@tsed/swagger": "^4.20.0",
"@tsed/testing": "^4.20.2",
"ajv": "^6.5.0",
"bcrypt-nodejs": "^0.0.3",
"body-parser": "^1.18.3",
Expand Down
45 changes: 29 additions & 16 deletions src/common/services/tvmaze/tvmaze.service.spec.ts
Original file line number Diff line number Diff line change
@@ -1,23 +1,36 @@
import { ParseService } from "@tsed/common";
import {inject} from "@tsed/testing";
import { UserRepositoryToken } from '../../../api/show/show.model';
import { getInjectionService } from '../../utils/tests/injectors';
import { TvMazeService } from './tvmaze.service';

describe('UserService', () => {
it('should fetch user by id', async () => {
const inject = await getInjectionService(this);
const locals = new Map();
const userData = { name: 'test' };
const findSpy = jest.fn().mockReturnValue(Promise.resolve(userData));
locals.set(UserRepositoryToken, {
findById: findSpy
});
let service;

const service = inject.invoke<TvMazeService>(TvMazeService, locals);
const foundUser = await service.getShowById('123');
beforeEach(inject([TvMazeService], (_tvmazeService_: TvMazeService) => {
service = _tvmazeService_;
}));

expect(foundUser).toBeDefined();
// expect(foundUser).toEqual(userData);
// expect(findSpy).toHaveBeenCalledTimes(1);
// expect(findSpy.mock.calls[0][0]).toBe('123');
it('should fetch show by id', async () => {
const foundShow = await service.getShowById('123');
expect(foundShow).toHaveProperty('id');
expect(foundShow).toHaveProperty('url');
expect(foundShow).toHaveProperty('name');
expect(foundShow).toHaveProperty('type');
expect(foundShow).toHaveProperty('language');
expect(foundShow).toHaveProperty('genres');
expect(foundShow).toHaveProperty('status');
expect(foundShow).toHaveProperty('runtime');
expect(foundShow).toHaveProperty('premiered');
expect(foundShow).toHaveProperty('officialSite');
expect(foundShow).toHaveProperty('schedule');
expect(foundShow).toHaveProperty('rating');
expect(foundShow).toHaveProperty('weight');
expect(foundShow).toHaveProperty('network');
expect(foundShow).toHaveProperty('webChannel');
expect(foundShow).toHaveProperty('externals');
expect(foundShow).toHaveProperty('image');
expect(foundShow).toHaveProperty('summary');
expect(foundShow).toHaveProperty('updated');
expect(foundShow).toHaveProperty('_links');
});
});
});
10 changes: 0 additions & 10 deletions src/common/utils/tests/injectors.ts

This file was deleted.

0 comments on commit 84ece10

Please sign in to comment.