You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
56 lines
1.9 KiB
56 lines
1.9 KiB
import { Test, type TestingModule } from '@nestjs/testing';
|
|
import { MoviesController } from './movies.controller';
|
|
import { createTestOmdbEnrichedDataService } from './utils/testHelpers';
|
|
|
|
describe('AppController', () => {
|
|
let moviesController: MoviesController;
|
|
|
|
beforeEach(async () => {
|
|
const app: TestingModule = await Test.createTestingModule({
|
|
controllers: [MoviesController],
|
|
providers: [
|
|
{
|
|
provide: 'enrichedDataService',
|
|
useFactory: createTestOmdbEnrichedDataService,
|
|
},
|
|
],
|
|
}).compile();
|
|
|
|
moviesController = app.get<MoviesController>(MoviesController);
|
|
});
|
|
|
|
describe('root', () => {
|
|
it('should return movie by internal id', () => {
|
|
expect(moviesController.getMovie('11528860')).toMatchObject({
|
|
title: 'The Jungle Book',
|
|
});
|
|
});
|
|
|
|
it('should return movie by imdb id', () => {
|
|
expect(moviesController.getMovie('tt0061852')).toMatchObject({
|
|
title: 'The Jungle Book',
|
|
});
|
|
});
|
|
|
|
it('should return 404 for unknown imdb id', () => {
|
|
expect(() => moviesController.getMovie('tt7394674')).toThrow(
|
|
'Not Found',
|
|
);
|
|
});
|
|
|
|
it('should throw an error for empty search query', () => {
|
|
expect(() => moviesController.searchMovies({})).toThrow(
|
|
'Query should not be empty',
|
|
);
|
|
});
|
|
|
|
it('should return movies matching writer', () => {
|
|
expect(
|
|
moviesController.searchMovies({ writers: 'George Lucas' }),
|
|
).toMatchObject([
|
|
{ title: 'Indiana Jones and the Last Crusade' },
|
|
{ title: 'Star Wars: Episode IV - A New Hope' },
|
|
]);
|
|
});
|
|
});
|
|
});
|
|
|