-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(api): ✨ Add new endpoint for storing movies
- Loading branch information
1 parent
9ff038c
commit 3038198
Showing
4 changed files
with
83 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,14 @@ | ||
/* eslint-disable @typescript-eslint/no-extraneous-class */ | ||
export class CreateMovieDto {} | ||
export class CreateMovieDto { | ||
genre: string | ||
director: string | ||
duration: number | ||
subtitles: string[] | ||
releaseDate: Date | ||
movieTitles: CreateMovieTitleDto[] | ||
} | ||
|
||
export class CreateMovieTitleDto { | ||
language: string | ||
title: string | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,54 @@ | ||
import { Test, TestingModule } from '@nestjs/testing' | ||
|
||
import { PrismaService } from '../database/prisma.service' | ||
|
||
import { MoviesService } from './movies.service' | ||
import { CreateMovieDto } from './dto/create-movie.dto' | ||
|
||
describe('MoviesService', () => { | ||
let service: MoviesService | ||
let prismaService: PrismaService | ||
|
||
beforeEach(async () => { | ||
const module: TestingModule = await Test.createTestingModule({ | ||
providers: [MoviesService] | ||
providers: [ | ||
MoviesService, | ||
{ | ||
provide: PrismaService, | ||
useValue: { | ||
movie: { | ||
create: jest.fn().mockResolvedValue({}) | ||
} | ||
} | ||
} | ||
] | ||
}).compile() | ||
|
||
service = module.get<MoviesService>(MoviesService) | ||
prismaService = module.get<PrismaService>(PrismaService) | ||
}) | ||
|
||
it('should be defined', () => { | ||
expect(service).toBeDefined() | ||
}) | ||
|
||
it('should create a movie', async () => { | ||
const createMovieDto: CreateMovieDto = { | ||
genre: 'Action', | ||
director: 'John Doe', | ||
duration: 120, | ||
subtitles: ['English', 'Spanish'], | ||
releaseDate: new Date(), | ||
movieTitles: [{ language: 'English', title: 'Example Title' }] | ||
} | ||
|
||
const expectedResult = { | ||
...createMovieDto, | ||
id: 1 | ||
} | ||
|
||
jest.spyOn(prismaService.movie, 'create').mockResolvedValue(expectedResult) | ||
|
||
await expect(service.create(createMovieDto)).resolves.toEqual(expectedResult) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters