Skip to content

Commit

Permalink
feat: add the missing planet api (#37)
Browse files Browse the repository at this point in the history
fixes #36
  • Loading branch information
lholmquist committed Mar 4, 2019
1 parent 790965e commit 72fe6de
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 0 deletions.
4 changes: 4 additions & 0 deletions lib/swapi-node.js
Original file line number Diff line number Diff line change
Expand Up @@ -114,5 +114,9 @@ module.exports = {
getSpecies (options) {
var opts = parseOptions(options);
return makeRequest('species' + (opts.id ? '/' + opts.id : '/'));
},
getPlanets (options) {
var opts = parseOptions(options);
return makeRequest('planets' + (opts.id ? '/' + opts.id : '/'));
}
};
41 changes: 41 additions & 0 deletions test/swapi-api-tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -224,3 +224,44 @@ test('GET species - with error', (t) => {
t.end();
});
});

test('GET planets', (t) => {
nock('https://swapi.co/api/')
.matchHeader('User-Agent', 'swapi-node')
.matchHeader('SWAPI-Node-Version', version)
.get('/planets/1')
.reply(200, {});

const request = swapi.getPlanets(1).then((result) => {
t.pass('success return');
t.end();
});

t.equal(request instanceof Promise, true, 'should return a Promise');
});

test('GET planets - with options', (t) => {
nock('https://swapi.co/api/')
.matchHeader('User-Agent', 'swapi-node')
.matchHeader('SWAPI-Node-Version', version)
.get('/planets/1')
.reply(200, {});

const request = swapi.getPlanets({id: 1}).then((result) => {
t.pass('success return');
t.end();
});
});

test('GET planets - with error', (t) => {
nock('https://swapi.co/api/')
.matchHeader('User-Agent', 'swapi-node')
.matchHeader('SWAPI-Node-Version', version)
.get('/planets/1')
.reply(400, {});

const request = swapi.getPlanets({id: 1}).then(null, (result) => {
t.pass('error return');
t.end();
});
});

0 comments on commit 72fe6de

Please sign in to comment.