This commit is contained in:
parent
31d637c8a7
commit
89c25c07b6
|
@ -1,6 +1,6 @@
|
||||||
const {models} = require('vn-loopback/server/server');
|
const {models} = require('vn-loopback/server/server');
|
||||||
|
|
||||||
fdescribe('VnUser Sign-in()', () => {
|
describe('VnUser Sign-in()', () => {
|
||||||
const employeeId = 1;
|
const employeeId = 1;
|
||||||
const unauthCtx = {
|
const unauthCtx = {
|
||||||
req: {
|
req: {
|
||||||
|
@ -76,24 +76,26 @@ fdescribe('VnUser Sign-in()', () => {
|
||||||
|
|
||||||
describe('when passExpired', () => {
|
describe('when passExpired', () => {
|
||||||
it('should throw a passExpired error', async() => {
|
it('should throw a passExpired error', async() => {
|
||||||
let error;
|
const tx = await VnUser.beginTransaction({});
|
||||||
const employee = await VnUser.findById(employeeId);
|
const employee = await VnUser.findById(employeeId);
|
||||||
const yesterday = Date.vnNew();
|
const yesterday = Date.vnNew();
|
||||||
yesterday.setDate(yesterday.getDate() - 1);
|
yesterday.setDate(yesterday.getDate() - 1);
|
||||||
|
|
||||||
|
let error;
|
||||||
try {
|
try {
|
||||||
await employee.updateAttribute('passExpired', yesterday);
|
const options = {transaction: tx};
|
||||||
|
await employee.updateAttribute('passExpired', yesterday, options);
|
||||||
|
|
||||||
await VnUser.signin(unauthCtx, 'employee', 'nightmare');
|
await VnUser.signin(unauthCtx, 'employee', 'nightmare', options);
|
||||||
|
await tx.rollback();
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
|
await tx.rollback();
|
||||||
error = e;
|
error = e;
|
||||||
}
|
}
|
||||||
|
|
||||||
expect(error).toBeDefined();
|
expect(error).toBeDefined();
|
||||||
expect(error.statusCode).toBe(400);
|
expect(error.statusCode).toBe(400);
|
||||||
expect(error.message).toBe('Pass expired');
|
expect(error.message).toBe('Pass expired');
|
||||||
|
|
||||||
await employee.updateAttribute('passExpired', null);
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
|
@ -28,7 +28,7 @@ export async function getBrowser() {
|
||||||
args,
|
args,
|
||||||
defaultViewport: null,
|
defaultViewport: null,
|
||||||
headless: headless,
|
headless: headless,
|
||||||
slowMo: 1, // slow down by ms
|
slowMo: 20, // slow down by ms
|
||||||
// ignoreDefaultArgs: ['--disable-extensions'],
|
// ignoreDefaultArgs: ['--disable-extensions'],
|
||||||
// executablePath: '/usr/bin/google-chrome-stable',
|
// executablePath: '/usr/bin/google-chrome-stable',
|
||||||
// executablePath: '/usr/bin/firefox-developer-edition',
|
// executablePath: '/usr/bin/firefox-developer-edition',
|
||||||
|
|
|
@ -16,6 +16,7 @@ describe('ChangePassword path', async() => {
|
||||||
await browser.close();
|
await browser.close();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
const badPassword = 'badpass';
|
||||||
const oldPassword = 'nightmare';
|
const oldPassword = 'nightmare';
|
||||||
const newPassword = 'newPass.1234';
|
const newPassword = 'newPass.1234';
|
||||||
describe('Bad login', async() => {
|
describe('Bad login', async() => {
|
||||||
|
@ -37,13 +38,22 @@ describe('ChangePassword path', async() => {
|
||||||
expect(message.text).toContain('Invalid current password');
|
expect(message.text).toContain('Invalid current password');
|
||||||
|
|
||||||
// Bad attempt: password not meet requirements
|
// Bad attempt: password not meet requirements
|
||||||
|
message = await page.sendForm($.form, {
|
||||||
|
oldPassword: oldPassword,
|
||||||
|
newPassword: badPassword,
|
||||||
|
repeatPassword: badPassword
|
||||||
|
});
|
||||||
|
|
||||||
|
expect(message.text).toContain('Password does not meet requirements');
|
||||||
|
|
||||||
|
// Bad attempt: same password
|
||||||
message = await page.sendForm($.form, {
|
message = await page.sendForm($.form, {
|
||||||
oldPassword: oldPassword,
|
oldPassword: oldPassword,
|
||||||
newPassword: oldPassword,
|
newPassword: oldPassword,
|
||||||
repeatPassword: oldPassword
|
repeatPassword: oldPassword
|
||||||
});
|
});
|
||||||
|
|
||||||
expect(message.text).toContain('Password does not meet requirements');
|
expect(message.text).toContain('You can not use the same password');
|
||||||
|
|
||||||
// Correct attempt: change password
|
// Correct attempt: change password
|
||||||
message = await page.sendForm($.form, {
|
message = await page.sendForm($.form, {
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
import selectors from '../../helpers/selectors.js';
|
import selectors from '../../helpers/selectors.js';
|
||||||
import getBrowser from '../../helpers/puppeteer';
|
import getBrowser from '../../helpers/puppeteer';
|
||||||
|
|
||||||
describe('Account Alias create and basic data path', () => {
|
fdescribe('Account Alias create and basic data path', () => {
|
||||||
let browser;
|
let browser;
|
||||||
let page;
|
let page;
|
||||||
|
|
||||||
|
|
|
@ -15,10 +15,6 @@ export default class Controller {
|
||||||
}
|
}
|
||||||
|
|
||||||
$onInit() {
|
$onInit() {
|
||||||
this.oldPassword = 'nightmare';
|
|
||||||
this.repeatPassword = 'test.1234';
|
|
||||||
this.newPassword = 'test.1234';
|
|
||||||
this.verificationCode = '1234';
|
|
||||||
if (!this.$state.params.id)
|
if (!this.$state.params.id)
|
||||||
this.$state.go('login');
|
this.$state.go('login');
|
||||||
|
|
||||||
|
|
|
@ -21,7 +21,7 @@ module.exports = Self => {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
Self.setPassword = async function(id, newPassword) {
|
Self.setPassword = async function(id, newPassword, options) {
|
||||||
await Self.app.models.VnUser.setPassword(id, newPassword);
|
await Self.app.models.VnUser.setPassword(id, newPassword, options);
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
|
@ -8,8 +8,18 @@ describe('Account setPassword()', () => {
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should update password when it passes requirements', async() => {
|
it('should update password when it passes requirements', async() => {
|
||||||
let req = models.Account.setPassword(1, 'Very$ecurePa22.');
|
const tx = await models.Account.beginTransaction({});
|
||||||
|
|
||||||
await expectAsync(req).toBeResolved();
|
let error;
|
||||||
|
try {
|
||||||
|
const options = {transaction: tx};
|
||||||
|
await models.Account.setPassword(1, 'Very$ecurePa22.', options);
|
||||||
|
await tx.rollback();
|
||||||
|
} catch (e) {
|
||||||
|
await tx.rollback();
|
||||||
|
error = e;
|
||||||
|
}
|
||||||
|
|
||||||
|
expect(error).not.toBeDefined();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in New Issue