Skip to content

Commit

Permalink
Merge pull request #4 from shemaeric/feature/Implement-movie-quote
Browse files Browse the repository at this point in the history
Add Movie Quote
  • Loading branch information
shemaeric authored Apr 18, 2023
2 parents 7af60f1 + 0fc7644 commit 0741d74
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 2 deletions.
8 changes: 8 additions & 0 deletions src/Models/Movie.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,12 @@ export declare type Movie = {
academyAwardNominations: number;
academyAwardWins: number;
rottenTomatoesScore: number;
}

export declare type MovieQuote = {
_id: string;
dialog: string;
movie: string;
character: string;
id: string;
}
8 changes: 7 additions & 1 deletion src/services/movie.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Movie } from '../Models/Movie';
import { Movie, MovieQuote } from '../Models/Movie';
import { Base } from '../client/base';
import { resources } from '../utils';

Expand All @@ -15,4 +15,10 @@ export class MovieService extends Base {

return await this.invoke(movieUrl);
}

public async getMovieQuote(id: string): Promise<MovieQuote> {
const url = `${resources.movie}/${id}/quote`;

return await this.invoke(url);
}
}
31 changes: 30 additions & 1 deletion src/tests/services/movie.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { MovieService } from "../../services";
import { Movie } from "../../Models";
import { Movie, MovieQuote } from "../../Models";

// Mock fetch function
function mockFetch(returnValue: unknown) {
Expand Down Expand Up @@ -66,4 +66,33 @@ describe("MovieService", () => {
// Call getSingleMovie method and expect it to throw an error
await expect(movieService.getSingleMovie(movieId)).rejects.toThrowError("Not Found");
});

test("getMovieQuote should fetch a movie quote successfully", async () => {
// Mock fetch response
const movieId = "123";
const movieQuote = { dialog: "One ring to rule them all." } as unknown as MovieQuote;
mockFetch({
ok: true,
json: () => Promise.resolve(movieQuote),
});

// Call getMovieQuote method
const actual = await movieService.getMovieQuote(movieId);

// Assert response
expect(actual).toEqual(movieQuote);

});

test("getMovieQuote should throw an error when fetch response is not ok", async () => {
// Mock fetch response
const movieId = "123";
mockFetch({
ok: false,
statusText: "Not Found",
});

// Call getMovieQuote method and expect it to throw an error
await expect(movieService.getMovieQuote(movieId)).rejects.toThrowError("Not Found");
});
});

0 comments on commit 0741d74

Please sign in to comment.