routes backend unit test completed
This commit is contained in:
parent
7c36daf496
commit
d700d3a905
|
@ -1,7 +1,22 @@
|
|||
import app from '../../../server/server';
|
||||
import routes from '../routes';
|
||||
import restoreFixtures from '../../../../../services/db/testing_fixtures';
|
||||
|
||||
describe('Auth routes', () => {
|
||||
let fixturesToApply = {tables: ['`salix`.`user`'], inserts: [
|
||||
`INSERT INTO salix.user(id,username,password,email)
|
||||
VALUES
|
||||
(10, 'JessicaJones', 'ac754a330530832ba1bf7687f577da91', 'JessicaJones@verdnatura.es');`
|
||||
]};
|
||||
|
||||
beforeEach(done => {
|
||||
restoreFixtures(fixturesToApply, done);
|
||||
});
|
||||
|
||||
afterAll(done => {
|
||||
restoreFixtures(fixturesToApply, done);
|
||||
});
|
||||
|
||||
let User = app.models.User;
|
||||
let loginFunction;
|
||||
let logoutFunction;
|
||||
|
@ -29,6 +44,20 @@ describe('Auth routes', () => {
|
|||
loginFunction(req, res);
|
||||
});
|
||||
|
||||
describe('when the user doesnt exist but the client does and the password is correct', () => {
|
||||
it('should create the user login and return the token', done => {
|
||||
spyOn(User, 'upsertWithWhere').and.callThrough();
|
||||
req.body.user = 'PetterParker';
|
||||
req.body.password = 'nightmare';
|
||||
res.json = response => {
|
||||
expect(User.upsertWithWhere).toHaveBeenCalledWith(jasmine.any(Object), jasmine.any(Object), jasmine.any(Function));
|
||||
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';
|
||||
|
|
Loading…
Reference in New Issue