Created
April 3, 2014 17:47
-
-
Save gabhi/9959221 to your computer and use it in GitHub Desktop.
Sample test case to test POST method for express js REST API
This file contains 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
//Following test case assumes you have express js server running at port 5000 and has api /api/login | |
var should = require('should'); | |
var assert = require('assert'); | |
var request = require('supertest'); | |
var winston = require('winston'); | |
describe('Routing', function() { | |
var url = 'http://localhost:5000'; | |
before(function(done) { | |
// In our tests we use the test db | |
done(); | |
}); | |
describe('REST Api', function() { | |
it('should return valid AuthId', function(done) { | |
var params = { | |
username: 'test', | |
password: 'password', | |
}; | |
request(url) | |
.post('/api/login') | |
.send(params) | |
// end handles the response | |
.end(function(err, res) { | |
if (err) { | |
throw err; | |
} | |
res.should.have.status(200); | |
res.body.should.have.property('AuthId'); | |
done(); | |
}); | |
}); | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment