From d700d3a905a23f6084554744c53b3d9b9e8ef9ce Mon Sep 17 00:00:00 2001 From: Carlos Jimenez <=> Date: Tue, 30 Jan 2018 15:49:22 +0100 Subject: [PATCH] routes backend unit test completed --- .../auth/server/boot/specs/routes.spec.js | 29 +++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/services/auth/server/boot/specs/routes.spec.js b/services/auth/server/boot/specs/routes.spec.js index 7dd5a49d44..2ea72a1e92 100644 --- a/services/auth/server/boot/specs/routes.spec.js +++ b/services/auth/server/boot/specs/routes.spec.js @@ -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';