Updated back unit tests
gitea/salix/pipeline/head There was a failure building this commit
Details
gitea/salix/pipeline/head There was a failure building this commit
Details
This commit is contained in:
parent
3456438485
commit
f0b44a2992
|
@ -1,25 +1,25 @@
|
||||||
const {models} = require('vn-loopback/server/server');
|
const {models} = require('vn-loopback/server/server');
|
||||||
|
|
||||||
describe('account login()', () => {
|
describe('VnUser signIn()', () => {
|
||||||
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 models.VnUser.login('salesAssistant', 'nightmare');
|
let login = await models.VnUser.signIn('salesAssistant', 'nightmare');
|
||||||
let accessToken = await models.AccessToken.findById(login.token);
|
let accessToken = await models.AccessToken.findById(login.token);
|
||||||
let ctx = {req: {accessToken: accessToken}};
|
let ctx = {req: {accessToken: accessToken}};
|
||||||
|
|
||||||
expect(login.token).toBeDefined();
|
expect(login.token).toBeDefined();
|
||||||
|
|
||||||
await models.VnUser.logout(ctx);
|
await models.VnUser.signOut(ctx);
|
||||||
});
|
});
|
||||||
|
|
||||||
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 models.VnUser.login('PetterParker', 'nightmare');
|
let login = await models.VnUser.signIn('PetterParker', 'nightmare');
|
||||||
let accessToken = await models.AccessToken.findById(login.token);
|
let accessToken = await models.AccessToken.findById(login.token);
|
||||||
let ctx = {req: {accessToken: accessToken}};
|
let ctx = {req: {accessToken: accessToken}};
|
||||||
|
|
||||||
expect(login.token).toBeDefined();
|
expect(login.token).toBeDefined();
|
||||||
|
|
||||||
await models.VnUser.logout(ctx);
|
await models.VnUser.signOut(ctx);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -28,7 +28,7 @@ describe('account login()', () => {
|
||||||
let error;
|
let error;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
await models.VnUser.login('IDontExist', 'TotallyWrongPassword');
|
await models.VnUser.signIn('IDontExist', 'TotallyWrongPassword');
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
error = e;
|
error = e;
|
||||||
}
|
}
|
|
@ -1,12 +1,12 @@
|
||||||
const {models} = require('vn-loopback/server/server');
|
const {models} = require('vn-loopback/server/server');
|
||||||
|
|
||||||
describe('account logout()', () => {
|
describe('VnUser signOut()', () => {
|
||||||
it('should logout and remove token after valid login', async() => {
|
it('should logout and remove token after valid login', async() => {
|
||||||
let loginResponse = await models.VnUser.login('buyer', 'nightmare');
|
let loginResponse = await models.VnUser.signOut('buyer', 'nightmare');
|
||||||
let accessToken = await models.AccessToken.findById(loginResponse.token);
|
let accessToken = await models.AccessToken.findById(loginResponse.token);
|
||||||
let ctx = {req: {accessToken: accessToken}};
|
let ctx = {req: {accessToken: accessToken}};
|
||||||
|
|
||||||
let logoutResponse = await models.VnUser.logout(ctx);
|
let logoutResponse = await models.VnUser.signOut(ctx);
|
||||||
let tokenAfterLogout = await models.AccessToken.findById(loginResponse.token);
|
let tokenAfterLogout = await models.AccessToken.findById(loginResponse.token);
|
||||||
|
|
||||||
expect(logoutResponse).toBeTrue();
|
expect(logoutResponse).toBeTrue();
|
||||||
|
@ -18,7 +18,7 @@ describe('account logout()', () => {
|
||||||
let ctx = {req: {accessToken: {id: 'invalidToken'}}};
|
let ctx = {req: {accessToken: {id: 'invalidToken'}}};
|
||||||
|
|
||||||
try {
|
try {
|
||||||
response = await models.VnUser.logout(ctx);
|
response = await models.VnUser.signOut(ctx);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
error = e;
|
error = e;
|
||||||
}
|
}
|
||||||
|
@ -32,7 +32,7 @@ describe('account logout()', () => {
|
||||||
let ctx = {req: {accessToken: null}};
|
let ctx = {req: {accessToken: null}};
|
||||||
|
|
||||||
try {
|
try {
|
||||||
response = await models.VnUser.logout(ctx);
|
response = await models.VnUser.signOut(ctx);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
error = e;
|
error = e;
|
||||||
}
|
}
|
|
@ -7,6 +7,7 @@ module.exports = function(Self) {
|
||||||
require('../methods/vn-user/signOut')(Self);
|
require('../methods/vn-user/signOut')(Self);
|
||||||
require('../methods/vn-user/acl')(Self);
|
require('../methods/vn-user/acl')(Self);
|
||||||
require('../methods/vn-user/change-password')(Self);
|
require('../methods/vn-user/change-password')(Self);
|
||||||
|
require('../methods/vn-user/recover-password')(Self);
|
||||||
require('../methods/vn-user/set-password')(Self);
|
require('../methods/vn-user/set-password')(Self);
|
||||||
require('../methods/vn-user/validate-token')(Self);
|
require('../methods/vn-user/validate-token')(Self);
|
||||||
require('../methods/vn-user/privileges')(Self);
|
require('../methods/vn-user/privileges')(Self);
|
||||||
|
|
|
@ -9,6 +9,7 @@
|
||||||
},
|
},
|
||||||
"excludeBaseProperties": [
|
"excludeBaseProperties": [
|
||||||
"username",
|
"username",
|
||||||
|
"password",
|
||||||
"login"
|
"login"
|
||||||
],
|
],
|
||||||
"properties": {
|
"properties": {
|
||||||
|
|
|
@ -233,7 +233,7 @@ module.exports = Self => {
|
||||||
const code = error.code;
|
const code = error.code;
|
||||||
const message = error.sqlMessage;
|
const message = error.sqlMessage;
|
||||||
|
|
||||||
if (code === 'ER_DUP_ENTRY' && message.includes(`for key 'mail'`))
|
if (error.message && error.message.includes(`Email already exists`))
|
||||||
throw new UserError(`This personal mail already exists`);
|
throw new UserError(`This personal mail already exists`);
|
||||||
|
|
||||||
if (code === 'ER_DUP_ENTRY' && message.includes(`CodigoTrabajador_UNIQUE`))
|
if (code === 'ER_DUP_ENTRY' && message.includes(`CodigoTrabajador_UNIQUE`))
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
{
|
{
|
||||||
"name": "salix-back",
|
"name": "salix-back",
|
||||||
"version": "230401",
|
"version": "23.04.01",
|
||||||
"author": "Verdnatura Levante SL",
|
"author": "Verdnatura Levante SL",
|
||||||
"description": "Salix backend",
|
"description": "Salix backend",
|
||||||
"license": "GPL-3.0",
|
"license": "GPL-3.0",
|
||||||
|
|
Loading…
Reference in New Issue