refs #6434 feat: new test user signIn with email
gitea/salix/pipeline/head This commit looks good
Details
gitea/salix/pipeline/head This commit looks good
Details
This commit is contained in:
parent
579cd832c0
commit
386b556216
|
@ -14,6 +14,16 @@ describe('VnUser Sign-in()', () => {
|
||||||
};
|
};
|
||||||
const {VnUser, AccessToken} = models;
|
const {VnUser, AccessToken} = models;
|
||||||
describe('when credentials are correct', () => {
|
describe('when credentials are correct', () => {
|
||||||
|
it('should return the token if user uses email', async() => {
|
||||||
|
let login = await VnUser.signIn(unauthCtx, 'salesAssistant@mydomain.com', 'nightmare');
|
||||||
|
let accessToken = await AccessToken.findById(login.token);
|
||||||
|
let ctx = {req: {accessToken: accessToken}};
|
||||||
|
|
||||||
|
expect(login.token).toBeDefined();
|
||||||
|
|
||||||
|
await VnUser.logout(ctx.req.accessToken.id);
|
||||||
|
});
|
||||||
|
|
||||||
it('should return the token', async() => {
|
it('should return the token', async() => {
|
||||||
let login = await VnUser.signIn(unauthCtx, 'salesAssistant', 'nightmare');
|
let login = await VnUser.signIn(unauthCtx, 'salesAssistant', 'nightmare');
|
||||||
let accessToken = await AccessToken.findById(login.token);
|
let accessToken = await AccessToken.findById(login.token);
|
||||||
|
|
|
@ -124,17 +124,20 @@ module.exports = function(Self) {
|
||||||
|
|
||||||
return email.send();
|
return email.send();
|
||||||
});
|
});
|
||||||
|
Self.signInValidate = (user, userToken) => {
|
||||||
|
const [[key, value]] = Object.entries(Self.userUses(user));
|
||||||
|
if (userToken[key].toLowerCase() !== value.toLowerCase()) {
|
||||||
|
console.error('ERROR!!! - Signin with other user', _userToken, _user);
|
||||||
|
throw new UserError('Try again');
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
Self.validateLogin = async function(user, password) {
|
Self.validateLogin = async function(user, password) {
|
||||||
const loginInfo = Object.assign({password}, Self.userUses(user));
|
const loginInfo = Object.assign({password}, Self.userUses(user));
|
||||||
const token = await Self.login(loginInfo, 'user');
|
const token = await Self.login(loginInfo, 'user');
|
||||||
|
|
||||||
const userToken = await token.user.get();
|
const userToken = await token.user.get();
|
||||||
|
Self.signInValidate(user, userToken);
|
||||||
// if (userToken.username.toLowerCase() !== user.toLowerCase()) {
|
|
||||||
// console.error('ERROR!!! - Signin with other user', userToken, user);
|
|
||||||
// throw new UserError('Try again');
|
|
||||||
// }
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
await Self.app.models.Account.sync(userToken.name, password);
|
await Self.app.models.Account.sync(userToken.name, password);
|
||||||
|
|
Loading…
Reference in New Issue