feat: add backTest
gitea/salix/pipeline/head This commit is unstable Details

This commit is contained in:
Vicent Llopis 2022-06-09 14:59:17 +02:00
parent aab484ad41
commit a9badfc1ba
4 changed files with 48 additions and 7 deletions

View File

@ -1,2 +1,4 @@
INSERT INTO `salix`.`ACL`(`model`, `property`, `accessType`, `permission`, `principalType`, `principalId`)
VALUES('ZoneExclusionGeo', '*', '*', 'ALLOW', 'ROLE', 'employee');
VALUES
('ZoneExclusionGeo', '*', 'READ', 'ALLOW', 'ROLE', 'employee'),
('ZoneExclusionGeo', '*', 'WRITE', 'ALLOW', 'ROLE', 'deliveryBoss');

View File

@ -224,5 +224,6 @@
"The agency is already assigned to another autonomous": "La agencia ya está asignada a otro autónomo",
"date in the future": "Fecha en el futuro",
"reference duplicated": "Referencia duplicada",
"This ticket is already a refund": "Este ticket ya es un abono"
"This ticket is already a refund": "Este ticket ya es un abono",
"You must select a location": "Debes seleccionar una localización"
}

View File

@ -1,7 +1,9 @@
const UserError = require('vn-loopback/util/user-error');
module.exports = Self => {
Self.remoteMethod('exclusionGeo', {
description: 'Exclude a zoneGeo for a zone',
description: 'Exclude a zoneGeo from a zone',
accepts: [
{
arg: 'zoneFk',
@ -30,19 +32,33 @@ module.exports = Self => {
}
});
Self.exclusionGeo = async(zoneFk, date, geoIds) => {
Self.exclusionGeo = async(zoneFk, date, geoIds, options) => {
const models = Self.app.models;
const myOptions = {};
if (typeof options == 'object')
Object.assign(myOptions, options);
if (!geoIds.lenght) throw new Error(`You must select a location`);
const newZoneExclusion = await models.ZoneExclusion.create({
zoneFk: zoneFk,
dated: date
});
}, myOptions);
const promises = [];
for (let geoId of geoIds) {
await models.ZoneExclusionGeo.create({
const newZoneExclusionGeo = await models.ZoneExclusionGeo.create({
zoneExclusionFk: newZoneExclusion.id,
geoFk: geoId.id
});
}, myOptions);
promises.push(newZoneExclusionGeo);
}
const newZoneExclusionGeos = await Promise.all(promises);
return newZoneExclusionGeos;
};
};

View File

@ -0,0 +1,22 @@
const models = require('vn-loopback/server/server').models;
describe('zone exclusionGeo()', () => {
it('should create two exclusion by geo', async() => {
const tx = await models.Zone.beginTransaction({});
try {
const options = {transaction: tx};
const today = new Date();
const zoneId = 1;
const geoIds = [{id: 1}, {id: 2}];
const result = await models.Zone.exclusionGeo(zoneId, today, geoIds, options);
expect(result.length).toEqual(2);
await tx.rollback();
} catch (e) {
await tx.rollback();
throw e;
}
});
});