From e73fcc1e7304ab2ad7de08f9ced335ec1fba7135 Mon Sep 17 00:00:00 2001 From: Inga <52715130+inga-lovinde@users.noreply.github.com> Date: Sun, 10 Dec 2023 01:54:05 +0000 Subject: [PATCH] reorganization --- src/integration/movies/internal.ts | 16 -------- .../storage.spec.ts} | 22 +++++++--- src/integration/movies/internal/storage.ts | 16 ++++++++ src/integration/movies/internal/types.ts | 41 +++++++++++++++++++ src/integration/movies/omdb/apiClient.spec.ts | 4 +- src/integration/movies/omdb/index.spec.ts | 2 +- 6 files changed, 76 insertions(+), 25 deletions(-) delete mode 100644 src/integration/movies/internal.ts rename src/integration/movies/{internal.spec.ts => internal/storage.spec.ts} (68%) create mode 100644 src/integration/movies/internal/storage.ts create mode 100644 src/integration/movies/internal/types.ts diff --git a/src/integration/movies/internal.ts b/src/integration/movies/internal.ts deleted file mode 100644 index 73e300c..0000000 --- a/src/integration/movies/internal.ts +++ /dev/null @@ -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)), - }; -}; diff --git a/src/integration/movies/internal.spec.ts b/src/integration/movies/internal/storage.spec.ts similarity index 68% rename from src/integration/movies/internal.spec.ts rename to src/integration/movies/internal/storage.spec.ts index ecc9f2a..e22dbe1 100644 --- a/src/integration/movies/internal.spec.ts +++ b/src/integration/movies/internal/storage.spec.ts @@ -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(); + }); }); diff --git a/src/integration/movies/internal/storage.ts b/src/integration/movies/internal/storage.ts new file mode 100644 index 0000000..a538be9 --- /dev/null +++ b/src/integration/movies/internal/storage.ts @@ -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)), + }; +}; diff --git a/src/integration/movies/internal/types.ts b/src/integration/movies/internal/types.ts new file mode 100644 index 0000000..c49db64 --- /dev/null +++ b/src/integration/movies/internal/types.ts @@ -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; + getMetadataByImdbId(imdbId: string): Promise; +}; diff --git a/src/integration/movies/omdb/apiClient.spec.ts b/src/integration/movies/omdb/apiClient.spec.ts index 2bc7af6..aa01e26 100644 --- a/src/integration/movies/omdb/apiClient.spec.ts +++ b/src/integration/movies/omdb/apiClient.spec.ts @@ -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); diff --git a/src/integration/movies/omdb/index.spec.ts b/src/integration/movies/omdb/index.spec.ts index 3d0c2eb..e481fde 100644 --- a/src/integration/movies/omdb/index.spec.ts +++ b/src/integration/movies/omdb/index.spec.ts @@ -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);