reorganization

main
Inga 🏳‍🌈 12 months ago
parent 560f75b7c9
commit e73fcc1e73
  1. 16
      src/integration/movies/internal.ts
  2. 22
      src/integration/movies/internal/storage.spec.ts
  3. 16
      src/integration/movies/internal/storage.ts
  4. 41
      src/integration/movies/internal/types.ts
  5. 4
      src/integration/movies/omdb/apiClient.spec.ts
  6. 2
      src/integration/movies/omdb/index.spec.ts

@ -1,16 +0,0 @@
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';
import { InternalMoviesProvider } from './types';
const movies = [movie1, movie2, movie3, movie4];
export const createInternalMoviesClient = (): InternalMoviesProvider => {
return {
getMovieMetadataByInternalId: async (internalId: number) =>
Promise.resolve(movies.find(({ id }) => id == internalId)),
getMovieMetadataByImdbId: async (id: string) =>
Promise.resolve(movies.find(({ imdbId }) => imdbId == id)),
};
};

@ -1,12 +1,12 @@
import { describe, it, expect } from '@jest/globals';
import { createInternalMoviesClient } from './internal';
import { createStorageClient } from './storage';
describe('createInternalMoviesClient', () => {
const client = createInternalMoviesClient();
describe('createStorageClient', () => {
const client = createStorageClient();
it('returns data for internal movie id', async () => {
const result = await client.getMovieMetadataByInternalId(11528860);
it('returns data for internal id', async () => {
const result = await client.getMetadataByInternalId(11528860);
expect(result).toMatchObject({
description: expect.any(String),
duration: 75,
@ -28,8 +28,13 @@ describe('createInternalMoviesClient', () => {
});
});
it('returns undefined for non-existent internal id', async () => {
const result = await client.getMetadataByInternalId(999999);
expect(result).toBeUndefined();
});
it('returns data for imdb id', async () => {
const result = await client.getMovieMetadataByImdbId('tt0061852');
const result = await client.getMetadataByImdbId('tt0061852');
expect(result).toMatchObject({
description: expect.any(String),
duration: 75,
@ -50,4 +55,9 @@ describe('createInternalMoviesClient', () => {
},
});
});
it('returns undefined for non-existent imdb id', async () => {
const result = await client.getMetadataByImdbId('tt99999999999');
expect(result).toBeUndefined();
});
});

@ -0,0 +1,16 @@
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';
import { StorageClient } from './types';
const movies = [movie1, movie2, movie3, movie4];
export const createStorageClient = (): StorageClient => {
return {
getMetadataByInternalId: async (internalId: number) =>
Promise.resolve(movies.find(({ id }) => id == internalId)),
getMetadataByImdbId: async (id: string) =>
Promise.resolve(movies.find(({ imdbId }) => imdbId == id)),
};
};

@ -0,0 +1,41 @@
type StoredData = {
/**
* Description in local language
*/
description: string;
/**
* A whole number of minutes, presumably
*/
duration: number;
id: number;
imdbId: string;
/**
* Two-letter codes
*/
languages: string[];
/**
* Two-letter code
*/
originalLanguage: string;
productionYear: number;
studios: string[];
/**
* Title in local language
*/
title: string;
userrating: {
countStar1: number;
countStar2: number;
countStar3: number;
countStar4: number;
countStar5: number;
countTotal: number;
};
};
export type StorageClient = {
getMetadataByInternalId(
internalId: number,
): Promise<StoredData | undefined>;
getMetadataByImdbId(imdbId: string): Promise<StoredData | undefined>;
};

@ -4,7 +4,7 @@ import { createOmdbApiClient } from './apiClient';
describe('createOmdbApiClient', () => {
const client = createOmdbApiClient('68fd98ab');
it('returns some data for the sample movie id', async () => {
it('returns some data for tt11873472', async () => {
const result = await client.fetchMetadata('tt11873472');
expect(result).toMatchObject({
Actors: 'Cheryl Isheja, Elvis Ngabo, Diogène Ntarindwa',
@ -34,7 +34,7 @@ describe('createOmdbApiClient', () => {
});
}, 10_000);
it('returns undefined for non-existend movie id', async () => {
it('returns undefined for non-existent id', async () => {
const result = await client.fetchMetadata('tt99999999999');
expect(result).toBeUndefined();
}, 10_000);

@ -32,7 +32,7 @@ describe('createOmdbProvider', () => {
});
}, 10_000);
it('returns undefined for non-existend movie id', async () => {
it('returns undefined for non-existent id', async () => {
const result = await client.getMetadata('tt99999999999');
expect(result).toBeUndefined();
}, 10_000);

Loading…
Cancel
Save