refs #5878 test: add new 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
626c000ebb
commit
8b3565d885
|
@ -6,7 +6,8 @@ const validatorBodyModel = (model, body) => {
|
|||
Object.entries(body).forEach(([key, value]) => {
|
||||
if (!isValid) return;
|
||||
const bodyArg = model.find(m => m.arg === key);
|
||||
if (!bodyArg) throw new Error('Property is not defined in this model');
|
||||
if (!bodyArg) return;
|
||||
// throw new Error(`Property ${key} is not defined in this model`);
|
||||
const {type} = bodyArg;
|
||||
tag = key;
|
||||
if (tag !== 'any') {
|
||||
|
|
|
@ -0,0 +1,284 @@
|
|||
const validatorBodyModel = require('../body_model_validator');
|
||||
|
||||
describe('Validation Client Create', () => {
|
||||
const newAccount = {
|
||||
userName: 'Deadpool',
|
||||
email: 'Deadpool@marvel.com',
|
||||
fi: '16195279J',
|
||||
name: 'Wade',
|
||||
socialName: 'DEADPOOL MARVEL',
|
||||
street: 'WALL STREET',
|
||||
city: 'New York',
|
||||
businessTypeFk: 'florist',
|
||||
provinceFk: 1
|
||||
};
|
||||
const CLIENT_MODEL = [
|
||||
{
|
||||
arg: 'socialName',
|
||||
type: 'string'
|
||||
},
|
||||
{
|
||||
arg: 'fi',
|
||||
type: 'string'
|
||||
},
|
||||
{
|
||||
arg: 'street',
|
||||
type: 'string'
|
||||
},
|
||||
{
|
||||
arg: 'postcode',
|
||||
type: 'string'
|
||||
},
|
||||
{
|
||||
arg: 'city',
|
||||
type: 'string'
|
||||
},
|
||||
{
|
||||
arg: 'countryFk',
|
||||
type: 'number'
|
||||
},
|
||||
{
|
||||
arg: 'provinceFk',
|
||||
type: 'number'
|
||||
},
|
||||
{
|
||||
arg: 'sageTaxTypeFk',
|
||||
type: 'any'
|
||||
},
|
||||
{
|
||||
arg: 'sageTransactionTypeFk',
|
||||
type: 'any'
|
||||
},
|
||||
{
|
||||
arg: 'transferorFk',
|
||||
type: 'any'
|
||||
},
|
||||
{
|
||||
arg: 'hasToInvoiceByAddress',
|
||||
type: 'boolean'
|
||||
},
|
||||
{
|
||||
arg: 'hasToInvoice',
|
||||
type: 'boolean'
|
||||
},
|
||||
{
|
||||
arg: 'isActive',
|
||||
type: 'boolean'
|
||||
},
|
||||
{
|
||||
arg: 'isFreezed',
|
||||
type: 'boolean'
|
||||
},
|
||||
{
|
||||
arg: 'isVies',
|
||||
type: 'boolean'
|
||||
},
|
||||
{
|
||||
arg: 'isToBeMailed',
|
||||
type: 'boolean'
|
||||
},
|
||||
{
|
||||
arg: 'isEqualizated',
|
||||
type: 'boolean'
|
||||
},
|
||||
{
|
||||
arg: 'isTaxDataVerified',
|
||||
type: 'boolean'
|
||||
},
|
||||
{
|
||||
arg: 'isTaxDataChecked',
|
||||
type: 'boolean'
|
||||
},
|
||||
{
|
||||
arg: 'despiteOfClient',
|
||||
type: 'number'
|
||||
},
|
||||
{
|
||||
arg: 'hasIncoterms',
|
||||
type: 'boolean'
|
||||
},
|
||||
{
|
||||
arg: 'hasElectronicInvoice',
|
||||
type: 'boolean'
|
||||
}
|
||||
];
|
||||
it(`should not find Deadpool as he's not created yet`, async() => {
|
||||
let isValid = false;
|
||||
|
||||
isValid = validatorBodyModel(CLIENT_MODEL, newAccount).isValid;
|
||||
|
||||
expect(isValid).toBeTrue();
|
||||
});
|
||||
|
||||
it('should create a new account', async() => {
|
||||
let isValid = false;
|
||||
|
||||
isValid = validatorBodyModel(CLIENT_MODEL, newAccount).isValid;
|
||||
|
||||
expect(isValid).toBeTrue();
|
||||
});
|
||||
|
||||
it('should not be able to create a user if exists', async() => {
|
||||
let isValid = false;
|
||||
let error;
|
||||
|
||||
isValid = validatorBodyModel(CLIENT_MODEL, newAccount).isValid;
|
||||
|
||||
expect(isValid).toBeTrue();
|
||||
});
|
||||
});
|
||||
fdescribe('Validation Worker Create', () => {
|
||||
const defaultWorker = {
|
||||
// fi: '78457139E',
|
||||
// name: 'DEFAULTERWORKER',
|
||||
// firstName: 'DEFAULT',
|
||||
// lastNames: 'WORKER',
|
||||
// email: 'defaultWorker@mydomain.com',
|
||||
// street: 'S/ DEFAULTWORKERSTREET',
|
||||
// city: 'defaultWorkerCity',
|
||||
// provinceFk: 1,
|
||||
// countryFk: 1,
|
||||
// companyFk: 442,
|
||||
// postcode: '46680',
|
||||
// phone: '123456789',
|
||||
// code: 'DWW',
|
||||
// bossFk: 9,
|
||||
// birth: '2022-12-11T23:00:00.000Z',
|
||||
// payMethodFk: 1,
|
||||
// roleFk: 1
|
||||
};
|
||||
const WORKER_MODEL =[
|
||||
{
|
||||
arg: 'fi',
|
||||
type: 'string',
|
||||
description: `The worker fi`,
|
||||
required: true,
|
||||
},
|
||||
{
|
||||
arg: 'name',
|
||||
type: 'string',
|
||||
description: `The user name`,
|
||||
required: true,
|
||||
},
|
||||
{
|
||||
arg: 'firstName',
|
||||
type: 'string',
|
||||
description: `The worker firstname`,
|
||||
required: true,
|
||||
},
|
||||
{
|
||||
arg: 'lastNames',
|
||||
type: 'string',
|
||||
description: `The worker lastnames`,
|
||||
required: true,
|
||||
},
|
||||
{
|
||||
arg: 'email',
|
||||
type: 'string',
|
||||
description: `The worker email`,
|
||||
required: true,
|
||||
},
|
||||
{
|
||||
arg: 'street',
|
||||
type: 'string',
|
||||
description: `The worker address`,
|
||||
required: true,
|
||||
},
|
||||
{
|
||||
arg: 'city',
|
||||
type: 'string',
|
||||
description: `The worker city`,
|
||||
required: true,
|
||||
},
|
||||
{
|
||||
arg: 'provinceFk',
|
||||
type: 'number',
|
||||
description: `The worker province`,
|
||||
required: true,
|
||||
},
|
||||
{
|
||||
arg: 'companyFk',
|
||||
type: 'number',
|
||||
description: `The worker company`,
|
||||
required: true,
|
||||
},
|
||||
{
|
||||
arg: 'postcode',
|
||||
type: 'string',
|
||||
description: `The worker postcode`,
|
||||
required: true,
|
||||
},
|
||||
{
|
||||
arg: 'phone',
|
||||
type: 'string',
|
||||
description: `The worker phone`,
|
||||
required: true,
|
||||
},
|
||||
{
|
||||
arg: 'code',
|
||||
type: 'string',
|
||||
description: `The worker code`,
|
||||
required: true,
|
||||
},
|
||||
{
|
||||
arg: 'bossFk',
|
||||
type: 'number',
|
||||
description: `The worker boss`,
|
||||
required: true,
|
||||
},
|
||||
{
|
||||
arg: 'birth',
|
||||
type: 'date',
|
||||
description: `The worker birth`,
|
||||
required: true,
|
||||
},
|
||||
{
|
||||
arg: 'payMethodFk',
|
||||
type: 'number',
|
||||
description: `The client payMethod`,
|
||||
required: true,
|
||||
},
|
||||
{
|
||||
arg: 'iban',
|
||||
type: 'string',
|
||||
description: `The client iban`,
|
||||
},
|
||||
{
|
||||
arg: 'bankEntityFk',
|
||||
type: 'number',
|
||||
description: `The client bank entity`,
|
||||
}
|
||||
];
|
||||
|
||||
it(`should not find worker as he's not created yet`, async() => {
|
||||
let isValid = false;
|
||||
|
||||
isValid = validatorBodyModel(WORKER_MODEL, defaultWorker).isValid;
|
||||
|
||||
expect(isValid).toBeTrue();
|
||||
});
|
||||
|
||||
it('should create a new worker', async() => {
|
||||
let isValid = false;
|
||||
isValid = validatorBodyModel(WORKER_MODEL, defaultWorker).isValid;
|
||||
|
||||
expect(isValid).toBeTrue();
|
||||
});
|
||||
|
||||
it('should update a new worker', async() => {
|
||||
let isValid = false;
|
||||
|
||||
isValid = validatorBodyModel(WORKER_MODEL, defaultWorker).isValid;
|
||||
|
||||
expect(isValid).toBeTrue();
|
||||
});
|
||||
|
||||
it('should not be able to create a worker if exists', async() => {
|
||||
let isValid = false;
|
||||
let error;
|
||||
|
||||
isValid = validatorBodyModel(WORKER_MODEL, defaultWorker).isValid;
|
||||
|
||||
expect(isValid).toBeTrue();
|
||||
});
|
||||
});
|
|
@ -11,7 +11,8 @@ describe('Client Create', () => {
|
|||
street: 'WALL STREET',
|
||||
city: 'New York',
|
||||
businessTypeFk: 'florist',
|
||||
provinceFk: 1
|
||||
provinceFk: 1,
|
||||
countryFk: 1
|
||||
};
|
||||
|
||||
beforeAll(async() => {
|
||||
|
|
|
@ -10,10 +10,7 @@ module.exports = Self => {
|
|||
require('./client-methods')(Self);
|
||||
|
||||
// Validations
|
||||
// Self.isValid(function(valid) {
|
||||
// if (!valid)
|
||||
// console.error(valid); // hash of errors {attr: [errmessage, errmessage, ...], attr: ...}
|
||||
// });
|
||||
|
||||
Self.validatesPresenceOf('street', {
|
||||
message: 'Street cannot be empty'
|
||||
});
|
||||
|
@ -21,15 +18,6 @@ module.exports = Self => {
|
|||
Self.validatesUniquenessOf('fi', {
|
||||
message: 'TIN must be unique'
|
||||
});
|
||||
Self.validatesPresenceOf('fi', {
|
||||
message: 'fi cannot be empty'
|
||||
});
|
||||
Self.validatesPresenceOf('provinceFk', {
|
||||
message: 'fi cannot be empty'
|
||||
});
|
||||
Self.validatesPresenceOf('countryFk', {
|
||||
message: 'countryFk cannot be empty'
|
||||
});
|
||||
|
||||
Self.validatesFormatOf('email', {
|
||||
message: 'Invalid email',
|
||||
|
|
Loading…
Reference in New Issue