Small Nest.js-based project
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.
 
test-assignment-joyn/src/app.module.spec.ts

106 lines
3.6 KiB

import { Test, type TestingModule } from '@nestjs/testing';
import type { INestApplication } from '@nestjs/common';
import request from 'supertest';
import { AppModule } from './app.module';
import { createTestOmdbEnrichedDataService } from './utils/testHelpers';
import { configureApp } from './utils/nestjsHelpers';
describe('AppController (e2e)', () => {
let app: INestApplication;
beforeAll(async () => {
const enrichedDataService = await createTestOmdbEnrichedDataService();
const moduleFixture: TestingModule = await Test.createTestingModule({
imports: [AppModule],
})
.overrideProvider('enrichedDataService')
.useValue(enrichedDataService)
.compile();
app = moduleFixture.createNestApplication();
configureApp(app);
await app.init();
});
it('/api/movies/tt0061852 (GET)', () => {
return request(app.getHttpServer())
.get('/api/movies/tt0061852')
.expect(200)
.expect((response) => {
expect(response.body).toMatchObject({
title: 'The Jungle Book',
});
});
});
it('/api/movies/11528860 (GET)', () => {
return request(app.getHttpServer())
.get('/api/movies/11528860')
.expect(200)
.expect((response) => {
expect(response.body).toMatchObject({
title: 'The Jungle Book',
});
});
});
it('/api/movies (GET)', () => {
return request(app.getHttpServer()).get('/api/movies').expect(400);
});
it('/api/movies?writers=George Lucas (GET)', () => {
return request(app.getHttpServer())
.get('/api/movies?writers=George Lucas')
.expect(200)
.expect((response) => {
expect(response.body).toMatchObject([
{ title: 'Indiana Jones and the Last Crusade' },
{ title: 'Star Wars: Episode IV - A New Hope' },
]);
});
});
it('/api/movies?writers=George Lucas&actors=Mark Hamill (GET)', () => {
return request(app.getHttpServer())
.get('/api/movies?writers=George Lucas&actors=Mark Hamill')
.expect(200)
.expect((response) => {
expect(response.body).toMatchObject([
{ title: 'Star Wars: Episode IV - A New Hope' },
]);
});
});
it('/api/movies?productionYear=1967 (GET)', () => {
return request(app.getHttpServer())
.get('/api/movies?productionYear=1967')
.expect(200)
.expect((response) => {
expect(response.body).toMatchObject([
{ title: 'The Jungle Book' },
]);
});
});
it('/api/movies?productionYear=1800 (GET)', () => {
return request(app.getHttpServer())
.get('/api/movies?productionYear=1800')
.expect(200)
.expect((response) => {
expect(response.body).toMatchObject([]);
});
});
it('/api/movies?writers=gEoRgE lUcAs (GET)', () => {
return request(app.getHttpServer())
.get('/api/movies?writers=gEoRgE lUcAs')
.expect(200)
.expect((response) => {
expect(response.body).toMatchObject([
{ title: 'Indiana Jones and the Last Crusade' },
{ title: 'Star Wars: Episode IV - A New Hope' },
]);
});
});
});