Merge pull request 'refs #6397 emailValidation' (!1941) from 6397-emailValidation into dev
gitea/salix/pipeline/head This commit looks good Details

Reviewed-on: #1941
Reviewed-by: Alex Moreno <alexm@verdnatura.es>
This commit is contained in:
Carlos Satorres 2024-02-01 17:45:53 +00:00
commit e59ab6fd97
3 changed files with 30 additions and 3 deletions

View File

@ -336,5 +336,6 @@
"Incorrect pin": "Pin incorrecto",
"You already have the mailAlias": "Ya tienes este alias de correo",
"The alias cant be modified": "Este alias de correo no puede ser modificado",
"No tickets to invoice": "No hay tickets para facturar"
"No tickets to invoice": "No hay tickets para facturar",
"An email is necessary": "Es necesario un email"
}

View File

@ -1,3 +1,5 @@
const UserError = require('vn-loopback/util/user-error');
module.exports = function(Self) {
Self.remoteMethod('createWithUser', {
description: 'Creates both client and its web account',
@ -29,7 +31,11 @@ module.exports = function(Self) {
myOptions.transaction = tx;
}
const firstEmail = data.email ? data.email.split(',')[0] : null;
if (!data.email)
throw new UserError('An email is necessary');
const firstEmail = data.email.split(',')[0];
const user = {
name: data.userName,
email: firstEmail,

View File

@ -13,6 +13,8 @@ describe('Client Create', () => {
businessTypeFk: 'florist',
provinceFk: 1
};
const newAccountWithoutEmail = JSON.parse(JSON.stringify(newAccount));
delete newAccountWithoutEmail.email;
beforeAll(async() => {
const activeCtx = {
@ -48,6 +50,24 @@ describe('Client Create', () => {
}
});
it('should not create a new account', async() => {
const tx = await models.Client.beginTransaction({});
let error;
try {
const options = {transaction: tx};
await models.Client.createWithUser(newAccountWithoutEmail, options);
await tx.rollback();
} catch (e) {
error = e.message;
await tx.rollback();
}
expect(error).toEqual(`An email is necessary`);
});
it('should create a new account', async() => {
const tx = await models.Client.beginTransaction({});