Merge branch 'dev' of https://git.verdnatura.es/salix into dev

This commit is contained in:
Juan Ferrer Toribio 2018-01-30 08:59:12 +01:00
commit 9d92b9def7
4 changed files with 86 additions and 4 deletions

View File

@ -51,7 +51,7 @@ module.exports = function(app) {
continueUrl = null;
}
loginUrl = applications[apiKey];
let loginUrl = applications[apiKey];
res.json({
token: token.id,
@ -85,7 +85,8 @@ module.exports = function(app) {
});
app.get('/logout', function(req, res) {
User.logout(req.accessToken.id,
() => res.redirect('/'));
User.logout(req.accessToken.id, () => {
res.redirect('/');
});
});
};

View File

@ -0,0 +1,81 @@
import app from '../../../server/server';
import routes from '../routes';
describe('Auth routes', () => {
let User = app.models.User;
let loginFunction;
let logoutFunction;
let res;
let req;
beforeEach(() => {
spyOn(app, 'post');
spyOn(app, 'get').and.callThrough();
routes(app);
loginFunction = app.post.calls.mostRecent().args[1];
logoutFunction = app.get.calls.argsFor(2)[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);
});
it('should define the loginUrl upon login', done => {
req.body.user = 'JessicaJones';
req.body.password = 'nightmare';
req.body.location = 'http://localhost:5000/auth/?apiKey=salix';
res.json = response => {
expect(response.loginUrl).toBeDefined();
done();
};
loginFunction(req, res);
});
it('should logout after login', done => {
spyOn(User, 'logout').and.callThrough();
req.accessToken = {id: 'testingTokenId'};
logoutFunction(req, res);
res.redirect = url => {
expect(User.logout).toHaveBeenCalledWith('testingTokenId', jasmine.any(Function));
expect(url).toBe('/');
done();
};
});
});
describe('when the user is incorrect', () => {
it('should return a 401 unauthorized', done => {
req.body.user = 'IDontExist';
req.body.password = 'TotallyWrongPassword';
res.status = status => {
expect(status).toBe(401);
};
res.json = response => {
expect(response.message).toBe('Login failed');
done();
};
loginFunction(req, res);
});
});
});

View File

@ -389,7 +389,6 @@ INSERT INTO `vn`.`client`(`id`,`name`,`fi`,`socialName`,`contact`,`street`,`city
(9, 'Bruce Banner', '16104829E', 'Hulk', 'Black widow', 'Somewhere in New York', 'Silla', 46460, 1111111111, 222222222, 333333333, 1, 'BruceBanner@verdnatura.es', NULL, 0, 1234567890, 0, 1, 1, 300, 1, 1,NULL, 10, 5,CURDATE(), 1, 5, 1, 1, 1,'0000-00-00', 1, NULL, 1, 1, 1, 1, NULL, 0, 0, 4, 0, 1),
(10, 'Jessica Jones', '58282869H', 'Jessica Jones', 'Luke Cage', 'NYCC 2015 Poster', 'Silla', 46460, 1111111111, 222222222, 333333333, 1, 'JessicaJones@verdnatura.es', NULL, 0, 1234567890, 0, 1, 1, 300, 1, 1,NULL, 10, 5,CURDATE(), 1, 5, 1, 1, 1,'0000-00-00', 1, NULL, 1, 1, 1, 1, NULL, 0, 0, 4, 0, 1);
INSERT INTO `salix`.`Address`(`id`, `consignee`, `street`, `city`, `postcode`, `provinceFk`, `phone`, `mobile`, `isEnabled`, `isDefaultAddress`, `clientFk`, `defaultAgencyFk`, `longitude`, `latitude`, `isEqualizated`)
VALUES
(1, 'Bruce Wayne', 'The Bat cave', 'Silla', 46460, 1, NULL, NULL, 1, 1, 1, 2, NULL, NULL, 0),

View File

@ -21,6 +21,7 @@ var SpecReporter = require('jasmine-spec-reporter').SpecReporter;
jasmine.loadConfig({
spec_dir: 'services',
spec_files: [
'auth/server/**/*[sS]pec.js',
'client/common/**/*[sS]pec.js'
],
helpers: [