Skip to content
This repository has been archived by the owner on Nov 20, 2019. It is now read-only.

Commit

Permalink
Added tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
cn0047 committed Jun 23, 2017
1 parent d4689d2 commit dd18267
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 11 deletions.
6 changes: 4 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,15 @@ which helps fetch data from different REST API endpoints into one request.
````js
const getthemall = require('getthemall');

app.use('/resources', (req, res) => {
getthemall(req, res, (data) => {
app.use('/resources', function(req, res) {
getthemall(req, res, function (data) {
res.json(data);
});
});
````

You can find example of usage [here](github.com/cn007b/simplerestapi).

## Tests

`npm test`
3 changes: 1 addition & 2 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,9 @@ const fetchData = function(resourceName, url, cb) {
* Performs fetch data from different endpoints simultaneously.
*
* @param {object} req Request object.
* @param {object} res Response object.
* @param {function} cb Callback function, which will receive array with all obtained data.
*/
module.exports = function(req, res, cb) {
module.exports = function(req, cb) {

var host = req.protocol + '://' + req.get('host') + '/';
var promises = [];
Expand Down
5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "getthemall",
"version": "1.1.1",
"version": "1.2.1",
"description": "Simple demo package.",
"main": "index.js",
"scripts": {
Expand All @@ -24,7 +24,8 @@
"chai": "^4.0.2",
"coveralls": "^2.13.1",
"istanbul": "^0.4.5",
"mocha": "^3.4.2"
"mocha": "^3.4.2",
"nock": "^9.0.13"
},
"dependencies": {
"node-fetch": "^1.7.1"
Expand Down
32 changes: 27 additions & 5 deletions test/test.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,34 @@
'use strict';
var nock = require('nock');
const chai = require('chai');
const expect = chai.expect;

let expect = require('chai').expect;
let getthemall = require('../index');
const getthemall = require('../index');

describe('#getthemall', function() {

it('Fake', function() {
expect(true).to.equal(true);
it('Main test', function(done) {
// Mock `fetch` function.
nock('https://fake.host.com')
.get('/users/1')
.reply(200, '{"id": 1, "name": "James Bond"}')
;
// Stub express request.
var req = {
protocol: 'https',
get: function (key) {
return 'fake.host.com';
},
query: {
usersList: 'users/1'
}
};
// Perform action.
getthemall(req, function (data) {
var actualResult = JSON.stringify(data);
var expectedResult = '{"usersList":{"id":1,"name":"James Bond"}}';
expect(actualResult).to.equal(expectedResult);
done();
});
});

});

0 comments on commit dd18267

Please sign in to comment.