From f6ab9d8a3186969a92fae9be40dd9ee5c79a7dbc Mon Sep 17 00:00:00 2001 From: vicent Date: Fri, 10 Jun 2022 08:15:54 +0200 Subject: [PATCH] feat: updated backTest --- .../zone/back/methods/zone/exclusionGeo.js | 2 +- .../methods/zone/specs/exclusionGeo.spec.js | 21 +++++++++++++++++++ 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/modules/zone/back/methods/zone/exclusionGeo.js b/modules/zone/back/methods/zone/exclusionGeo.js index f36d67039..38ea0944e 100644 --- a/modules/zone/back/methods/zone/exclusionGeo.js +++ b/modules/zone/back/methods/zone/exclusionGeo.js @@ -39,7 +39,7 @@ module.exports = Self => { if (typeof options == 'object') Object.assign(myOptions, options); - if (!geoIds.lenght) throw new Error(`You must select a location`); + if (!geoIds[0]) throw new UserError(`You must select a location`); const newZoneExclusion = await models.ZoneExclusion.create({ zoneFk: zoneFk, diff --git a/modules/zone/back/methods/zone/specs/exclusionGeo.spec.js b/modules/zone/back/methods/zone/specs/exclusionGeo.spec.js index ed06a4cd2..5f5c76fb6 100644 --- a/modules/zone/back/methods/zone/specs/exclusionGeo.spec.js +++ b/modules/zone/back/methods/zone/specs/exclusionGeo.spec.js @@ -1,6 +1,27 @@ const models = require('vn-loopback/server/server').models; describe('zone exclusionGeo()', () => { + it(`should show an error when location isn't selected`, async() => { + const tx = await models.Zone.beginTransaction({}); + + try { + const options = {transaction: tx}; + const today = new Date(); + const zoneId = 1; + const geoIds = []; + const result = await models.Zone.exclusionGeo(zoneId, today, geoIds, options); + + expect(result.length).toEqual(2); + + await tx.rollback(); + } catch (e) { + await tx.rollback(); + error = e; + } + + expect(error.message).toContain(`You must select a location`); + }); + it('should create two exclusion by geo', async() => { const tx = await models.Zone.beginTransaction({});