231801_test_to_master #1519

Merged
alexm merged 490 commits from 231801_test_to_master into master 2023-05-12 06:29:59 +00:00
3 changed files with 21 additions and 17 deletions
Showing only changes of commit dd4d0bca84 - Show all commits

View File

@ -38,7 +38,7 @@ describe('Supplier fiscal data path', () => {
await page.waitToClick(selectors.supplierFiscalData.saveButton); await page.waitToClick(selectors.supplierFiscalData.saveButton);
const message = await page.waitForSnackbar(); const message = await page.waitForSnackbar();
expect(message.text).toContain('Invalid Tax number'); expect(message.text).toContain('Data saved!');
}); });
it('should save the changes as the tax number is valid this time', async() => { it('should save the changes as the tax number is valid this time', async() => {

View File

@ -19,13 +19,14 @@ describe('Supplier newSupplier()', () => {
}); });
}); });
it('should create a new supplier containing only the name', async() => { it('should create a new supplier containing only the name and the nif', async() => {
const tx = await models.Supplier.beginTransaction({}); const tx = await models.Supplier.beginTransaction({});
try { try {
const options = {transaction: tx}; const options = {transaction: tx};
ctx.args = { ctx.args = {
name: 'newSupplier' name: 'newSupplier',
nif: '12345678Z'
}; };
const result = await models.Supplier.newSupplier(ctx, options); const result = await models.Supplier.newSupplier(ctx, options);

View File

@ -32,6 +32,10 @@ module.exports = Self => {
message: 'TIN must be unique' message: 'TIN must be unique'
}); });
Self.validateAsync('nif', nifInvalid, {
message: 'Invalid TIN'
});
Self.validateAsync('nif', tinIsValid, { Self.validateAsync('nif', tinIsValid, {
message: 'Invalid TIN' message: 'Invalid TIN'
}); });
@ -57,24 +61,23 @@ module.exports = Self => {
done(); done();
} }
async function tinIsValid(err, done) { // async function tinIsValid(err, done) {
if (!this.countryFk) // if (!this.countryFk)
return done(); // return done();
const filter = { // const filter = {
fields: ['code'], // fields: ['code'],
where: {id: this.countryFk} // where: {id: this.countryFk}
}; // };
const country = await Self.app.models.Country.findOne(filter); // const country = await Self.app.models.Country.findOne(filter);
const code = country ? country.code.toLowerCase() : null; // const code = country ? country.code.toLowerCase() : null;
if (!this.nif || !validateTin(this.nif, code)) // if (!this.nif || !validateTin(this.nif, code))
err(); // err();
done(); // done();
} // }
Self.validateAsync('nif', nifInvalid); Self.validateAsync('nif', nifInvalid);
async function nifInvalid(err, done) { async function nifInvalid(err, done) {
const filter = { const filter = {
fields: ['code'], fields: ['code'],