implemented basic local integration

main
Inga 🏳‍🌈 11 months ago
parent 449d95109e
commit b8f3cac3fc
  1. 53
      src/integration/movies/local.spec.ts
  2. 13
      src/integration/movies/local.ts
  3. 6
      src/integration/movies/omdb.ts
  4. 0
      src/resources/movies/11043689.json
  5. 0
      src/resources/movies/11528860.json
  6. 0
      src/resources/movies/3532674.json
  7. 0
      src/resources/movies/5979300.json
  8. 1
      tsconfig.json

@ -0,0 +1,53 @@
import { describe, it, expect } from '@jest/globals';
import { createLocalMoviesClient } from './local';
describe('createLocalMoviesClient', () => {
const client = createLocalMoviesClient();
it('returns data for internal movie id', async () => {
const result = await client.getMovieMetadataByInternalId(11528860);
expect(result).toMatchObject({
description: expect.any(String),
duration: 75,
id: 11528860,
imdbId: 'tt0061852',
languages: expect.any(Array),
originalLanguage: 'en',
productionYear: 1967,
studios: ['Disney'],
title: 'Das Dschungelbuch',
userrating: {
countStar1: expect.any(Number),
countStar2: expect.any(Number),
countStar3: expect.any(Number),
countStar4: expect.any(Number),
countStar5: expect.any(Number),
countTotal: expect.any(Number),
},
});
});
it('returns data for imdb id', async () => {
const result = await client.getMovieMetadataByImdbId('tt0061852');
expect(result).toMatchObject({
description: expect.any(String),
duration: 75,
id: 11528860,
imdbId: 'tt0061852',
languages: expect.any(Array),
originalLanguage: 'en',
productionYear: 1967,
studios: ['Disney'],
title: 'Das Dschungelbuch',
userrating: {
countStar1: expect.any(Number),
countStar2: expect.any(Number),
countStar3: expect.any(Number),
countStar4: expect.any(Number),
countStar5: expect.any(Number),
countTotal: expect.any(Number),
},
});
});
});

@ -0,0 +1,13 @@
import movie1 from '../../resources/movies/3532674.json';
import movie2 from '../../resources/movies/5979300.json';
import movie3 from '../../resources/movies/11043689.json';
import movie4 from '../../resources/movies/11528860.json';
const movies = [movie1, movie2, movie3, movie4];
export const createLocalMoviesClient = () => {
return {
getMovieMetadataByInternalId: async (internalId: number) => movies.find(({ id }) => id == internalId),
getMovieMetadataByImdbId: async (id: string) => movies.find(({ imdbId }) => imdbId == id),
};
};

@ -2,7 +2,7 @@ import fetch from 'node-fetch';
import PQueue from 'p-queue'; import PQueue from 'p-queue';
export const createOmdbClient = (apiKey: string) => { export const createOmdbClient = (apiKey: string) => {
// Rate limit (according to readme, it's 10k per day; // Rate limit (according to readme, it's 1k per day;
// here we set it 1 per second, should be enough for the demo app goal) // here we set it 1 per second, should be enough for the demo app goal)
const queue = new PQueue({ const queue = new PQueue({
interval: 1000, interval: 1000,
@ -12,10 +12,10 @@ export const createOmdbClient = (apiKey: string) => {
}); });
return { return {
getMovieMetadata: async (movieId: string) => getMovieMetadata: async (imdbId: string) =>
queue.add(async () => { queue.add(async () => {
const url = new URL('https://www.omdbapi.com/'); const url = new URL('https://www.omdbapi.com/');
url.searchParams.append('i', movieId); url.searchParams.append('i', imdbId);
url.searchParams.append('apikey', apiKey); url.searchParams.append('apikey', apiKey);
url.searchParams.append('plot', 'full'); url.searchParams.append('plot', 'full');
const response = await fetch(url); const response = await fetch(url);

@ -7,6 +7,7 @@
"emitDecoratorMetadata": true, "emitDecoratorMetadata": true,
"experimentalDecorators": true, "experimentalDecorators": true,
"allowSyntheticDefaultImports": true, "allowSyntheticDefaultImports": true,
"resolveJsonModule": true,
"target": "ES2021", "target": "ES2021",
"sourceMap": true, "sourceMap": true,
"outDir": "./dist", "outDir": "./dist",

Loading…
Cancel
Save