extracted test omdb client with test data to test helpers

main
Inga 🏳‍🌈 12 months ago
parent 4ec2cb033e
commit 5147882e6a
  1. 170
      src/services/omdbEnrichedDataService.spec.ts
  2. 171
      src/utils/testHelpers.ts

@ -1,174 +1,8 @@
import { describe, it, expect } from '@jest/globals'; import { describe, it, expect } from '@jest/globals';
import { createInternalProvider } from '../integration/movies/internal'; import { createTestOmdbEnrichedDataService } from '../utils/testHelpers';
import { createOmdbProviderByApiClient } from '../integration/movies/omdb';
import type {
OmdbApiClient,
RawOmdbData,
} from '../integration/movies/omdb/types';
import { createOmdbEnrichedDataService } from './omdbEnrichedDataService';
const omdbResponses: Record<string, RawOmdbData> = {
tt0401792: {
Title: 'Sin City',
Year: '2005',
Rated: 'R',
Released: '01 Apr 2005',
Runtime: '124 min',
Genre: 'Crime, Thriller',
Director: 'Frank Miller, Quentin Tarantino, Robert Rodriguez',
Writer: 'Frank Miller, Robert Rodriguez',
Actors: 'Mickey Rourke, Clive Owen, Bruce Willis',
Plot: "Four tales of crime adapted from Frank Miller's popular comics, focusing around a muscular brute who's looking for the person responsible for the death of his beloved Goldie (Jaime King), a man fed up with Sin City's corrupt law enforcement who takes the law into his own hands after a horrible mistake, a cop who risks his life to protect a girl from a deformed pedophile and a hitman looking to make a little cash.",
Language: 'English',
Country: 'United States',
Awards: '38 wins & 54 nominations',
Poster: 'https://m.media-amazon.com/images/M/MV5BODZmYjMwNzEtNzVhNC00ZTRmLTk2M2UtNzE1MTQ2ZDAxNjc2XkEyXkFqcGdeQXVyMTQxNzMzNDI@._V1_SX300.jpg',
Ratings: [
{ Source: 'Internet Movie Database', Value: '8.0/10' },
{ Source: 'Rotten Tomatoes', Value: '76%' },
{ Source: 'Metacritic', Value: '74/100' },
],
Metascore: '74',
imdbRating: '8.0',
imdbVotes: '786,745',
imdbID: 'tt0401792',
Type: 'movie',
DVD: '03 Sep 2016',
BoxOffice: '$74,103,820',
Production: 'N/A',
Website: 'N/A',
},
tt0097576: {
Title: 'Indiana Jones and the Last Crusade',
Year: '1989',
Rated: 'PG-13',
Released: '24 May 1989',
Runtime: '127 min',
Genre: 'Action, Adventure',
Director: 'Steven Spielberg',
Writer: 'Jeffrey Boam, George Lucas, Menno Meyjes',
Actors: 'Harrison Ford, Sean Connery, Alison Doody',
Plot: 'An art collector appeals to Indiana Jones to embark on a search for the Holy Grail. He learns that another archaeologist has disappeared while searching for the precious goblet, and the missing man is his own father, Dr. Henry Jones. The artifact is much harder to find than they expected, and its powers are too much for those impure of heart.',
Language: 'English, German, Greek, Latin, Italian',
Country: 'United States',
Awards: 'Won 1 Oscar. 9 wins & 24 nominations total',
Poster: 'https://m.media-amazon.com/images/M/MV5BY2Q0ODg4ZmItNDZiYi00ZWY5LTg2NzctNmYwZjA5OThmNzE1XkEyXkFqcGdeQXVyMjM4MzQ4OTQ@._V1_SX300.jpg',
Ratings: [
{ Source: 'Internet Movie Database', Value: '8.2/10' },
{ Source: 'Rotten Tomatoes', Value: '84%' },
{ Source: 'Metacritic', Value: '65/100' },
],
Metascore: '65',
imdbRating: '8.2',
imdbVotes: '797,615',
imdbID: 'tt0097576',
Type: 'movie',
DVD: '28 Jan 2014',
BoxOffice: '$197,171,806',
Production: 'N/A',
Website: 'N/A',
},
tt0076759: {
Title: 'Star Wars: Episode IV - A New Hope',
Year: '1977',
Rated: 'PG',
Released: '25 May 1977',
Runtime: '121 min',
Genre: 'Action, Adventure, Fantasy',
Director: 'George Lucas',
Writer: 'George Lucas',
Actors: 'Mark Hamill, Harrison Ford, Carrie Fisher',
Plot: 'The Imperial Forces, under orders from cruel Darth Vader, hold Princess Leia hostage in their efforts to quell the rebellion against the Galactic Empire. Luke Skywalker and Han Solo, captain of the Millennium Falcon, work together with the companionable droid duo R2-D2 and C-3PO to rescue the beautiful princess, help the Rebel Alliance and restore freedom and justice to the Galaxy.',
Language: 'English',
Country: 'United States',
Awards: 'Won 6 Oscars. 65 wins & 31 nominations total',
Poster: 'https://m.media-amazon.com/images/M/MV5BOTA5NjhiOTAtZWM0ZC00MWNhLThiMzEtZDFkOTk2OTU1ZDJkXkEyXkFqcGdeQXVyMTA4NDI1NTQx._V1_SX300.jpg',
Ratings: [
{ Source: 'Internet Movie Database', Value: '8.6/10' },
{ Source: 'Rotten Tomatoes', Value: '93%' },
{ Source: 'Metacritic', Value: '90/100' },
],
Metascore: '90',
imdbRating: '8.6',
imdbVotes: '1,424,627',
imdbID: 'tt0076759',
Type: 'movie',
DVD: '10 Oct 2016',
BoxOffice: '$460,998,507',
Production: 'N/A',
Website: 'N/A',
},
tt0061852: {
Title: 'The Jungle Book',
Year: '1967',
Rated: 'G',
Released: '18 Oct 1967',
Runtime: '78 min',
Genre: 'Animation, Adventure, Comedy',
Director: 'Wolfgang Reitherman',
Writer: 'Larry Clemmons, Ralph Wright, Ken Anderson',
Actors: 'Phil Harris, Sebastian Cabot, Louis Prima',
Plot: "Abandoned after an accident, baby Mowgli is taken and raised by a family of wolves. As the boy grows older, the wise panther Bagheera realizes he must be returned to his own kind in the nearby man-village. Baloo the bear, however, thinks differently, taking the young Mowgli under his wing and teaching him that living in the jungle is the best life there is. Bagheera realizes that Mowgli is in danger, particularly from Shere Khan the tiger who hates all people. When Baloo finally comes around, Mowgli runs off into the jungle where he survives a second encounter with Kaa the snake and finally, with Shere Khan. It's the sight of a pretty girl, however, that draws Mowgli to the nearby man-village and stay there.",
Language: 'English',
Country: 'United States',
Awards: 'Nominated for 1 Oscar. 6 wins & 4 nominations total',
Poster: 'https://m.media-amazon.com/images/M/MV5BYmY1MTA3NmUtYzJmZC00YTFjLTk2NzktYTJhMWQ0ZTlkNzJjXkEyXkFqcGdeQXVyNjc5NjEzNA@@._V1_SX300.jpg',
Ratings: [
{ Source: 'Internet Movie Database', Value: '7.6/10' },
{ Source: 'Rotten Tomatoes', Value: '88%' },
{ Source: 'Metacritic', Value: '65/100' },
],
Metascore: '65',
imdbRating: '7.6',
imdbVotes: '195,021',
imdbID: 'tt0061852',
Type: 'movie',
DVD: '10 Aug 2016',
BoxOffice: '$141,843,612',
Production: 'N/A',
Website: 'N/A',
},
tt7394674: {
Title: 'Blood Quantum',
Year: '2019',
Rated: 'Not Rated',
Released: '28 Apr 2020',
Runtime: '98 min',
Genre: 'Drama, Horror',
Director: 'Jeff Barnaby',
Writer: 'Jeff Barnaby',
Actors: 'Michael Greyeyes, Elle-Máijá Tailfeathers, Forrest Goodluck',
Plot: 'The term "blood quantum" refers to a colonial blood measurement system that is used to determine an individual\'s Indigenous status, and is criticized as a tool of control and erasure of Indigenous peoples. The words take on even more provocative implications as the title of Jeff Barnaby\'s sophomore feature, which grimly depicts an apocalyptic scenario where in an isolated "Mi\'gmaq" community discover they are the only humans immune to a zombie plague. As the citizens of surrounding cities flee to the "Mi\'gmaq" reserve in search of refuge from the outbreak, the community must reckon with whether to let the outsiders in - and thus risk not just the extinction of their tribe but of humanity, period. The severe and scathing portrait of post-colonial Indigenous life and culture that Barnaby previously captured in the acclaimed Rhymes for Young Ghouls here deftly collides with the iconography and violent hyperbole typical of the zombie genre. The Undead are spectacularly and gruesomely dispatched via samurai swords, chainsaws, shotguns, and makeshift axes, while the living - a terrific ensemble cast led by Michael Greyeyes (Woman Walks Ahead and Fear the Walking Dead) - endure the paranoid pressures that such dire straits foment. In this iteration, however, Barnaby takes full advantage of the canvas zombie films regularly afford for cultural critique, exploring racism, colonialism, and the very real threat of extinction that Indigenous communities have experienced for generations. Further accentuated by arresting animated chapter breaks that instill a cool comic-book aesthetic to its horrific proceedings, Blood Quantum is as powerful an entry into the annals of zombie cinema as the devastating conclusion to George Romero\'s 1968 original Night of the Living Dead, and a meaningful demonstration of how marginalized voices - when given the opportunity - can resurrect a tired genre with incendiary new life.',
Language: 'English, Micmac',
Country: 'Canada',
Awards: '9 wins & 8 nominations',
Poster: 'https://m.media-amazon.com/images/M/MV5BZTc1ODE0ZDAtZWU4YS00OTFmLWJkYWItNmRkMzkzZmRlNTFlXkEyXkFqcGdeQXVyNTM0NTU5Mg@@._V1_SX300.jpg',
Ratings: [
{ Source: 'Internet Movie Database', Value: '5.6/10' },
{ Source: 'Rotten Tomatoes', Value: '90%' },
{ Source: 'Metacritic', Value: '63/100' },
],
Metascore: '63',
imdbRating: '5.6',
imdbVotes: '5,230',
imdbID: 'tt7394674',
Type: 'movie',
DVD: '28 Apr 2020',
BoxOffice: 'N/A',
Production: 'N/A',
Website: 'N/A',
},
};
const omdbApiClient: OmdbApiClient = {
fetchMetadata: (imdbId) => Promise.resolve(omdbResponses[imdbId]),
};
describe('createOmdbEnrichedDataService', () => { describe('createOmdbEnrichedDataService', () => {
const servicePromise = createOmdbEnrichedDataService( const servicePromise = createTestOmdbEnrichedDataService();
createInternalProvider(),
createOmdbProviderByApiClient(omdbApiClient),
);
it('returns correct data for 3532674', async () => { it('returns correct data for 3532674', async () => {
const service = await servicePromise; const service = await servicePromise;

@ -0,0 +1,171 @@
import { createInternalProvider } from '../integration/movies/internal';
import { createOmdbProviderByApiClient } from '../integration/movies/omdb';
import type {
OmdbApiClient,
RawOmdbData,
} from '../integration/movies/omdb/types';
import { createOmdbEnrichedDataService } from '../services/omdbEnrichedDataService';
const omdbResponses: Record<string, RawOmdbData> = {
tt0401792: {
Title: 'Sin City',
Year: '2005',
Rated: 'R',
Released: '01 Apr 2005',
Runtime: '124 min',
Genre: 'Crime, Thriller',
Director: 'Frank Miller, Quentin Tarantino, Robert Rodriguez',
Writer: 'Frank Miller, Robert Rodriguez',
Actors: 'Mickey Rourke, Clive Owen, Bruce Willis',
Plot: "Four tales of crime adapted from Frank Miller's popular comics, focusing around a muscular brute who's looking for the person responsible for the death of his beloved Goldie (Jaime King), a man fed up with Sin City's corrupt law enforcement who takes the law into his own hands after a horrible mistake, a cop who risks his life to protect a girl from a deformed pedophile and a hitman looking to make a little cash.",
Language: 'English',
Country: 'United States',
Awards: '38 wins & 54 nominations',
Poster: 'https://m.media-amazon.com/images/M/MV5BODZmYjMwNzEtNzVhNC00ZTRmLTk2M2UtNzE1MTQ2ZDAxNjc2XkEyXkFqcGdeQXVyMTQxNzMzNDI@._V1_SX300.jpg',
Ratings: [
{ Source: 'Internet Movie Database', Value: '8.0/10' },
{ Source: 'Rotten Tomatoes', Value: '76%' },
{ Source: 'Metacritic', Value: '74/100' },
],
Metascore: '74',
imdbRating: '8.0',
imdbVotes: '786,745',
imdbID: 'tt0401792',
Type: 'movie',
DVD: '03 Sep 2016',
BoxOffice: '$74,103,820',
Production: 'N/A',
Website: 'N/A',
},
tt0097576: {
Title: 'Indiana Jones and the Last Crusade',
Year: '1989',
Rated: 'PG-13',
Released: '24 May 1989',
Runtime: '127 min',
Genre: 'Action, Adventure',
Director: 'Steven Spielberg',
Writer: 'Jeffrey Boam, George Lucas, Menno Meyjes',
Actors: 'Harrison Ford, Sean Connery, Alison Doody',
Plot: 'An art collector appeals to Indiana Jones to embark on a search for the Holy Grail. He learns that another archaeologist has disappeared while searching for the precious goblet, and the missing man is his own father, Dr. Henry Jones. The artifact is much harder to find than they expected, and its powers are too much for those impure of heart.',
Language: 'English, German, Greek, Latin, Italian',
Country: 'United States',
Awards: 'Won 1 Oscar. 9 wins & 24 nominations total',
Poster: 'https://m.media-amazon.com/images/M/MV5BY2Q0ODg4ZmItNDZiYi00ZWY5LTg2NzctNmYwZjA5OThmNzE1XkEyXkFqcGdeQXVyMjM4MzQ4OTQ@._V1_SX300.jpg',
Ratings: [
{ Source: 'Internet Movie Database', Value: '8.2/10' },
{ Source: 'Rotten Tomatoes', Value: '84%' },
{ Source: 'Metacritic', Value: '65/100' },
],
Metascore: '65',
imdbRating: '8.2',
imdbVotes: '797,615',
imdbID: 'tt0097576',
Type: 'movie',
DVD: '28 Jan 2014',
BoxOffice: '$197,171,806',
Production: 'N/A',
Website: 'N/A',
},
tt0076759: {
Title: 'Star Wars: Episode IV - A New Hope',
Year: '1977',
Rated: 'PG',
Released: '25 May 1977',
Runtime: '121 min',
Genre: 'Action, Adventure, Fantasy',
Director: 'George Lucas',
Writer: 'George Lucas',
Actors: 'Mark Hamill, Harrison Ford, Carrie Fisher',
Plot: 'The Imperial Forces, under orders from cruel Darth Vader, hold Princess Leia hostage in their efforts to quell the rebellion against the Galactic Empire. Luke Skywalker and Han Solo, captain of the Millennium Falcon, work together with the companionable droid duo R2-D2 and C-3PO to rescue the beautiful princess, help the Rebel Alliance and restore freedom and justice to the Galaxy.',
Language: 'English',
Country: 'United States',
Awards: 'Won 6 Oscars. 65 wins & 31 nominations total',
Poster: 'https://m.media-amazon.com/images/M/MV5BOTA5NjhiOTAtZWM0ZC00MWNhLThiMzEtZDFkOTk2OTU1ZDJkXkEyXkFqcGdeQXVyMTA4NDI1NTQx._V1_SX300.jpg',
Ratings: [
{ Source: 'Internet Movie Database', Value: '8.6/10' },
{ Source: 'Rotten Tomatoes', Value: '93%' },
{ Source: 'Metacritic', Value: '90/100' },
],
Metascore: '90',
imdbRating: '8.6',
imdbVotes: '1,424,627',
imdbID: 'tt0076759',
Type: 'movie',
DVD: '10 Oct 2016',
BoxOffice: '$460,998,507',
Production: 'N/A',
Website: 'N/A',
},
tt0061852: {
Title: 'The Jungle Book',
Year: '1967',
Rated: 'G',
Released: '18 Oct 1967',
Runtime: '78 min',
Genre: 'Animation, Adventure, Comedy',
Director: 'Wolfgang Reitherman',
Writer: 'Larry Clemmons, Ralph Wright, Ken Anderson',
Actors: 'Phil Harris, Sebastian Cabot, Louis Prima',
Plot: "Abandoned after an accident, baby Mowgli is taken and raised by a family of wolves. As the boy grows older, the wise panther Bagheera realizes he must be returned to his own kind in the nearby man-village. Baloo the bear, however, thinks differently, taking the young Mowgli under his wing and teaching him that living in the jungle is the best life there is. Bagheera realizes that Mowgli is in danger, particularly from Shere Khan the tiger who hates all people. When Baloo finally comes around, Mowgli runs off into the jungle where he survives a second encounter with Kaa the snake and finally, with Shere Khan. It's the sight of a pretty girl, however, that draws Mowgli to the nearby man-village and stay there.",
Language: 'English',
Country: 'United States',
Awards: 'Nominated for 1 Oscar. 6 wins & 4 nominations total',
Poster: 'https://m.media-amazon.com/images/M/MV5BYmY1MTA3NmUtYzJmZC00YTFjLTk2NzktYTJhMWQ0ZTlkNzJjXkEyXkFqcGdeQXVyNjc5NjEzNA@@._V1_SX300.jpg',
Ratings: [
{ Source: 'Internet Movie Database', Value: '7.6/10' },
{ Source: 'Rotten Tomatoes', Value: '88%' },
{ Source: 'Metacritic', Value: '65/100' },
],
Metascore: '65',
imdbRating: '7.6',
imdbVotes: '195,021',
imdbID: 'tt0061852',
Type: 'movie',
DVD: '10 Aug 2016',
BoxOffice: '$141,843,612',
Production: 'N/A',
Website: 'N/A',
},
tt7394674: {
Title: 'Blood Quantum',
Year: '2019',
Rated: 'Not Rated',
Released: '28 Apr 2020',
Runtime: '98 min',
Genre: 'Drama, Horror',
Director: 'Jeff Barnaby',
Writer: 'Jeff Barnaby',
Actors: 'Michael Greyeyes, Elle-Máijá Tailfeathers, Forrest Goodluck',
Plot: 'The term "blood quantum" refers to a colonial blood measurement system that is used to determine an individual\'s Indigenous status, and is criticized as a tool of control and erasure of Indigenous peoples. The words take on even more provocative implications as the title of Jeff Barnaby\'s sophomore feature, which grimly depicts an apocalyptic scenario where in an isolated "Mi\'gmaq" community discover they are the only humans immune to a zombie plague. As the citizens of surrounding cities flee to the "Mi\'gmaq" reserve in search of refuge from the outbreak, the community must reckon with whether to let the outsiders in - and thus risk not just the extinction of their tribe but of humanity, period. The severe and scathing portrait of post-colonial Indigenous life and culture that Barnaby previously captured in the acclaimed Rhymes for Young Ghouls here deftly collides with the iconography and violent hyperbole typical of the zombie genre. The Undead are spectacularly and gruesomely dispatched via samurai swords, chainsaws, shotguns, and makeshift axes, while the living - a terrific ensemble cast led by Michael Greyeyes (Woman Walks Ahead and Fear the Walking Dead) - endure the paranoid pressures that such dire straits foment. In this iteration, however, Barnaby takes full advantage of the canvas zombie films regularly afford for cultural critique, exploring racism, colonialism, and the very real threat of extinction that Indigenous communities have experienced for generations. Further accentuated by arresting animated chapter breaks that instill a cool comic-book aesthetic to its horrific proceedings, Blood Quantum is as powerful an entry into the annals of zombie cinema as the devastating conclusion to George Romero\'s 1968 original Night of the Living Dead, and a meaningful demonstration of how marginalized voices - when given the opportunity - can resurrect a tired genre with incendiary new life.',
Language: 'English, Micmac',
Country: 'Canada',
Awards: '9 wins & 8 nominations',
Poster: 'https://m.media-amazon.com/images/M/MV5BZTc1ODE0ZDAtZWU4YS00OTFmLWJkYWItNmRkMzkzZmRlNTFlXkEyXkFqcGdeQXVyNTM0NTU5Mg@@._V1_SX300.jpg',
Ratings: [
{ Source: 'Internet Movie Database', Value: '5.6/10' },
{ Source: 'Rotten Tomatoes', Value: '90%' },
{ Source: 'Metacritic', Value: '63/100' },
],
Metascore: '63',
imdbRating: '5.6',
imdbVotes: '5,230',
imdbID: 'tt7394674',
Type: 'movie',
DVD: '28 Apr 2020',
BoxOffice: 'N/A',
Production: 'N/A',
Website: 'N/A',
},
};
const omdbApiClient: OmdbApiClient = {
fetchMetadata: (imdbId) => Promise.resolve(omdbResponses[imdbId]),
};
const omdbProvider = createOmdbProviderByApiClient(omdbApiClient);
const internalProvider = createInternalProvider();
export const createTestOmdbEnrichedDataService = () =>
createOmdbEnrichedDataService(internalProvider, omdbProvider);
Loading…
Cancel
Save