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({
|
const authAccess = await $.UserAccess.findOne({
|
||||||
where: {
|
where: {
|
||||||
userFk: account.id,
|
userFk: account.id,
|
||||||
|
|
|
@ -1,9 +1,10 @@
|
||||||
const app = require('vn-loopback/server/server');
|
const app = require('vn-loopback/server/server');
|
||||||
|
|
||||||
describe('account login()', () => {
|
describe('account login()', () => {
|
||||||
|
const unauthCtx = {};
|
||||||
describe('when credentials are correct', () => {
|
describe('when credentials are correct', () => {
|
||||||
it('should return the token', async() => {
|
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 accessToken = await app.models.AccessToken.findById(login.token);
|
||||||
let ctx = {req: {accessToken: accessToken}};
|
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() => {
|
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 accessToken = await app.models.AccessToken.findById(login.token);
|
||||||
let ctx = {req: {accessToken: accessToken}};
|
let ctx = {req: {accessToken: accessToken}};
|
||||||
|
|
||||||
|
@ -28,7 +29,7 @@ describe('account login()', () => {
|
||||||
let error;
|
let error;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
await app.models.Account.login('IDontExist', 'TotallyWrongPassword');
|
await app.models.Account.login(unauthCtx, 'IDontExist', 'TotallyWrongPassword');
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
error = e;
|
error = e;
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,7 +2,8 @@ const app = require('vn-loopback/server/server');
|
||||||
|
|
||||||
describe('account logout()', () => {
|
describe('account logout()', () => {
|
||||||
it('should logout and remove token after valid login', async() => {
|
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 accessToken = await app.models.AccessToken.findById(loginResponse.token);
|
||||||
let ctx = {req: {accessToken: accessToken}};
|
let ctx = {req: {accessToken: accessToken}};
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue