Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tmdb movie details #26

Merged
merged 29 commits into from
Aug 12, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
87 changes: 74 additions & 13 deletions __tests__/controllers/cacheController.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,11 @@ import { Request } from 'express'
import Week from '../../src/models/week'
import { FirebaseMock } from '../support/firebaseMock'
import FirestoreAdapter from '../../src/data/firestoreAdapter'
import { NotionMovie } from '../support/notionHelpers'
import { TmdbMock } from '../support/tmdbMock'
import { mockFetch } from '../support/fetchMock'
import Movie from '../../src/models/movie'
import TmdbAdapter from '../../src/data/tmdb/tmdbAdapter'

let notionMock: NotionMock

Expand All @@ -31,23 +36,25 @@ beforeEach(() => {
describe('cache', () => {
let firestore: FirestoreAdapter
let notion: NotionAdapter
let tmdbAdapter: TmdbAdapter
let req: Request

beforeEach(() => {
notionMock.mockIsFullPageOrDatabase(true)
notionMock.mockQuery([
NotionMock.mockWeek('id1', '2021-01-01', 'theme1'),
NotionMock.mockWeek('id2', '2021-01-08', 'theme2'),
NotionMock.mockWeek('id3', '2021-01-15', 'theme3'),
])
firestore = new FirestoreAdapter()
notion = new NotionAdapter()
req = getMockReq()
})

describe('when the cache is empty', () => {
beforeEach(() => {
notionMock.mockIsFullPageOrDatabase(true)
notionMock.mockQuery([
NotionMock.mockWeek('id1', '2021-01-01', 'theme1'),
NotionMock.mockWeek('id2', '2021-01-08', 'theme2'),
NotionMock.mockWeek('id3', '2021-01-15', 'theme3'),
])
firestore = new FirestoreAdapter()
notion = new NotionAdapter()
tmdbAdapter = new TmdbAdapter()
req = getMockReq()
})

it('updates all weeks in firestore', async () => {
const cacheController = new CacheController(firestore, notion)
const cacheController = new CacheController(firestore, notion, tmdbAdapter)

await cacheController.cache(req, res)

Expand All @@ -70,4 +77,58 @@ describe('cache', () => {
)
})
})

describe('movies without directors', () => {
let expected: Movie

beforeEach(() => {
expected = new Movie(
'title',
'director',
2001,
90,
'https://www.themoviedb.org/movie/1234',
'https://image.tmdb.org/t/p/original/poster.jpg',
1234,
'notionId',
)
const tmdb = new Movie(
'title',
'director',
2001,
90,
'https://www.themoviedb.org/movie/1234',
'https://image.tmdb.org/t/p/original/poster.jpg',
1234,
)
const notionResponse = new NotionMovie('notionId', 'title')
notionMock.mockIsFullPageOrDatabase(true)
notionMock.mockQuery([
NotionMock.mockWeek('id1', '2021-01-01', 'theme1', false, [notionResponse]),
])
notionMock.mockRetrieve(notionResponse)
firestore = new FirestoreAdapter()
notion = new NotionAdapter()
tmdbAdapter = new TmdbAdapter()
req = getMockReq()
const tmdbMock = new TmdbMock(mockFetch())
tmdbMock.mockSearchMovie(tmdb)
tmdbMock.mockMovieDetails(tmdb)
})

it('stores data from tmdb in firestore', async () => {
const cacheController = new CacheController(firestore, notion, tmdbAdapter)

await cacheController.cache(req, res)

expect(res.sendStatus).toHaveBeenCalledWith(200)
expect(transaction.set).toHaveBeenCalledTimes(1)
expect(transaction.set).toHaveBeenCalledWith(
FirebaseMock.mockDoc('weeks', '2021-01-01'),
(new Week('id1', 'theme1', new Date('2021-01-01'), false, [
expected,
])).toFirebaseDTO()
)
})
})
})
3 changes: 2 additions & 1 deletion __tests__/data/notionAdapter.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ describe('getMovie', () => {
const movie = await new NotionAdapter().getMovie('movieId')

expect(movie).toEqual({
id: 'movieId',
notionId: 'movieId',
title: 'movieTitle',
director: 'movieDirector',
year: 2021,
Expand All @@ -81,6 +81,7 @@ describe('getMovie', () => {
posterUrl: 'moviePosterUrl',
theaterName: 'movieTheaterName',
showingUrl: 'movieShowingUrl',
tmdbId: null,
})
})

Expand Down
24 changes: 24 additions & 0 deletions __tests__/data/tmdb/dtos/crewResponse.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import { describe, expect, it } from '@jest/globals'
import CrewResponse from '../../../../src/data/tmdb/dtos/crewResponse.js'

describe('fromTmdbResponse', () => {
it('should assign all fields correctly', () => {
const input = {
adult: false,
gender: 1,
id: 57434,
known_for_department: 'Directing',
name: 'Amy Heckerling',
original_name: 'Amy Heckerling',
popularity: 7.914,
profile_path: '/hIc3bQxLOPAcpGJ1CVFuzpzJRZ0.jpg',
credit_id: '52fe4510c3a36847f80ba261',
department: 'Directing',
job: 'Director',
}
const response = CrewResponse.fromTmdbResponse(input)

expect(response.name).toEqual('Amy Heckerling')
expect(response.job).toEqual('Director')
})
})
202 changes: 202 additions & 0 deletions __tests__/data/tmdb/dtos/movieResponse.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,202 @@
import { beforeEach, describe, expect, it } from '@jest/globals'
import MovieResponse from '../../../../src/data/tmdb/dtos/movieResponse'
import CrewResponse from '../../../../src/data/tmdb/dtos/crewResponse'

describe('fromTmdbResponse', () => {
it('should assign all fields correctly from search', () => {
const response = MovieResponse.fromTmdbResponse({
adult: false,
backdrop_path: '/2FonLz0RPxbBriOlZ9mWhYdlqCp.jpg',
id: 9603,
original_language: 'en',
original_title: 'Clueless',
overview: 'Shallow, rich and socially successful Cher is at the top of her Beverly Hills high school\'s pecking scale. Seeing herself as a matchmaker, Cher first coaxes two teachers into dating each other. Emboldened by her success, she decides to give hopelessly klutzy new student Tai a makeover. When Tai becomes more popular than she is, Cher realizes that her disapproving ex-stepbrother was right about how misguided she was -- and falls for him.',
popularity: 32.244,
poster_path: '/8AwVTcgpTnmeOs4TdTWqcFDXEsA.jpg',
release_date: '1995-07-19',
title: 'Clueless',
video: false,
vote_average: 7.282,
vote_count: 3953,
})

expect(response.adult).toEqual(false)
expect(response.backdropPath).toEqual('/2FonLz0RPxbBriOlZ9mWhYdlqCp.jpg')
expect(response.id).toEqual(9603)
expect(response.originalLanguage).toEqual('en')
expect(response.originalTitle).toEqual('Clueless')
expect(response.overview).toEqual('Shallow, rich and socially successful Cher is at the top of her Beverly Hills high school\'s pecking scale. Seeing herself as a matchmaker, Cher first coaxes two teachers into dating each other. Emboldened by her success, she decides to give hopelessly klutzy new student Tai a makeover. When Tai becomes more popular than she is, Cher realizes that her disapproving ex-stepbrother was right about how misguided she was -- and falls for him.')
expect(response.popularity).toEqual(32.244)
expect(response.posterPath).toEqual('/8AwVTcgpTnmeOs4TdTWqcFDXEsA.jpg')
expect(response.releaseDate).toEqual('1995-07-19')
expect(response.title).toEqual('Clueless')
expect(response.video).toEqual(false)
expect(response.voteAverage).toEqual(7.282)
expect(response.voteCount).toEqual(3953)
expect(response.crew).toEqual([])
})

describe('From Details', () => {
let response: MovieResponse

beforeEach(() => {
response = MovieResponse.fromTmdbResponse({
adult: false,
backdrop_path: '/2FonLz0RPxbBriOlZ9mWhYdlqCp.jpg',
belongs_to_collection: null,
budget: 12000000,
genres: [
{
id: 35,
name: 'Comedy',
},
{
id: 10749,
name: 'Romance',
},
],
homepage: '',
id: 9603,
imdb_id: 'tt0112697',
original_language: 'en',
original_title: 'Clueless',
overview: 'Shallow, rich and socially successful Cher is at the top of her Beverly Hills high school\'s pecking scale. Seeing herself as a matchmaker, Cher first coaxes two teachers into dating each other. Emboldened by her success, she decides to give hopelessly klutzy new student Tai a makeover. When Tai becomes more popular than she is, Cher realizes that her disapproving ex-stepbrother was right about how misguided she was -- and falls for him.',
popularity: 32.244,
poster_path: '/8AwVTcgpTnmeOs4TdTWqcFDXEsA.jpg',
production_companies: [
{
id: 4,
logo_path: '/gz66EfNoYPqHTYI4q9UEN4CbHRc.png',
name: 'Paramount',
origin_country: 'US',
},
],
production_countries: [
{
iso_3166_1: 'US',
name: 'United States of America',
},
],
release_date: '1995-07-19',
revenue: 56631572,
runtime: 97,
spoken_languages: [
{
english_name: 'Spanish',
iso_639_1: 'es',
name: 'Español',
},
{
english_name: 'English',
iso_639_1: 'en',
name: 'English',
},
],
status: 'Released',
tagline: 'Sex. Clothes. Popularity. Is there a problem here?',
title: 'Clueless',
video: false,
vote_average: 7.282,
vote_count: 3953,
credits: {
cast: [
{
adult: false,
gender: 1,
id: 5588,
known_for_department: 'Acting',
name: 'Alicia Silverstone',
original_name: 'Alicia Silverstone',
popularity: 23.419,
profile_path: '/pyxqkP4i0ubVdoRe5hoiiiwkHkb.jpg',
cast_id: 8,
character: 'Cher Horowitz',
credit_id: '52fe4510c3a36847f80ba283',
order: 0,
},
{
adult: false,
gender: 1,
id: 58150,
known_for_department: 'Acting',
name: 'Stacey Dash',
original_name: 'Stacey Dash',
popularity: 9.118,
profile_path: '/mn9QUB95Hxkk5hVjKTZlSAMWGin.jpg',
cast_id: 9,
character: 'Dionne Davenport',
credit_id: '52fe4510c3a36847f80ba287',
order: 1,
},
],
crew: [
{
adult: false,
gender: 2,
id: 2997,
known_for_department: 'Production',
name: 'Scott Rudin',
original_name: 'Scott Rudin',
popularity: 1.247,
profile_path: '/zIeKeFgBERBHmabgmqZFmgcxqvO.jpg',
credit_id: '52fe4510c3a36847f80ba273',
department: 'Production',
job: 'Producer',
},
{
adult: false,
gender: 0,
id: 7240,
known_for_department: 'Sound',
name: 'Cary Weitz',
original_name: 'Cary Weitz',
popularity: 0.694,
profile_path: null,
credit_id: '60db8cc4a12856005eaa867f',
department: 'Sound',
job: 'Boom Operator',
},
{
adult: false,
gender: 1,
id: 57434,
known_for_department: 'Directing',
name: 'Amy Heckerling',
original_name: 'Amy Heckerling',
popularity: 7.914,
profile_path: '/hIc3bQxLOPAcpGJ1CVFuzpzJRZ0.jpg',
credit_id: '52fe4510c3a36847f80ba261',
department: 'Directing',
job: 'Director',
},
],
},
})
})

it('should assign all fields correctly', () => {
expect(response.adult).toEqual(false)
expect(response.backdropPath).toEqual('/2FonLz0RPxbBriOlZ9mWhYdlqCp.jpg')
expect(response.id).toEqual(9603)
expect(response.originalLanguage).toEqual('en')
expect(response.originalTitle).toEqual('Clueless')
expect(response.overview).toEqual('Shallow, rich and socially successful Cher is at the top of her Beverly Hills high school\'s pecking scale. Seeing herself as a matchmaker, Cher first coaxes two teachers into dating each other. Emboldened by her success, she decides to give hopelessly klutzy new student Tai a makeover. When Tai becomes more popular than she is, Cher realizes that her disapproving ex-stepbrother was right about how misguided she was -- and falls for him.')
expect(response.popularity).toEqual(32.244)
expect(response.posterPath).toEqual('/8AwVTcgpTnmeOs4TdTWqcFDXEsA.jpg')
expect(response.releaseDate).toEqual('1995-07-19')
expect(response.title).toEqual('Clueless')
expect(response.video).toEqual(false)
expect(response.voteAverage).toEqual(7.282)
expect(response.voteCount).toEqual(3953)
expect(response.crew).toEqual([
new CrewResponse('Scott Rudin', 'Producer'),
new CrewResponse('Cary Weitz', 'Boom Operator'),
new CrewResponse('Amy Heckerling', 'Director'),
])
})

it('should have output the correct director', () => {
expect(response.director).toEqual('Amy Heckerling')
})
})
})
Loading
Loading