From 92d836a9f59dfdf527c371a644601453171e3242 Mon Sep 17 00:00:00 2001 From: Inga <52715130+inga-lovinde@users.noreply.github.com> Date: Sun, 10 Dec 2023 11:12:05 +0000 Subject: [PATCH] added test case for episode; improved types; minor improvements --- .../movies/omdb/converters.spec.ts | 49 +++++++++++++++++++ src/integration/movies/omdb/converters.ts | 8 ++- src/integration/movies/omdb/types.ts | 7 ++- src/integration/movies/types.ts | 43 +++++++--------- src/utils/objectHelpers.ts | 6 ++- 5 files changed, 83 insertions(+), 30 deletions(-) diff --git a/src/integration/movies/omdb/converters.spec.ts b/src/integration/movies/omdb/converters.spec.ts index 5d3779b..4632cd3 100644 --- a/src/integration/movies/omdb/converters.spec.ts +++ b/src/integration/movies/omdb/converters.spec.ts @@ -268,4 +268,53 @@ describe('normalizeRawOmdbData', () => { writers: ['Olivia Vieweg'], }); }); + + it('normalizes data correctly for tt10703258 (episode)', () => { + const result = normalizeRawOmdbData({ + Title: "Seo Hee's Resentment", + Year: '2019', + Rated: 'N/A', + Released: '24 Aug 2019', + Season: '1', + Episode: '13', + Runtime: '82 min', + Genre: 'Action, Comedy, Drama', + Director: 'Choong Hwan Oh', + Writer: 'Jeong-eun Hong, Mi-ran Hong', + Actors: 'Ji-eun Lee, Yeo Jin-gu, Shin Jeong-geun', + Plot: "Choi Seo Hee prepares to move on to the next life. The killer ghost terrorizes Chan Seong's friends. Man Wol witnesses a startling relationship.", + Language: 'Korean', + Country: 'South Korea', + Awards: 'N/A', + Poster: 'https://m.media-amazon.com/images/M/MV5BODVlYzg4MWYtOTU2Ny00OWY0LWIzYTItNWExYmM3MjJhNmJjXkEyXkFqcGdeQXVyNzk0NTA5NQ@@._V1_SX300.jpg', + Ratings: [], + Metascore: 'N/A', + imdbRating: 'N/A', + imdbVotes: '147', + imdbID: 'tt10703258', + seriesID: 't10220588', + Type: 'episode', + }); + expect(result).toEqual({ + actors: ['Ji-eun Lee', 'Yeo Jin-gu', 'Shin Jeong-geun'], + description: + "Choi Seo Hee prepares to move on to the next life. The killer ghost terrorizes Chan Seong's friends. Man Wol witnesses a startling relationship.", + directors: ['Choong Hwan Oh'], + duration: 82, + episodeNumber: 13, + genres: ['Action', 'Comedy', 'Drama'], + imdbId: 'tt10703258', + posterUrl: + 'https://m.media-amazon.com/images/M/MV5BODVlYzg4MWYtOTU2Ny00OWY0LWIzYTItNWExYmM3MjJhNmJjXkEyXkFqcGdeQXVyNzk0NTA5NQ@@._V1_SX300.jpg', + productionCountries: ['South Korea'], + productionYear: 2019, + ratings: [], + releaseDate: '24 Aug 2019', + seasonNumber: 1, + seriesImdbId: 't10220588', + title: "Seo Hee's Resentment", + type: 'episode', + writers: ['Jeong-eun Hong', 'Mi-ran Hong'], + }); + }); }); diff --git a/src/integration/movies/omdb/converters.ts b/src/integration/movies/omdb/converters.ts index f5c7e75..03c07c5 100644 --- a/src/integration/movies/omdb/converters.ts +++ b/src/integration/movies/omdb/converters.ts @@ -30,6 +30,7 @@ export const normalizeRawOmdbData = ( Country, DVD, Director, + Episode, Genre, Language: _language, Metascore: _metascore, @@ -40,6 +41,7 @@ export const normalizeRawOmdbData = ( Ratings, Released, Runtime, + Season, Title, Type, Website, @@ -48,6 +50,7 @@ export const normalizeRawOmdbData = ( imdbID, imdbRating: _imdbRating, imdbVotes: _imdbVotes, + seriesID, totalSeasons, ...rest } = rawOmdbData; @@ -61,13 +64,14 @@ export const normalizeRawOmdbData = ( return { ...createRequiredField('actors', Actors, stringToArray), - ...createRequiredField('awards', Awards, identity), + ...createOptionalField('awards', Awards, identity), ...createOptionalField('boxOffice', BoxOffice, identity), ...createOptionalField('contentRating', Rated, identity), ...createRequiredField('description', Plot, identity), ...createOptionalField('directors', Director, stringToArray), ...createRequiredField('duration', Runtime, stringToDuration), ...createOptionalField('dvdReleaseDate', DVD, identity), + ...createOptionalField('episodeNumber', Episode, stringToNumber), ...createRequiredField('genres', Genre, stringToArray), ...createRequiredField('imdbId', imdbID, identity), ...createRequiredField('posterUrl', Poster, identity), @@ -79,6 +83,8 @@ export const normalizeRawOmdbData = ( omdbRatingsToNormalizedRatings, ), ...createRequiredField('releaseDate', Released, identity), + ...createOptionalField('seasonNumber', Season, stringToNumber), + ...createOptionalField('seriesImdbId', seriesID, identity), ...createRequiredField('title', Title, identity), ...createOptionalField('totalSeasons', totalSeasons, stringToNumber), ...createRequiredField('type', Type, identity), diff --git a/src/integration/movies/omdb/types.ts b/src/integration/movies/omdb/types.ts index 0c758a5..b0a04f7 100644 --- a/src/integration/movies/omdb/types.ts +++ b/src/integration/movies/omdb/types.ts @@ -1,10 +1,11 @@ export type RawOmdbData = { Actors: string; - Awards: string; + Awards?: string; BoxOffice?: string; Country: string; DVD?: string; Director: string; + Episode?: string; Genre: string; Language: string; Metascore: string; @@ -18,14 +19,16 @@ export type RawOmdbData = { }[]; Released: string; Runtime: string; + Season?: string; Title: string; - Type: 'movie' | 'series'; + Type: 'movie' | 'series' | 'episode'; Website?: string; Writer: string; Year: string; imdbID: string; imdbRating: string; imdbVotes: string; + seriesID?: string; totalSeasons?: string; }; diff --git a/src/integration/movies/types.ts b/src/integration/movies/types.ts index 5e937a1..d415c05 100644 --- a/src/integration/movies/types.ts +++ b/src/integration/movies/types.ts @@ -6,12 +6,15 @@ type MovieData = { description: string; localDescription: string; posterUrl: string; - type: 'movie' | 'series'; + type: 'movie' | 'series' | 'episode'; + seriesImdbId?: string; + episodeNumber?: number; + seasonNumber?: number; /** * A whole number of minutes */ duration: number; - totalSeasons: number; + totalSeasons?: number; /** * Two-letter code */ @@ -22,45 +25,33 @@ type MovieData = { availableLanguages: string[]; productionYear: number; releaseDate: string; - dvdReleaseDate: string; + dvdReleaseDate?: string; genres: string[]; - directors: string[]; + directors?: string[]; writers: string[]; actors: string[]; studios: string[]; - awards: string; + awards?: string; productionCountries: string[]; - boxOffice: string; - contentRating: string; - website: string; + boxOffice?: string; + contentRating?: string; + website?: string; ratings: { source: string; value: string; }[]; }; -type StrictPartial< - T, - TForbiddenKeys extends keyof T, - TOptionalKeys extends Exclude, -> = Omit & Partial>; - -export type NormalizedOmdbData = StrictPartial< +export type NormalizedOmdbData = Omit< MovieData, | 'availableLanguages' | 'localDescription' | 'localTitle' | 'originalLanguage' - | 'studios', - | 'boxOffice' - | 'contentRating' - | 'directors' - | 'dvdReleaseDate' - | 'totalSeasons' - | 'website' + | 'studios' >; -export type NormalizedInternalData = StrictPartial< +export type NormalizedInternalData = Omit< MovieData, | 'actors' | 'awards' @@ -69,16 +60,18 @@ export type NormalizedInternalData = StrictPartial< | 'description' | 'directors' | 'dvdReleaseDate' + | 'episodeNumber' | 'genres' | 'posterUrl' | 'productionCountries' | 'releaseDate' + | 'seasonNumber' + | 'seriesImdbId' | 'title' | 'totalSeasons' | 'type' | 'website' - | 'writers', - never + | 'writers' > & { internalId: number; }; diff --git a/src/utils/objectHelpers.ts b/src/utils/objectHelpers.ts index 5c62065..4c78f43 100644 --- a/src/utils/objectHelpers.ts +++ b/src/utils/objectHelpers.ts @@ -9,7 +9,7 @@ export const createTargetHelpers = ( >( key: TKey, value: TRawValue, - transformer: (value: TRawValue) => TTarget[TKey], + transformer: (value: TRawValue) => Exclude, ) => { if (value === undefined) { throw new Error(`Value for ${key} is not defined`); @@ -30,7 +30,9 @@ export const createTargetHelpers = ( >( key: TKey, value: TRawValue, - transformer: (value: Exclude) => TTarget[TKey], + transformer: ( + value: Exclude, + ) => Exclude, ) => { if (value === undefined || missingValueIndicators.includes(value)) { return undefined;