added test case for episode; improved types; minor improvements

main
Inga 🏳‍🌈 12 months ago
parent 08840712af
commit 92d836a9f5
  1. 49
      src/integration/movies/omdb/converters.spec.ts
  2. 8
      src/integration/movies/omdb/converters.ts
  3. 7
      src/integration/movies/omdb/types.ts
  4. 43
      src/integration/movies/types.ts
  5. 6
      src/utils/objectHelpers.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'],
});
});
});

@ -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),

@ -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;
};

@ -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<keyof T, TForbiddenKeys>,
> = Omit<T, TForbiddenKeys | TOptionalKeys> & Partial<Pick<T, TOptionalKeys>>;
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;
};

@ -9,7 +9,7 @@ export const createTargetHelpers = <TTarget>(
>(
key: TKey,
value: TRawValue,
transformer: (value: TRawValue) => TTarget[TKey],
transformer: (value: TRawValue) => Exclude<TTarget[TKey], undefined>,
) => {
if (value === undefined) {
throw new Error(`Value for ${key} is not defined`);
@ -30,7 +30,9 @@ export const createTargetHelpers = <TTarget>(
>(
key: TKey,
value: TRawValue,
transformer: (value: Exclude<TRawValue, undefined>) => TTarget[TKey],
transformer: (
value: Exclude<TRawValue, undefined>,
) => Exclude<TTarget[TKey], undefined>,
) => {
if (value === undefined || missingValueIndicators.includes(value)) {
return undefined;

Loading…
Cancel
Save