-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #89 from steniowagner/feat/movies-images
Feat/movies images
- Loading branch information
Showing
12 changed files
with
711 additions
and
2 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 2 additions & 0 deletions
2
src/graphql/datasources/the-movie-db-api/handlers/movies/images/index.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
export { handler } from "./movie-images.handler"; | ||
export * as types from "./movie-images.types"; |
92 changes: 92 additions & 0 deletions
92
src/graphql/datasources/the-movie-db-api/handlers/movies/images/movie-images.handler.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
import TheMovieDBAPI from "@tmdb-api/tmdb-movie-db-api"; | ||
import { Iso6391Language } from "@generated-types"; | ||
import { CONSTANTS as TMDBAPI_CONSTANS } from "@tmdb-api/utils"; | ||
|
||
import * as fixtures from "../../../../../../../__test__/datasources/tmdb-api/fixtures"; | ||
|
||
import { handler } from "./movie-images.handler"; | ||
|
||
const ID = 1; | ||
|
||
const mockGet = jest.fn(); | ||
|
||
jest.mock("@apollo/datasource-rest", () => { | ||
class MockRESTDataSource { | ||
baseUrl = ""; | ||
get = mockGet; | ||
} | ||
return { | ||
RESTDataSource: MockRESTDataSource, | ||
}; | ||
}); | ||
|
||
describe("DataSources/TheMovieDBApi/Movie-Images-Query-Handler", () => { | ||
beforeEach(() => { | ||
jest.clearAllMocks(); | ||
}); | ||
|
||
describe('When the "language" is defined', () => { | ||
it('should call "RESTDatasource.get" correctly', async () => { | ||
const tmdbAPI = new TheMovieDBAPI(); | ||
const language = Iso6391Language.Pt; | ||
await handler( | ||
{ | ||
language, | ||
id: ID, | ||
}, | ||
tmdbAPI, | ||
); | ||
expect(mockGet.mock.calls[0][0]).toEqual(`movie/${ID}/images`); | ||
expect(mockGet.mock.calls[0][1].params).toEqual({ | ||
language, | ||
}); | ||
expect(typeof mockGet.mock.calls[0][1].headers.Authorization).toEqual("string"); | ||
}); | ||
}); | ||
|
||
describe('When the "language" is not defined', () => { | ||
it('should call "RESTDatasource.get" correctly', async () => { | ||
const tmdbAPI = new TheMovieDBAPI(); | ||
await handler( | ||
{ | ||
id: ID, | ||
}, | ||
tmdbAPI, | ||
); | ||
expect(mockGet.mock.calls[0][0]).toEqual(`movie/${ID}/images`); | ||
expect(mockGet.mock.calls[0][1].params).toEqual({ | ||
language: TMDBAPI_CONSTANS.FALLBACK_LANGUAGE, | ||
}); | ||
expect(typeof mockGet.mock.calls[0][1].headers.Authorization).toEqual("string"); | ||
}); | ||
}); | ||
|
||
describe('When the response received is "undefined"', () => { | ||
it("should return the data correctly", async () => { | ||
mockGet.mockReturnValueOnce(undefined); | ||
const tmdbAPI = new TheMovieDBAPI(); | ||
const result = await handler( | ||
{ | ||
id: ID, | ||
}, | ||
tmdbAPI, | ||
); | ||
expect(result).toEqual([]); | ||
}); | ||
}); | ||
|
||
describe("When receive the data", () => { | ||
it("should return the data correctly", async () => { | ||
mockGet.mockReturnValueOnce(fixtures.movieImages); | ||
const tmdbAPI = new TheMovieDBAPI(); | ||
const result = await handler( | ||
{ | ||
id: ID, | ||
}, | ||
tmdbAPI, | ||
); | ||
const images = fixtures.movieImages.backdrops.map((backdrop) => backdrop.file_path); | ||
expect(result).toEqual(images); | ||
}); | ||
}); | ||
}); |
17 changes: 17 additions & 0 deletions
17
src/graphql/datasources/the-movie-db-api/handlers/movies/images/movie-images.handler.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import { CONSTANTS as TMDB_CONSTANS } from "@tmdb-api/utils"; | ||
import TheMovieDBAPI from "@tmdb-api/tmdb-movie-db-api"; | ||
import { TvShowImagesArgs } from "@generated-types"; | ||
|
||
import { Response } from "./movie-images.types"; | ||
|
||
export const handler = async (params: TvShowImagesArgs, tmdbAPI: TheMovieDBAPI) => { | ||
const response = await tmdbAPI.handle<Response>(`movie/${params.id}/images`, { | ||
language: params.language ?? TMDB_CONSTANS.FALLBACK_LANGUAGE, | ||
}); | ||
if (!response) { | ||
return []; | ||
} | ||
return response.backdrops | ||
.filter((backdrop) => !!backdrop.file_path) | ||
.map((backdrop) => backdrop.file_path); | ||
}; |
11 changes: 11 additions & 0 deletions
11
src/graphql/datasources/the-movie-db-api/handlers/movies/images/movie-images.types.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
export type Response = { | ||
backdrops: { | ||
aspect_ratio: number; | ||
height: number; | ||
iso_639_1: string; | ||
file_path: string; | ||
vote_average: number; | ||
vote_count: number; | ||
width: number; | ||
}[]; | ||
}; |
3 changes: 2 additions & 1 deletion
3
src/graphql/datasources/the-movie-db-api/handlers/movies/index.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
import * as details from "./details"; | ||
import * as videos from "./videos"; | ||
import * as images from "./images"; | ||
|
||
export { details, videos }; | ||
export { details, videos, images }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters