refs #6397 emailValidation #1941
|
@ -336,5 +336,6 @@
|
||||||
"Incorrect pin": "Pin incorrecto",
|
"Incorrect pin": "Pin incorrecto",
|
||||||
"You already have the mailAlias": "Ya tienes este alias de correo",
|
"You already have the mailAlias": "Ya tienes este alias de correo",
|
||||||
"The alias cant be modified": "Este alias de correo no puede ser modificado",
|
"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"
|
||||||
carlossa marked this conversation as resolved
Outdated
|
|||||||
}
|
}
|
||||||
|
|
|
@ -1,3 +1,5 @@
|
||||||
|
const UserError = require('vn-loopback/util/user-error');
|
||||||
|
|
||||||
module.exports = function(Self) {
|
module.exports = function(Self) {
|
||||||
Self.remoteMethod('createWithUser', {
|
Self.remoteMethod('createWithUser', {
|
||||||
description: 'Creates both client and its web account',
|
description: 'Creates both client and its web account',
|
||||||
|
@ -29,7 +31,11 @@ module.exports = function(Self) {
|
||||||
myOptions.transaction = tx;
|
myOptions.transaction = tx;
|
||||||
}
|
}
|
||||||
|
|
||||||
const firstEmail = data.email ? data.email.split(',')[0] : null;
|
if (!data.email)
|
||||||
jgallego
commented
@alexm valorares la opcio de posar-ho en back/models/vn-user.js com a una validacio nativa? @alexm valorares la opcio de posar-ho en back/models/vn-user.js com a una validacio nativa?
alexm
commented
Per mi si, pero hi hauria que mirar els nulls que hi hajen com se comporta la restriccio, pq segurament qualsevol canvi en el model fallara Per mi si, pero hi hauria que mirar els nulls que hi hajen com se comporta la restriccio, pq segurament qualsevol canvi en el model fallara
|
|||||||
|
throw new UserError('An email is necessary');
|
||||||
carlossa marked this conversation as resolved
Outdated
alexm
commented
Esto se puede refactorizar y dejar sin if else Esto se puede refactorizar y dejar sin if else
|
|||||||
|
|
||||||
carlossa marked this conversation as resolved
Outdated
alexm
commented
Aqui como este codigo siempre va a tener data.email se puede quitar el hacer ? : (if else) Aqui como este codigo siempre va a tener data.email se puede quitar el hacer ? : (if else)
|
|||||||
|
const firstEmail = data.email.split(',')[0];
|
||||||
|
|
||||||
const user = {
|
const user = {
|
||||||
name: data.userName,
|
name: data.userName,
|
||||||
email: firstEmail,
|
email: firstEmail,
|
||||||
|
|
|
@ -13,6 +13,8 @@ describe('Client Create', () => {
|
||||||
businessTypeFk: 'florist',
|
businessTypeFk: 'florist',
|
||||||
provinceFk: 1
|
provinceFk: 1
|
||||||
};
|
};
|
||||||
|
const newAccountWithoutEmail = JSON.parse(JSON.stringify(newAccount));
|
||||||
carlossa marked this conversation as resolved
Outdated
alexm
commented
Si vas a gasstar dos vegades lo mateix pero canviant un parametre. Si vas a gasstar dos vegades lo mateix pero canviant un parametre.
Pots fer clonarte el objecte i modficar soles lo que vols
Teu vaig dir en persona
|
|||||||
|
delete newAccountWithoutEmail.email;
|
||||||
|
|
||||||
beforeAll(async() => {
|
beforeAll(async() => {
|
||||||
const activeCtx = {
|
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();
|
||||||
carlossa marked this conversation as resolved
alexm
commented
La estructura no esta correcta, deuria ser:
La estructura no esta correcta, deuria ser:
```
try{
await funcioQueVolsProbar()
await tx.rollback();
} catch (e) {
await tx.rollback();
error = e;
}
expect(error.message).toEqual('Error que esperes');
```
|
|||||||
|
}
|
||||||
|
|
||||||
|
expect(error).toEqual(`An email is necessary`);
|
||||||
|
});
|
||||||
|
|
||||||
it('should create a new account', async() => {
|
it('should create a new account', async() => {
|
||||||
const tx = await models.Client.beginTransaction({});
|
const tx = await models.Client.beginTransaction({});
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Falta traducir
Falta traducir