backend unit test for routes login
This commit is contained in:
parent
0e88c2c4e7
commit
ba6a1f0f16
|
@ -51,7 +51,7 @@ module.exports = function(app) {
|
||||||
continueUrl = null;
|
continueUrl = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
loginUrl = applications[apiKey];
|
let loginUrl = applications[apiKey];
|
||||||
|
|
||||||
res.json({
|
res.json({
|
||||||
token: token.id,
|
token: token.id,
|
||||||
|
|
|
@ -0,0 +1,55 @@
|
||||||
|
import app from '../../../server/server';
|
||||||
|
import routes from '../routes';
|
||||||
|
|
||||||
|
describe('Auth routes', () => {
|
||||||
|
let loginFunction;
|
||||||
|
let res;
|
||||||
|
let req;
|
||||||
|
|
||||||
|
beforeEach(() => {
|
||||||
|
spyOn(app, 'post');
|
||||||
|
routes(app);
|
||||||
|
loginFunction = app.post.calls.mostRecent().args[1];
|
||||||
|
res = {};
|
||||||
|
req = {body: {}};
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('when the user exists and the password is correct', () => {
|
||||||
|
it('should login and return the token', done => {
|
||||||
|
req.body.user = 'JessicaJones';
|
||||||
|
req.body.password = 'nightmare';
|
||||||
|
res.json = response => {
|
||||||
|
expect(response.token).toBeDefined();
|
||||||
|
done();
|
||||||
|
};
|
||||||
|
loginFunction(req, res);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should define the url to continue upon login', done => {
|
||||||
|
req.body.user = 'JessicaJones';
|
||||||
|
req.body.password = 'nightmare';
|
||||||
|
req.body.location = 'http://localhost:5000/auth/?apiKey=salix&continue="continueURL"';
|
||||||
|
res.json = response => {
|
||||||
|
expect(response.continue).toBeDefined();
|
||||||
|
done();
|
||||||
|
};
|
||||||
|
loginFunction(req, res);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('when the user is incorrect', () => {
|
||||||
|
it('should return a 401 unauthorized', done => {
|
||||||
|
req.body.user = 'IDontExists';
|
||||||
|
req.body.password = 'TotallyWrongPassword';
|
||||||
|
res.status = status => {
|
||||||
|
expect(status).toBe(401);
|
||||||
|
};
|
||||||
|
|
||||||
|
res.json = response => {
|
||||||
|
expect(response.message).toBe('Login failed');
|
||||||
|
done();
|
||||||
|
};
|
||||||
|
loginFunction(req, res);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
|
@ -21,6 +21,7 @@ var SpecReporter = require('jasmine-spec-reporter').SpecReporter;
|
||||||
jasmine.loadConfig({
|
jasmine.loadConfig({
|
||||||
spec_dir: 'services',
|
spec_dir: 'services',
|
||||||
spec_files: [
|
spec_files: [
|
||||||
|
'auth/server/**/*[sS]pec.js',
|
||||||
'client/common/**/*[sS]pec.js'
|
'client/common/**/*[sS]pec.js'
|
||||||
],
|
],
|
||||||
helpers: [
|
helpers: [
|
||||||
|
|
Loading…
Reference in New Issue