Updated unit tests
This commit is contained in:
parent
b9e48f2102
commit
087e91e898
|
@ -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,
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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}};
|
||||
|
||||
|
|
Loading…
Reference in New Issue