From 5be033cc761d1cd116ab61bf3cde876bb9f510dc Mon Sep 17 00:00:00 2001 From: Jordan Welch Date: Fri, 29 Sep 2023 10:56:12 -0500 Subject: [PATCH 01/14] do not automatically append poster url --- __tests__/controllers/cacheController.spec.ts | 4 ++-- __tests__/data/tmdb/tmdbAdapter.spec.ts | 2 +- __tests__/support/tmdbMock.ts | 5 ++--- src/data/tmdb/dtos/movieResponse.ts | 8 +------- src/models/movie.ts | 2 +- 5 files changed, 7 insertions(+), 14 deletions(-) diff --git a/__tests__/controllers/cacheController.spec.ts b/__tests__/controllers/cacheController.spec.ts index 2c33e393..5ff14ea4 100644 --- a/__tests__/controllers/cacheController.spec.ts +++ b/__tests__/controllers/cacheController.spec.ts @@ -98,7 +98,7 @@ describe('cache', () => { 2001, 90, 'https://www.themoviedb.org/movie/1234', - 'https://image.tmdb.org/t/p/original/poster.jpg', + '/poster.jpg', 1234, 'notionId', ) @@ -108,7 +108,7 @@ describe('cache', () => { 2001, 90, 'https://www.themoviedb.org/movie/1234', - 'https://image.tmdb.org/t/p/original/poster.jpg', + '/poster.jpg', 1234, ) const notionResponse = new NotionMovie('notionId', 'title') diff --git a/__tests__/data/tmdb/tmdbAdapter.spec.ts b/__tests__/data/tmdb/tmdbAdapter.spec.ts index e4ec3845..6c8a6241 100644 --- a/__tests__/data/tmdb/tmdbAdapter.spec.ts +++ b/__tests__/data/tmdb/tmdbAdapter.spec.ts @@ -25,7 +25,7 @@ describe('getMovie', () => { 2001, 90, 'https://www.themoviedb.org/movie/1234', - 'https://image.tmdb.org/t/p/original/posterPath.jpg', + 'posterPath.jpg', 1234, ) tmdbMock.mockSearchMovie(expected) diff --git a/__tests__/support/tmdbMock.ts b/__tests__/support/tmdbMock.ts index 4af3987d..6fb0571e 100644 --- a/__tests__/support/tmdbMock.ts +++ b/__tests__/support/tmdbMock.ts @@ -1,5 +1,4 @@ import Movie from '../../src/models/movie' -import { TMDB_POSTER_URL } from '../../src/data/tmdb/constants' import { MockFetch } from './fetchMock' export class TmdbMock { @@ -15,7 +14,7 @@ export class TmdbMock { { id: id, original_title: movie.title, - poster_path: movie.posterUrl?.replace(TMDB_POSTER_URL, ''), + poster_path: movie.posterUrl, release_date: `${movie.year}-07-19`, title: movie.title, adult: false, @@ -39,7 +38,7 @@ export class TmdbMock { .mockImplementationOnce(async () => new Response(JSON.stringify({ id: id, original_title: movie.title, - poster_path: movie.posterUrl?.replace(TMDB_POSTER_URL, ''), + poster_path: movie.posterUrl, release_date: `${movie.year}-07-19`, title: movie.title, adult: false, diff --git a/src/data/tmdb/dtos/movieResponse.ts b/src/data/tmdb/dtos/movieResponse.ts index fbedf466..b6d8c47f 100644 --- a/src/data/tmdb/dtos/movieResponse.ts +++ b/src/data/tmdb/dtos/movieResponse.ts @@ -1,4 +1,4 @@ -import { TMDB_MOVIE_URL, TMDB_POSTER_URL } from '../constants.js' +import { TMDB_MOVIE_URL } from '../constants.js' import CrewResponse from './crewResponse.js' import { MovieResponseTmdb, isMovieResponseTmdb } from './responseTypes.js' @@ -61,10 +61,4 @@ export default class MovieResponse { get fullMovieUrl (): string { return `${TMDB_MOVIE_URL}/${this.id}` } - - get fullPosterPath (): string { - if (this.posterPath === null) return '' - - return `${TMDB_POSTER_URL}${this.posterPath}` - } } diff --git a/src/models/movie.ts b/src/models/movie.ts index 393fa1ad..e324c8db 100644 --- a/src/models/movie.ts +++ b/src/models/movie.ts @@ -66,7 +66,7 @@ export default class Movie { parseInt(tmdbResponse.releaseDate.split('-')[0]), tmdbResponse.runtime ?? -1, tmdbResponse.fullMovieUrl, - tmdbResponse.fullPosterPath, + tmdbResponse.posterPath, tmdbResponse.id, ) } From 32e9e09faab3ad916205435b9d0ea5a468a701f3 Mon Sep 17 00:00:00 2001 From: Jordan Welch Date: Fri, 29 Sep 2023 11:16:25 -0500 Subject: [PATCH 02/14] Add nodeEnv to config --- __tests__/config/config.spec.ts | 12 ++++++++++++ src/config/config.ts | 2 ++ 2 files changed, 14 insertions(+) diff --git a/__tests__/config/config.spec.ts b/__tests__/config/config.spec.ts index 5d4b6f63..3e12db30 100644 --- a/__tests__/config/config.spec.ts +++ b/__tests__/config/config.spec.ts @@ -4,6 +4,7 @@ import Config from '../../src/config/config' beforeEach(() => { jest.resetModules() process.env = { + NODE_ENV: 'production', NOTION_TOKEN: 'NOTION_TOKEN', DATABASE_ID: 'DATABASE_ID', PORT: '3000', @@ -19,6 +20,7 @@ describe('env variables all present', () => { it('returns the config', () => { const config = new Config() + expect(config.nodeEnv).toBe('production') expect(config.notionToken).toBe('NOTION_TOKEN') expect(config.notionDatabaseId).toBe('DATABASE_ID') expect(config.port).toBe(3000) @@ -99,3 +101,13 @@ describe('env missing CALENDAR_URL', () => { expect(() => new Config()).toThrowError('CALENDAR_URL is missing') }) }) + +describe('env missing NODE_ENV', () => { + beforeEach(() => { + delete process.env.NODE_ENV + }) + + it('defaults to development', () => { + expect(new Config().nodeEnv).toBe('development') + }) +}) diff --git a/src/config/config.ts b/src/config/config.ts index ed865e87..b26bfde0 100644 --- a/src/config/config.ts +++ b/src/config/config.ts @@ -6,6 +6,7 @@ export default class Config { notionToken: string port: number tmdbApiKey: string + nodeEnv: string constructor () { this.adminEmail = this.requiredVariable('ADMIN_EMAIL') @@ -15,6 +16,7 @@ export default class Config { this.notionToken = this.requiredVariable('NOTION_TOKEN') this.port = parseInt(this.optionalVariable('PORT', '8080')) this.tmdbApiKey = this.requiredVariable('TMDB_READ_KEY') + this.nodeEnv = this.optionalVariable('NODE_ENV', 'development') } requiredVariable (name: string): string { From eea90bb476e39d8bcc6f74f5f109d5d7e7dd6d85 Mon Sep 17 00:00:00 2001 From: Jordan Welch Date: Fri, 29 Sep 2023 11:22:08 -0500 Subject: [PATCH 03/14] Add isProduction helper --- __tests__/config/config.spec.ts | 22 ++++++++++++++++++++++ src/config/config.ts | 4 ++++ 2 files changed, 26 insertions(+) diff --git a/__tests__/config/config.spec.ts b/__tests__/config/config.spec.ts index 3e12db30..4f463400 100644 --- a/__tests__/config/config.spec.ts +++ b/__tests__/config/config.spec.ts @@ -111,3 +111,25 @@ describe('env missing NODE_ENV', () => { expect(new Config().nodeEnv).toBe('development') }) }) + +describe('isProduction', () => { + describe('when NODE_ENV is production', () => { + beforeEach(() => { + process.env.NODE_ENV = 'production' + }) + + it('returns true', () => { + expect(new Config().isProduction).toBe(true) + }) + }) + + describe('when NODE_ENV is development', () => { + beforeEach(() => { + process.env.NODE_ENV = 'development' + }) + + it('returns false', () => { + expect(new Config().isProduction).toBe(false) + }) + }) +}) diff --git a/src/config/config.ts b/src/config/config.ts index b26bfde0..16aa405f 100644 --- a/src/config/config.ts +++ b/src/config/config.ts @@ -19,6 +19,10 @@ export default class Config { this.nodeEnv = this.optionalVariable('NODE_ENV', 'development') } + get isProduction (): boolean { + return this.nodeEnv === 'production' + } + requiredVariable (name: string): string { const value = process.env[name] if (value == null) { From 08ef149bcad975c825b4621c3ef7ceb2bbce02b3 Mon Sep 17 00:00:00 2001 From: Jordan Welch Date: Fri, 29 Sep 2023 11:32:28 -0500 Subject: [PATCH 04/14] Use dev collections --- .../data/firestore/firestoreAdapter.spec.ts | 28 +++++++++++++++++ __tests__/support/mockConfig.ts | 5 +++- src/data/firestore/firestoreAdapter.ts | 30 +++++++++++++++---- 3 files changed, 57 insertions(+), 6 deletions(-) diff --git a/__tests__/data/firestore/firestoreAdapter.spec.ts b/__tests__/data/firestore/firestoreAdapter.spec.ts index 108f1ece..57e195e0 100644 --- a/__tests__/data/firestore/firestoreAdapter.spec.ts +++ b/__tests__/data/firestore/firestoreAdapter.spec.ts @@ -194,6 +194,34 @@ describe('cacheWeeks', () => { ) }) }) + + 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') + ) + }) + }) }) describe('createRsvp', () => { diff --git a/__tests__/support/mockConfig.ts b/__tests__/support/mockConfig.ts index 157d0d82..dcdf782c 100644 --- a/__tests__/support/mockConfig.ts +++ b/__tests__/support/mockConfig.ts @@ -1,7 +1,10 @@ import Config from '../../src/config/config.js' -export function mockConfig (): Config { +export function mockConfig ({ + nodeEnv = 'production', +} = {}): Config { process.env = { + NODE_ENV: nodeEnv, NOTION_TOKEN: 'NOTION_TOKEN', DATABASE_ID: 'DATABASE_ID', PORT: '3000', diff --git a/src/data/firestore/firestoreAdapter.ts b/src/data/firestore/firestoreAdapter.ts index b3cc7d13..84461198 100644 --- a/src/data/firestore/firestoreAdapter.ts +++ b/src/data/firestore/firestoreAdapter.ts @@ -38,7 +38,7 @@ export default class FirestoreAdapter { weeks.forEach((week: Week) => { const ref = doc( this.firestore, - FirestoreAdapter.WEEKS_COLLECTION_NAME, + this.weeksCollectionName, week.dateString ) transaction.set(ref, week.toFirebaseDTO()) @@ -131,7 +131,7 @@ export default class FirestoreAdapter { }) => { transaction.set(doc( this.firestore, - FirestoreAdapter.TEMPLATES_COLLECTION_NAME, + this.templatesCollectionName, template.name ), { subject: template.subject, @@ -152,16 +152,36 @@ export default class FirestoreAdapter { return this.config.adminEmail } + private get mailCollectionName (): string { + return this.collectionName(FirestoreAdapter.MAIL_COLLECTION_NAME) + } + + private get rsvpsCollectionName (): string { + return this.collectionName(FirestoreAdapter.RSVPS_COLLECTION_NAME) + } + + private get templatesCollectionName (): string { + return this.collectionName(FirestoreAdapter.TEMPLATES_COLLECTION_NAME) + } + + private get weeksCollectionName (): string { + return this.collectionName(FirestoreAdapter.WEEKS_COLLECTION_NAME) + } + private get mailCollection (): Collection { - return collection(this.firestore, FirestoreAdapter.MAIL_COLLECTION_NAME) + return collection(this.firestore, this.mailCollectionName) } private get rsvpCollection (): Collection { - return collection(this.firestore, FirestoreAdapter.RSVPS_COLLECTION_NAME) + return collection(this.firestore, this.rsvpsCollectionName) } private get weekCollection (): Collection { - return collection(this.firestore, FirestoreAdapter.WEEKS_COLLECTION_NAME) + return collection(this.firestore, this.weeksCollectionName) + } + + private collectionName (name: string): string { + return this.config.isProduction ? name : `${name}-dev` } } From 890df91ce1a1bba2061fe1ff524e1dc21e1c8fbf Mon Sep 17 00:00:00 2001 From: Jordan Welch Date: Wed, 4 Oct 2023 12:58:48 -0500 Subject: [PATCH 05/14] Add toDTO test --- __tests__/models/movie.spec.ts | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/__tests__/models/movie.spec.ts b/__tests__/models/movie.spec.ts index 6caa1cd1..b69ebbe7 100644 --- a/__tests__/models/movie.spec.ts +++ b/__tests__/models/movie.spec.ts @@ -80,3 +80,33 @@ describe('toNotion', () => { }) }) }) + +describe('toDTO', () => { + it('should return a DTO', () => { + const movie = new Movie( + 'Movie Title', + 'Movie Director', + 2021, + 90, + 'Movie Url', + 'Movie Poster Url', + 1234, + 'notionId', + 'Theater', + 'Showing Url', + ) + + expect(movie.toDTO()).toEqual({ + title: movie.title, + director: movie.director, + year: movie.year, + length: movie.length, + url: movie.url, + posterUrl: movie.posterUrl, + theaterName: movie.theaterName, + showingUrl: movie.showingUrl, + isFieldTrip: true, + displayLength: '1h 30m', + }) + }) +}) From 25640be061c8ecdc16db7f13b471952d8033e6d8 Mon Sep 17 00:00:00 2001 From: Jordan Welch Date: Wed, 4 Oct 2023 13:05:41 -0500 Subject: [PATCH 06/14] Refactor to MovieFactory --- __tests__/models/movie.spec.ts | 14 ++-------- __tests__/support/factories/movieFactory.ts | 31 +++++++++++++++++++++ 2 files changed, 33 insertions(+), 12 deletions(-) create mode 100644 __tests__/support/factories/movieFactory.ts diff --git a/__tests__/models/movie.spec.ts b/__tests__/models/movie.spec.ts index b69ebbe7..4da417a0 100644 --- a/__tests__/models/movie.spec.ts +++ b/__tests__/models/movie.spec.ts @@ -1,5 +1,6 @@ import { describe, expect, it, test } from '@jest/globals' import Movie from '../../src/models/movie' +import { MovieFactory } from '../support/factories/movieFactory' describe('merge', () => { test('only null/undefined fields are overwritten by merge', () => { @@ -83,18 +84,7 @@ describe('toNotion', () => { describe('toDTO', () => { it('should return a DTO', () => { - const movie = new Movie( - 'Movie Title', - 'Movie Director', - 2021, - 90, - 'Movie Url', - 'Movie Poster Url', - 1234, - 'notionId', - 'Theater', - 'Showing Url', - ) + const movie = new MovieFactory().make() expect(movie.toDTO()).toEqual({ title: movie.title, diff --git a/__tests__/support/factories/movieFactory.ts b/__tests__/support/factories/movieFactory.ts new file mode 100644 index 00000000..26f93609 --- /dev/null +++ b/__tests__/support/factories/movieFactory.ts @@ -0,0 +1,31 @@ +import Movie from '../../../src/models/movie' + +export class MovieFactory { + private state = { + title: 'Movie Title', + director: 'Movie Director', + year: 2021, + length: 90, + url: 'Movie Url', + tmdbId: 1234, + posterUrl: 'Movie Poster Url', + notionId: 'notionId', + theaterName: 'Theater', + showingUrl: 'Showing Url', + } + + make (): Movie { + return new Movie( + this.state.title, + this.state.director, + this.state.year, + this.state.length, + this.state.url, + this.state.posterUrl, + this.state.tmdbId, + this.state.notionId, + this.state.theaterName, + this.state.showingUrl, + ) + } +} From 5ea90d6e9789d254858a40e09fb138a98508a947 Mon Sep 17 00:00:00 2001 From: Jordan Welch Date: Wed, 4 Oct 2023 13:08:02 -0500 Subject: [PATCH 07/14] Add state --- __tests__/models/movie.spec.ts | 22 +++++++++++++++++ __tests__/support/factories/movieFactory.ts | 27 ++++++++++++--------- 2 files changed, 38 insertions(+), 11 deletions(-) diff --git a/__tests__/models/movie.spec.ts b/__tests__/models/movie.spec.ts index 4da417a0..3be7accf 100644 --- a/__tests__/models/movie.spec.ts +++ b/__tests__/models/movie.spec.ts @@ -99,4 +99,26 @@ describe('toDTO', () => { displayLength: '1h 30m', }) }) + + describe('No poster or theaterName', () => { + it('marks isFieldTrip as false', () => { + const movie = new MovieFactory().state({ + posterUrl: null, + theaterName: null, + }).make() + + expect(movie.toDTO()).toEqual({ + title: movie.title, + director: movie.director, + year: movie.year, + length: movie.length, + url: movie.url, + posterUrl: null, + theaterName: null, + showingUrl: movie.showingUrl, + isFieldTrip: false, + displayLength: '1h 30m', + }) + }) + }) }) diff --git a/__tests__/support/factories/movieFactory.ts b/__tests__/support/factories/movieFactory.ts index 26f93609..1ec04147 100644 --- a/__tests__/support/factories/movieFactory.ts +++ b/__tests__/support/factories/movieFactory.ts @@ -1,7 +1,7 @@ import Movie from '../../../src/models/movie' export class MovieFactory { - private state = { + private _state = { title: 'Movie Title', director: 'Movie Director', year: 2021, @@ -16,16 +16,21 @@ export class MovieFactory { make (): Movie { return new Movie( - this.state.title, - this.state.director, - this.state.year, - this.state.length, - this.state.url, - this.state.posterUrl, - this.state.tmdbId, - this.state.notionId, - this.state.theaterName, - this.state.showingUrl, + this._state.title, + this._state.director, + this._state.year, + this._state.length, + this._state.url, + this._state.posterUrl, + this._state.tmdbId, + this._state.notionId, + this._state.theaterName, + this._state.showingUrl, ) } + + state (state: Partial): MovieFactory { + this._state = { ...this._state, ...state } + return this + } } From ef6b36fc69edbd009c14d49e04ceaad195f91d94 Mon Sep 17 00:00:00 2001 From: Jordan Welch Date: Wed, 4 Oct 2023 13:11:52 -0500 Subject: [PATCH 08/14] posterUrl -> posterPath --- __tests__/data/firestore/firestoreAdapter.spec.ts | 4 ++-- __tests__/data/notion/notionAdapter.spec.ts | 2 +- __tests__/models/movie.spec.ts | 8 ++++---- __tests__/support/factories/movieFactory.ts | 6 +++--- __tests__/support/notionHelpers.ts | 6 +++--- __tests__/support/tmdbMock.ts | 4 ++-- emails/reminder.mjml | 2 +- emails/rsvpConfirmation.mjml | 2 +- src/data/firestore/firestoreTypes.ts | 2 +- src/models/movie.ts | 12 ++++++------ views/partials/movie.ejs | 2 +- 11 files changed, 25 insertions(+), 25 deletions(-) diff --git a/__tests__/data/firestore/firestoreAdapter.spec.ts b/__tests__/data/firestore/firestoreAdapter.spec.ts index 57e195e0..09d6c186 100644 --- a/__tests__/data/firestore/firestoreAdapter.spec.ts +++ b/__tests__/data/firestore/firestoreAdapter.spec.ts @@ -282,7 +282,7 @@ describe('sendEmailTemplate', () => { title: 'test title', year: '2021', time: '6:00pm', - posterUrl: 'https://example.com/poster.jpg', + posterPath: 'https://example.com/poster.jpg', }, ], }) @@ -301,7 +301,7 @@ describe('sendEmailTemplate', () => { title: 'test title', year: '2021', time: '6:00pm', - posterUrl: 'https://example.com/poster.jpg', + posterPath: 'https://example.com/poster.jpg', }, ], }, diff --git a/__tests__/data/notion/notionAdapter.spec.ts b/__tests__/data/notion/notionAdapter.spec.ts index e3875ab6..4cb2070a 100644 --- a/__tests__/data/notion/notionAdapter.spec.ts +++ b/__tests__/data/notion/notionAdapter.spec.ts @@ -46,7 +46,7 @@ describe('getMovie', () => { year: 2021, length: 120, url: 'movieUrl', - posterUrl: 'moviePosterUrl', + posterPath: 'moviePosterPath', theaterName: 'movieTheaterName', showingUrl: 'movieShowingUrl', tmdbId: null, diff --git a/__tests__/models/movie.spec.ts b/__tests__/models/movie.spec.ts index 3be7accf..390cbcad 100644 --- a/__tests__/models/movie.spec.ts +++ b/__tests__/models/movie.spec.ts @@ -52,7 +52,7 @@ describe('toNotion', () => { Year: { number: movie.year }, 'Length (mins)': { number: movie.length }, URL: { url: movie.url }, - Poster: { url: movie.posterUrl }, + Poster: { url: movie.posterPath }, 'Theater Name': { rich_text: [ { text: { content: movie.theaterName } }, ] }, @@ -92,7 +92,7 @@ describe('toDTO', () => { year: movie.year, length: movie.length, url: movie.url, - posterUrl: movie.posterUrl, + posterPath: movie.posterPath, theaterName: movie.theaterName, showingUrl: movie.showingUrl, isFieldTrip: true, @@ -103,7 +103,7 @@ describe('toDTO', () => { describe('No poster or theaterName', () => { it('marks isFieldTrip as false', () => { const movie = new MovieFactory().state({ - posterUrl: null, + posterPath: null, theaterName: null, }).make() @@ -113,7 +113,7 @@ describe('toDTO', () => { year: movie.year, length: movie.length, url: movie.url, - posterUrl: null, + posterPath: null, theaterName: null, showingUrl: movie.showingUrl, isFieldTrip: false, diff --git a/__tests__/support/factories/movieFactory.ts b/__tests__/support/factories/movieFactory.ts index 1ec04147..0c93adbd 100644 --- a/__tests__/support/factories/movieFactory.ts +++ b/__tests__/support/factories/movieFactory.ts @@ -6,9 +6,9 @@ export class MovieFactory { director: 'Movie Director', year: 2021, length: 90, - url: 'Movie Url', + url: 'https://example.com/movie1234', tmdbId: 1234, - posterUrl: 'Movie Poster Url', + posterPath: '/path/to/poster.jpg', notionId: 'notionId', theaterName: 'Theater', showingUrl: 'Showing Url', @@ -21,7 +21,7 @@ export class MovieFactory { this._state.year, this._state.length, this._state.url, - this._state.posterUrl, + this._state.posterPath, this._state.tmdbId, this._state.notionId, this._state.theaterName, diff --git a/__tests__/support/notionHelpers.ts b/__tests__/support/notionHelpers.ts index 029fb0f5..fa06c51e 100644 --- a/__tests__/support/notionHelpers.ts +++ b/__tests__/support/notionHelpers.ts @@ -154,7 +154,7 @@ export class NotionMovie { public year: number | null = null, public length: number | null = null, public url: string | null = null, - public posterUrl: string | null = null, + public posterPath: string | null = null, public theaterName: string | null = null, public showingUrl: string | null = null, ) {} @@ -166,7 +166,7 @@ export class NotionMovie { Year: nNumber(this.year), 'Length (mins)': nNumber(this.length), URL: nUrl(this.url), - Poster: nUrl(this.posterUrl), + Poster: nUrl(this.posterPath), 'Theater Name': nRichText(this.theaterName), 'Showing URL': nUrl(this.showingUrl), }) @@ -180,7 +180,7 @@ export class NotionMovie { 2021, 120, 'movieUrl', - 'moviePosterUrl', + 'moviePosterPath', 'movieTheaterName', 'movieShowingUrl' ) diff --git a/__tests__/support/tmdbMock.ts b/__tests__/support/tmdbMock.ts index 6fb0571e..2e11e877 100644 --- a/__tests__/support/tmdbMock.ts +++ b/__tests__/support/tmdbMock.ts @@ -14,7 +14,7 @@ export class TmdbMock { { id: id, original_title: movie.title, - poster_path: movie.posterUrl, + poster_path: movie.posterPath, release_date: `${movie.year}-07-19`, title: movie.title, adult: false, @@ -38,7 +38,7 @@ export class TmdbMock { .mockImplementationOnce(async () => new Response(JSON.stringify({ id: id, original_title: movie.title, - poster_path: movie.posterUrl, + poster_path: movie.posterPath, release_date: `${movie.year}-07-19`, title: movie.title, adult: false, diff --git a/emails/reminder.mjml b/emails/reminder.mjml index 284444a0..2b9f1626 100644 --- a/emails/reminder.mjml +++ b/emails/reminder.mjml @@ -69,7 +69,7 @@ >{{ movie.title }} {{ movie.title }} From d303ba1d771a962576aa0b011f1a6a22fbc7dd1a Mon Sep 17 00:00:00 2001 From: Jordan Welch Date: Wed, 4 Oct 2023 13:15:09 -0500 Subject: [PATCH 09/14] Add posterUrl back as function --- __tests__/models/movie.spec.ts | 19 +++++++++++++++++++ src/models/movie.ts | 7 +++++++ 2 files changed, 26 insertions(+) diff --git a/__tests__/models/movie.spec.ts b/__tests__/models/movie.spec.ts index 390cbcad..82c43337 100644 --- a/__tests__/models/movie.spec.ts +++ b/__tests__/models/movie.spec.ts @@ -1,6 +1,7 @@ import { describe, expect, it, test } from '@jest/globals' import Movie from '../../src/models/movie' import { MovieFactory } from '../support/factories/movieFactory' +import { TMDB_POSTER_URL } from '../../src/data/tmdb/constants' describe('merge', () => { test('only null/undefined fields are overwritten by merge', () => { @@ -122,3 +123,21 @@ describe('toDTO', () => { }) }) }) + +describe('posterUrl', () => { + it('appends the posterPath to the base url', () => { + const movie = new MovieFactory().make() + + expect(movie.posterUrl()).toEqual( + `${TMDB_POSTER_URL}${movie.posterPath}` + ) + }) + + describe('posterPath is null', () => { + it('returns an empty string', () => { + const movie = new MovieFactory().state({ posterPath: null }).make() + + expect(movie.posterUrl()).toEqual('') + }) + }) +}) diff --git a/src/models/movie.ts b/src/models/movie.ts index d6d10fa8..388d41e3 100644 --- a/src/models/movie.ts +++ b/src/models/movie.ts @@ -12,6 +12,7 @@ import { notionUrl, } from '../data/notion/notionFormatters.js' import { FirestoreMovie } from '../data/firestore/firestoreTypes.js' +import { TMDB_POSTER_URL } from '../data/tmdb/constants.js' export default class Movie { constructor ( @@ -85,6 +86,12 @@ export default class Movie { : `${this.length}m` } + posterUrl (): string { + return this.posterPath + ? `${TMDB_POSTER_URL}${this.posterPath}` + : '' + } + toString (): string { return `${this.title} (${this.year})` } From f55ae67969b05ab58c508a95391c00ec896f2eff Mon Sep 17 00:00:00 2001 From: Jordan Welch Date: Wed, 4 Oct 2023 13:26:13 -0500 Subject: [PATCH 10/14] update to use w500 --- src/data/tmdb/constants.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/data/tmdb/constants.ts b/src/data/tmdb/constants.ts index d027b026..8b39999d 100644 --- a/src/data/tmdb/constants.ts +++ b/src/data/tmdb/constants.ts @@ -1,3 +1,3 @@ export const TMDB_BASE_URL = 'https://api.themoviedb.org/3' export const TMDB_MOVIE_URL = 'https://www.themoviedb.org/movie' -export const TMDB_POSTER_URL = 'https://image.tmdb.org/t/p/original' +export const TMDB_POSTER_URL = 'https://image.tmdb.org/t/p/w500' From c87bd001c5e76281b4a3de26a46b585943adb5a5 Mon Sep 17 00:00:00 2001 From: Jordan Welch Date: Wed, 4 Oct 2023 13:27:41 -0500 Subject: [PATCH 11/14] Fix test --- __tests__/models/movie.spec.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/__tests__/models/movie.spec.ts b/__tests__/models/movie.spec.ts index 82c43337..69d3ec70 100644 --- a/__tests__/models/movie.spec.ts +++ b/__tests__/models/movie.spec.ts @@ -101,10 +101,10 @@ describe('toDTO', () => { }) }) - describe('No poster or theaterName', () => { + describe('No showingUrl or theaterName', () => { it('marks isFieldTrip as false', () => { const movie = new MovieFactory().state({ - posterPath: null, + showingUrl: null, theaterName: null, }).make() @@ -114,7 +114,7 @@ describe('toDTO', () => { year: movie.year, length: movie.length, url: movie.url, - posterPath: null, + posterPath: movie.posterPath, theaterName: null, showingUrl: movie.showingUrl, isFieldTrip: false, From 1a6924ebc251b29f2df6d7fa278b26e08b1dcc5a Mon Sep 17 00:00:00 2001 From: Jordan Welch Date: Wed, 4 Oct 2023 14:05:34 -0500 Subject: [PATCH 12/14] use posterUrl for website --- __tests__/models/movie.spec.ts | 10 +++++----- src/models/movie.ts | 2 +- views/partials/movie.ejs | 2 +- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/__tests__/models/movie.spec.ts b/__tests__/models/movie.spec.ts index 69d3ec70..8936a316 100644 --- a/__tests__/models/movie.spec.ts +++ b/__tests__/models/movie.spec.ts @@ -93,11 +93,11 @@ describe('toDTO', () => { year: movie.year, length: movie.length, url: movie.url, - posterPath: movie.posterPath, + posterUrl: movie.posterUrl(), theaterName: movie.theaterName, showingUrl: movie.showingUrl, isFieldTrip: true, - displayLength: '1h 30m', + displayLength: movie.displayLength(), }) }) @@ -114,11 +114,11 @@ describe('toDTO', () => { year: movie.year, length: movie.length, url: movie.url, - posterPath: movie.posterPath, - theaterName: null, + posterUrl: movie.posterUrl(), + theaterName: movie.theaterName, showingUrl: movie.showingUrl, isFieldTrip: false, - displayLength: '1h 30m', + displayLength: movie.displayLength(), }) }) }) diff --git a/src/models/movie.ts b/src/models/movie.ts index 388d41e3..88bf033a 100644 --- a/src/models/movie.ts +++ b/src/models/movie.ts @@ -103,7 +103,7 @@ export default class Movie { year: this.year, length: this.length, url: this.url, - posterPath: this.posterPath, + posterUrl: this.posterUrl(), theaterName: this.theaterName, showingUrl: this.showingUrl, isFieldTrip: this.isFieldTrip(), diff --git a/views/partials/movie.ejs b/views/partials/movie.ejs index 32efdae2..4041dc9a 100644 --- a/views/partials/movie.ejs +++ b/views/partials/movie.ejs @@ -23,7 +23,7 @@ class="w-full" > From dae320ac321c9e501f7ee5c7d53824d45fd0f8aa Mon Sep 17 00:00:00 2001 From: Jordan Welch Date: Wed, 4 Oct 2023 14:20:46 -0500 Subject: [PATCH 13/14] Handle single movies sizes. --- views/partials/movie.ejs | 9 +-------- views/partials/weeks.ejs | 19 +++++++++++++++++++ 2 files changed, 20 insertions(+), 8 deletions(-) diff --git a/views/partials/movie.ejs b/views/partials/movie.ejs index 4041dc9a..f6db2382 100644 --- a/views/partials/movie.ejs +++ b/views/partials/movie.ejs @@ -1,11 +1,4 @@ - - -
+

+