diff --git a/lib/swapi-node.js b/lib/swapi-node.js index cb425f6..59b0058 100644 --- a/lib/swapi-node.js +++ b/lib/swapi-node.js @@ -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 : '/')); } }; diff --git a/test/swapi-api-tests.js b/test/swapi-api-tests.js index e43dc34..194c638 100644 --- a/test/swapi-api-tests.js +++ b/test/swapi-api-tests.js @@ -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(); + }); +});