From 087e91e898895a0187fb5b5da8f0683d5646b4a2 Mon Sep 17 00:00:00 2001 From: joan Date: Tue, 11 Apr 2023 08:15:46 +0200 Subject: [PATCH] Updated unit tests --- back/methods/account/login.js | 2 +- back/methods/account/specs/login.spec.js | 7 ++++--- back/methods/account/specs/logout.spec.js | 3 ++- 3 files changed, 7 insertions(+), 5 deletions(-) diff --git a/back/methods/account/login.js b/back/methods/account/login.js index 47d4d629a..2f6a04893 100644 --- a/back/methods/account/login.js +++ b/back/methods/account/login.js @@ -64,7 +64,7 @@ module.exports = Self => { } } - if (account.twoFactor === 'email') { + if (account && account.twoFactor === 'email') { const authAccess = await $.UserAccess.findOne({ where: { userFk: account.id, diff --git a/back/methods/account/specs/login.spec.js b/back/methods/account/specs/login.spec.js index 59eea2612..a51f6b91e 100644 --- a/back/methods/account/specs/login.spec.js +++ b/back/methods/account/specs/login.spec.js @@ -1,9 +1,10 @@ const app = require('vn-loopback/server/server'); describe('account login()', () => { + const unauthCtx = {}; describe('when credentials are correct', () => { it('should return the token', async() => { - let login = await app.models.Account.login('salesAssistant', 'nightmare'); + let login = await app.models.Account.login(unauthCtx, 'salesAssistant', 'nightmare'); let accessToken = await app.models.AccessToken.findById(login.token); let ctx = {req: {accessToken: accessToken}}; @@ -13,7 +14,7 @@ describe('account login()', () => { }); it('should return the token if the user doesnt exist but the client does', async() => { - let login = await app.models.Account.login('PetterParker', 'nightmare'); + let login = await app.models.Account.login(unauthCtx, 'PetterParker', 'nightmare'); let accessToken = await app.models.AccessToken.findById(login.token); let ctx = {req: {accessToken: accessToken}}; @@ -28,7 +29,7 @@ describe('account login()', () => { let error; try { - await app.models.Account.login('IDontExist', 'TotallyWrongPassword'); + await app.models.Account.login(unauthCtx, 'IDontExist', 'TotallyWrongPassword'); } catch (e) { error = e; } diff --git a/back/methods/account/specs/logout.spec.js b/back/methods/account/specs/logout.spec.js index b3d69d6ef..5acbf90df 100644 --- a/back/methods/account/specs/logout.spec.js +++ b/back/methods/account/specs/logout.spec.js @@ -2,7 +2,8 @@ const app = require('vn-loopback/server/server'); describe('account logout()', () => { it('should logout and remove token after valid login', async() => { - let loginResponse = await app.models.Account.login('buyer', 'nightmare'); + const unauthCtx = {}; + let loginResponse = await app.models.Account.login(unauthCtx, 'buyer', 'nightmare'); let accessToken = await app.models.AccessToken.findById(loginResponse.token); let ctx = {req: {accessToken: accessToken}};