Skip to content

Commit

Permalink
Add new tests for bad episode num and error handling
Browse files Browse the repository at this point in the history
  • Loading branch information
worr committed Jun 24, 2018
1 parent cdf249c commit ee3a079
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 5 deletions.
6 changes: 1 addition & 5 deletions src/imdb.ts
Original file line number Diff line number Diff line change
Expand Up @@ -485,11 +485,7 @@ export function get(req: MovieRequest, opts: MovieOpts): Promise<Movie> {
* @return a promise yielding search results
*/
export function search(req: SearchRequest, opts: MovieOpts, page?: number): Promise<SearchResults> {
try {
return new Client(opts).search(req, page);
} catch (e) {
return Promise.reject(e);
}
return new Client(opts).search(req, page);
}

/**
Expand Down
30 changes: 30 additions & 0 deletions test/test-getReq.ts
Original file line number Diff line number Diff line change
Expand Up @@ -222,4 +222,34 @@ describe('get', () => {
done();
});
});

it("gets an error from omdb by name", (done: MochaDone) => {
let scope = nock("https://www.omdbapi.com").get("/?apikey=foo&plot=full&r=json&t=blah").reply(200, {Error: "bad", Response: "False"});

imdb.get({
name: "blah"
}, {
apiKey: "foo"
}).then((data) => {
assert.notExists(data, "unreachable");
}).catch((err) => {
assert.isOk(err, "got an error");
done();
});
});

it("gets an error from omdb by id", (done: MochaDone) => {
let scope = nock("https://www.omdbapi.com").get("/?apikey=foo&plot=full&r=json&i=tt01").reply(200, {Error: "bad", Response: "False"});

imdb.get({
id: "tt01"
}, {
apiKey: "foo"
}).then((data) => {
assert.notExists(data, "unreachable");
}).catch((err) => {
assert.isOk(err, "got an error");
done();
});
});
});
5 changes: 5 additions & 0 deletions test/test-movie.ts
Original file line number Diff line number Diff line change
Expand Up @@ -159,4 +159,9 @@ describe("Episode", () => {
const ep = Object.assign(Object.create(orig_tv), {Year: "foo"});
assert.throws(() => new imdb.Episode(ep, 30), TypeError);
});

it("creates an episode with an invalid number", () => {
const ep = Object.assign(Object.create(orig_tv), {Episode: "foo"});
assert.throws(() => new imdb.Episode(ep, 30), TypeError);
});
});

0 comments on commit ee3a079

Please sign in to comment.