Created
May 22, 2019 21:21
-
-
Save luisenriquecorona/e3c38515557af25a8be71bd51513816a to your computer and use it in GitHub Desktop.
Angular And NodeJS
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'use strict'; | |
var request = require('request'); | |
var dbSession = require('../../src/backend/dbSession.js'); | |
var resetDatabase = require('../resetDatabase.js'); | |
var async = require('async'); | |
describe('The API', function () { | |
it('should respond to a GET request at /api/keywords/', function (done) { | |
var expected = { | |
"_items": [ | |
{'id': 1, 'value': 'Aubergine', 'categoryID': 1}, | |
{'id': 2, 'value': 'Onion', 'categoryID': 1}, | |
{'id': 3, 'value': 'Knife', 'categoryID': 2} | |
] | |
}; | |
async.series( | |
[ | |
function(callback) { resetDatabase(dbSession, callback); | |
}, | |
function(callback) { dbSession.insert( | |
'keyword', | |
{'value': 'Aubergine', 'categoryID': 1}, function(err) { callback(err) }); | |
}, | |
function(callback) { dbSession.insert( | |
'keyword', | |
{'value': 'Onion', 'categoryID': 1}, function(err) { callback(err) }); | |
}, | |
function(callback) { dbSession.insert( | |
'keyword', | |
{'value': 'Knife', 'categoryID': 2}, | |
function(err) { callback(err) }); } | |
], | |
function(err, results) { request.get( | |
{ | |
'url': 'http://localhost:8080/api/keywords/', 'json': true | |
}, | |
function (err, res, body) { | |
expect(res.statusCode).toBe(200); | |
expect(body).toEqual(expected); | |
done(); | |
} | |
); | |
} | |
); | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment