From 4b65b531fd12dd28d4a768e6e8dcafd18e193ba6 Mon Sep 17 00:00:00 2001 From: vicent Date: Fri, 8 Jul 2022 10:09:03 +0200 Subject: [PATCH] feat: add backTest --- .../methods/zone/specs/exclusionGeo.spec.js | 10 ++--- .../zone/specs/updateExclusionGeo.spec.js | 40 +++++++++++++++++++ 2 files changed, 44 insertions(+), 6 deletions(-) create mode 100644 modules/zone/back/methods/zone/specs/updateExclusionGeo.spec.js diff --git a/modules/zone/back/methods/zone/specs/exclusionGeo.spec.js b/modules/zone/back/methods/zone/specs/exclusionGeo.spec.js index 5f5c76fb6d..562a66d9b9 100644 --- a/modules/zone/back/methods/zone/specs/exclusionGeo.spec.js +++ b/modules/zone/back/methods/zone/specs/exclusionGeo.spec.js @@ -1,17 +1,17 @@ const models = require('vn-loopback/server/server').models; describe('zone exclusionGeo()', () => { + const zoneId = 1; + const today = new Date(); + 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 models.Zone.exclusionGeo(zoneId, today, geoIds, options); await tx.rollback(); } catch (e) { @@ -27,8 +27,6 @@ describe('zone exclusionGeo()', () => { 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); diff --git a/modules/zone/back/methods/zone/specs/updateExclusionGeo.spec.js b/modules/zone/back/methods/zone/specs/updateExclusionGeo.spec.js new file mode 100644 index 0000000000..2f982fc801 --- /dev/null +++ b/modules/zone/back/methods/zone/specs/updateExclusionGeo.spec.js @@ -0,0 +1,40 @@ +const models = require('vn-loopback/server/server').models; + +describe('zone updateExclusionGeo()', () => { + it(`should show an error when location isn't selected`, async() => { + const tx = await models.Zone.beginTransaction({}); + + try { + const options = {transaction: tx}; + const zoneId = 1; + const geoIds = []; + + await models.Zone.updateExclusionGeo(zoneId, geoIds, options); + + await tx.rollback(); + } catch (e) { + await tx.rollback(); + error = e; + } + + expect(error.message).toContain(`You must select a location`); + }); + + it('should delete all exclusion and then create two exclusion by geo for a zone', async() => { + const tx = await models.Zone.beginTransaction({}); + + try { + const options = {transaction: tx}; + const zoneId = 2; + const geoIds = [{id: 1}, {id: 2}]; + const result = await models.Zone.updateExclusionGeo(zoneId, geoIds, options); + + expect(result.length).toEqual(2); + + await tx.rollback(); + } catch (e) { + await tx.rollback(); + throw e; + } + }); +});