Skip to content

Commit

Permalink
Merge pull request #55 from JHWelch/add-time
Browse files Browse the repository at this point in the history
Add time
  • Loading branch information
JHWelch authored Oct 5, 2023
2 parents be2604d + 497ceac commit 8f0c2c1
Show file tree
Hide file tree
Showing 15 changed files with 90 additions and 27 deletions.
2 changes: 2 additions & 0 deletions __tests__/controllers/cacheController.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ describe('cache', () => {
'director',
2001,
90,
null,
'https://www.themoviedb.org/movie/1234',
'/poster.jpg',
1234,
Expand All @@ -107,6 +108,7 @@ describe('cache', () => {
'director',
2001,
90,
null,
'https://www.themoviedb.org/movie/1234',
'/poster.jpg',
1234,
Expand Down
34 changes: 22 additions & 12 deletions __tests__/data/firestore/firestoreAdapter.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import { transaction } from '../../../__mocks__/firebase/firestore'
import { FirebaseMock } from '../../support/firebaseMock'
import Week from '../../../src/models/week'
import { mockConfig } from '../../support/mockConfig'
import MovieFactory from '../../support/factories/movieFactory'

let firestore: FirestoreAdapter

Expand Down Expand Up @@ -195,31 +196,40 @@ describe('cacheWeeks', () => {
})
})

it('can update a week with movies', async () => {
const movie = new MovieFactory().make()
const weekWithMovie = new Week(
'id1',
'theme1',
new Date('2021-01-01'),
false,
[movie],
)

await firestore.cacheWeeks([
weekWithMovie,
])

expect(transaction.set)
.toHaveBeenCalledWith(
FirebaseMock.mockDoc('weeks', '2021-01-01'),
FirebaseMock.mockWeek('id1', 'theme1', '2021-01-01', [movie])
)
})

describe('when mode is development', () => {
it('uses the development collection', async () => {
firestore = new FirestoreAdapter(mockConfig({ nodeEnv: 'development' }))

await firestore.cacheWeeks([
new Week('id1', 'theme1', new Date('2021-01-01')),
new Week('id2', 'theme2', new Date('2021-01-08')),
new Week('id3', 'theme3', new Date('2021-01-15')),
])

expect(transaction.set)
.toHaveBeenCalledWith(
FirebaseMock.mockDoc('weeks-dev', '2021-01-01'),
FirebaseMock.mockWeek('id1', 'theme1', '2021-01-01')
)
expect(transaction.set)
.toHaveBeenCalledWith(
FirebaseMock.mockDoc('weeks-dev', '2021-01-08'),
FirebaseMock.mockWeek('id2', 'theme2', '2021-01-08')
)
expect(transaction.set)
.toHaveBeenCalledWith(
FirebaseMock.mockDoc('weeks-dev', '2021-01-15'),
FirebaseMock.mockWeek('id3', 'theme3', '2021-01-15')
)
})
})
})
Expand Down
2 changes: 2 additions & 0 deletions __tests__/data/notion/notionAdapter.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ describe('getMovie', () => {
director: 'movieDirector',
year: 2021,
length: 120,
time: '8:00 PM',
url: 'movieUrl',
posterPath: 'moviePosterPath',
theaterName: 'movieTheaterName',
Expand Down Expand Up @@ -179,6 +180,7 @@ describe('setMovie', () => {
'Movie Director',
2021,
120,
'8:00 PM',
'Movie Url',
'Movie Poster Url',
1234,
Expand Down
1 change: 1 addition & 0 deletions __tests__/data/tmdb/tmdbAdapter.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ describe('getMovie', () => {
'director',
2001,
90,
null,
'https://www.themoviedb.org/movie/1234',
'/posterPath.jpg',
1234,
Expand Down
28 changes: 27 additions & 1 deletion __tests__/models/movie.spec.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { describe, expect, it, test } from '@jest/globals'
import Movie from '../../src/models/movie'
import { MovieFactory } from '../support/factories/movieFactory'
import MovieFactory from '../support/factories/movieFactory'
import { TMDB_POSTER_URL } from '../../src/data/tmdb/constants'

describe('merge', () => {
Expand All @@ -11,6 +11,7 @@ describe('merge', () => {
'Director',
2001,
null,
'8:00 PM',
'https://www.themoviedb.org/movie/1234',
'https://image.tmdb.org/t/p/original/poster.jpg',
1234,
Expand All @@ -23,6 +24,7 @@ describe('merge', () => {
'Director',
2004,
120,
'8:00 PM',
'https://www.themoviedb.org/movie/1234',
'https://image.tmdb.org/t/p/original/poster.jpg',
1234,
Expand All @@ -37,6 +39,7 @@ describe('toNotion', () => {
'Movie Director',
2021,
120,
'8:00 PM',
'Movie Url',
'Movie Poster Url',
1234,
Expand Down Expand Up @@ -69,6 +72,7 @@ describe('toNotion', () => {
'Movie Director',
2021,
120,
'8:00 PM',
'Movie Url',
'Movie Poster Url',
1234,
Expand All @@ -92,6 +96,7 @@ describe('toDTO', () => {
director: movie.director,
year: movie.year,
length: movie.length,
time: movie.time,
url: movie.url,
posterUrl: movie.posterUrl(),
theaterName: movie.theaterName,
Expand All @@ -113,6 +118,7 @@ describe('toDTO', () => {
director: movie.director,
year: movie.year,
length: movie.length,
time: movie.time,
url: movie.url,
posterUrl: movie.posterUrl(),
theaterName: movie.theaterName,
Expand All @@ -124,6 +130,26 @@ describe('toDTO', () => {
})
})

describe('toFirebaseDTO', () => {
it('should return a DTO', () => {
const movie = new MovieFactory().make()

expect(movie.toFirebaseDTO()).toEqual({
title: movie.title,
director: movie.director,
year: movie.year,
length: movie.length,
time: movie.time,
url: movie.url,
posterPath: movie.posterPath,
tmdbId: movie.tmdbId,
notionId: movie.notionId,
theaterName: movie.theaterName,
showingUrl: movie.showingUrl,
})
})
})

describe('posterUrl', () => {
it('appends the posterPath to the base url', () => {
const movie = new MovieFactory().make()
Expand Down
4 changes: 3 additions & 1 deletion __tests__/support/factories/movieFactory.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import Movie from '../../../src/models/movie'

export class MovieFactory {
export default class MovieFactory {
private _state = {
title: 'Movie Title',
director: 'Movie Director',
year: 2021,
length: 90,
time: '8:00 PM',
url: 'https://example.com/movie1234',
tmdbId: 1234,
posterPath: '/path/to/poster.jpg',
Expand All @@ -20,6 +21,7 @@ export class MovieFactory {
this._state.director,
this._state.year,
this._state.length,
this._state.time,
this._state.url,
this._state.posterPath,
this._state.tmdbId,
Expand Down
6 changes: 4 additions & 2 deletions __tests__/support/firebaseMock.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { getDocs, getDoc, Timestamp, WithFieldValue } from 'firebase/firestore'
import { jest } from '@jest/globals'
import { FirestoreWeek } from '../../src/data/firestore/firestoreTypes'
import Week from '../../src/models/week'
import Movie from '../../src/models/movie'

export class FirebaseMock {
static mockWeeks (weeks: FirebaseWeek[]) {
Expand Down Expand Up @@ -44,9 +45,10 @@ export class FirebaseMock {
static mockWeek = (
id: string,
theme: string,
date: string
date: string,
movies: Movie[] = [],
): WithFieldValue<FirestoreWeek> =>
new Week(id, theme, new Date(date), false).toFirebaseDTO()
new Week(id, theme, new Date(date), false, movies).toFirebaseDTO()

static mockCollection = (collectionPath: string): {
firestore: { firestore: 'firestore' },
Expand Down
3 changes: 3 additions & 0 deletions __tests__/support/notionHelpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,7 @@ export class NotionMovie {
public director: string | null = null,
public year: number | null = null,
public length: number | null = null,
public time: string | null = null,
public url: string | null = null,
public posterPath: string | null = null,
public theaterName: string | null = null,
Expand All @@ -165,6 +166,7 @@ export class NotionMovie {
Director: nRichText(this.director),
Year: nNumber(this.year),
'Length (mins)': nNumber(this.length),
Time: nRichText(this.time),
URL: nUrl(this.url),
Poster: nUrl(this.posterPath),
'Theater Name': nRichText(this.theaterName),
Expand All @@ -179,6 +181,7 @@ export class NotionMovie {
'movieDirector',
2021,
120,
'8:00 PM',
'movieUrl',
'moviePosterPath',
'movieTheaterName',
Expand Down
12 changes: 3 additions & 9 deletions __tests__/support/notionMock.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,16 +51,10 @@ export class NotionMock {
const notionMovie = movie ?? NotionMovie.demo()

this.retrieve.mockImplementation(async (
args: WithAuth<GetPageParameters>
): Promise<GetPageResponse> => {
const { page_id } = args as { page_id: string }
_args: WithAuth<GetPageParameters>
): Promise<GetPageResponse> =>
notionMovie.toPageObjectResponse())

if (page_id !== notionMovie.id) {
throw new Error('Page not found')
}

return notionMovie.toPageObjectResponse()
})
return { pages: { retrieve: this.retrieve } }
}

Expand Down
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
"lint": "eslint . --ext .ts",
"fix": "eslint . --ext .ts --fix",
"test": "jest",
"test-watch": "jest --watch",
"coverage": "jest --coverage",
"watch": "concurrently \"npm run watch-express\" \"npm run watch-tailwind\"",
"watch-express": "nodemon src/index.ts",
"watch-tailwind": "npx tailwindcss -i ./css/app.css -o ./public/app.css --watch"
Expand Down
1 change: 1 addition & 0 deletions src/data/firestore/firestoreTypes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ export type FirestoreMovie = {
director: string | null;
year: number | null;
length: number | null;
time: string | null;
url: string | null;
posterPath: string | null;
tmdbId: number | null;
Expand Down
7 changes: 7 additions & 0 deletions src/models/movie.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ export default class Movie {
public director: string | null = null,
public year: number | null = null,
public length: number | null = null,
public time: string | null = null,
public url: string | null = null,
public posterPath: string | null = null,
public tmdbId: number | null = null,
Expand All @@ -36,6 +37,7 @@ export default class Movie {
properties.Director?.rich_text[0]?.plain_text,
properties.Year?.number,
properties['Length (mins)']?.number,
properties.Time?.rich_text[0]?.plain_text,
properties.URL?.url,
properties.Poster?.url,
null,
Expand All @@ -51,6 +53,7 @@ export default class Movie {
movie.director,
movie.year,
movie.length,
movie.time,
movie.url,
movie.posterPath,
movie.tmdbId,
Expand All @@ -66,6 +69,7 @@ export default class Movie {
tmdbResponse.director,
parseInt(tmdbResponse.releaseDate.split('-')[0]),
tmdbResponse.runtime ?? -1,
null,
tmdbResponse.fullMovieUrl,
tmdbResponse.posterPath,
tmdbResponse.id,
Expand Down Expand Up @@ -102,6 +106,7 @@ export default class Movie {
director: this.director,
year: this.year,
length: this.length,
time: this.time,
url: this.url,
posterUrl: this.posterUrl(),
theaterName: this.theaterName,
Expand All @@ -117,6 +122,7 @@ export default class Movie {
director: this.director,
year: this.year,
length: this.length,
time: this.time,
url: this.url,
tmdbId: this.tmdbId,
notionId: this.notionId,
Expand Down Expand Up @@ -149,6 +155,7 @@ export default class Movie {
this.director ??= other.director
this.year ??= other.year
this.length ??= other.length
this.time ??= other.time
this.url ??= other.url
this.posterPath ??= other.posterPath
this.tmdbId ??= other.tmdbId
Expand Down
5 changes: 5 additions & 0 deletions src/types/movieProperties.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,11 @@ export default interface MovieProperties {
'Length (mins)': {
number: number
}
Time: {
rich_text: Array<{
plain_text: string
}>
}
URL: {
url: string
}
Expand Down
8 changes: 7 additions & 1 deletion views/partials/movie.ejs
Original file line number Diff line number Diff line change
@@ -1,10 +1,16 @@
<div :class="`px-3 sm:${movieSizeClasses(week)}`">
<div class="flex flex-col px-4 py-2 rounded-md bg-violet-200 ">
<h4 class="flex items-center justify-center h-12">
<h4 class="flex items-center justify-between h-12 px-2">
<span
x-text="movie.title"
:class="titleSize(movie) + ' overflow-hidden font-medium text-center overflow-ellipsis'"
></span>

<span
x-show="movie.time"
x-text="movie.time"
class="text-md overflow-hidden font-medium text-center overflow-ellipsis bg-violet-700 text-white px-2 py-0.5 rounded-2xl"
></span>
</h4>

<div class="flex flex-col justify-between flex-1">
Expand Down
2 changes: 1 addition & 1 deletion views/partials/movie/field_trip_banner.ejs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<template x-if="movie.isFieldTrip">
<a
:href="movie.showingUrl"
class="absolute inset-0 flex items-center justify-between w-full h-12 p-3 font-medium text-center text-white text-md opacity-80 bg-fuchsia-500"
class="absolute inset-0 flex items-center justify-between w-full h-12 p-3 font-medium text-center text-white text-md bg-opacity-80 bg-violet-500"
>
<span x-text="movie.theaterName"></span>

Expand Down

0 comments on commit 8f0c2c1

Please sign in to comment.