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; + } + }); +});