From 0421fd8828ca41e3cc328d7207907e0e63cd8d60 Mon Sep 17 00:00:00 2001 From: carlosjr Date: Mon, 21 Jun 2021 15:04:23 +0200 Subject: [PATCH] back end unit tests for zone endpoints --- .../back/methods/zone/specs/getEvents.spec.js | 20 +++++++ .../back/methods/zone/specs/getLeaves.spec.js | 20 +++++++ .../zone/specs/toggleIsIncluded.spec.js | 56 +++++++++++++++++++ 3 files changed, 96 insertions(+) create mode 100644 modules/zone/back/methods/zone/specs/getEvents.spec.js create mode 100644 modules/zone/back/methods/zone/specs/getLeaves.spec.js create mode 100644 modules/zone/back/methods/zone/specs/toggleIsIncluded.spec.js diff --git a/modules/zone/back/methods/zone/specs/getEvents.spec.js b/modules/zone/back/methods/zone/specs/getEvents.spec.js new file mode 100644 index 000000000..4227908bb --- /dev/null +++ b/modules/zone/back/methods/zone/specs/getEvents.spec.js @@ -0,0 +1,20 @@ +const app = require('vn-loopback/server/server'); + +describe('zone getEvents()', () => { + it('should return all events for the specified geo and agency mode', async() => { + const tx = await app.models.Zone.beginTransaction({}); + + try { + const options = {transaction: tx}; + + let result = await app.models.Zone.getEvents(20, 1, options); + + expect(result.events.length).toEqual(10); + + await tx.rollback(); + } catch (e) { + await tx.rollback(); + throw e; + } + }); +}); diff --git a/modules/zone/back/methods/zone/specs/getLeaves.spec.js b/modules/zone/back/methods/zone/specs/getLeaves.spec.js new file mode 100644 index 000000000..853962cc4 --- /dev/null +++ b/modules/zone/back/methods/zone/specs/getLeaves.spec.js @@ -0,0 +1,20 @@ +const app = require('vn-loopback/server/server'); + +describe('zone getLeaves()', () => { + it('should return the country and the childs containing the search value', async() => { + const tx = await app.models.Zone.beginTransaction({}); + + try { + const options = {transaction: tx}; + + let result = await app.models.Zone.getLeaves(1, null, '46000', options); + + expect(result.length).toEqual(1); + + await tx.rollback(); + } catch (e) { + await tx.rollback(); + throw e; + } + }); +}); diff --git a/modules/zone/back/methods/zone/specs/toggleIsIncluded.spec.js b/modules/zone/back/methods/zone/specs/toggleIsIncluded.spec.js new file mode 100644 index 000000000..5fe948747 --- /dev/null +++ b/modules/zone/back/methods/zone/specs/toggleIsIncluded.spec.js @@ -0,0 +1,56 @@ +const app = require('vn-loopback/server/server'); + +describe('zone toggleIsIncluded()', () => { + it('should return the created location with isIncluded true', async() => { + const tx = await app.models.Zone.beginTransaction({}); + + try { + const options = {transaction: tx}; + + let result = await app.models.Zone.toggleIsIncluded(1, 20, true, options); + + expect(result.isIncluded).toBeTrue(); + + await tx.rollback(); + } catch (e) { + await tx.rollback(); + throw e; + } + }); + + it('should return the created location with isIncluded false', async() => { + const tx = await app.models.Zone.beginTransaction({}); + + try { + const options = {transaction: tx}; + + let result = await app.models.Zone.toggleIsIncluded(1, 20, false, options); + + expect(result.isIncluded).toBeFalse(); + + await tx.rollback(); + } catch (e) { + await tx.rollback(); + throw e; + } + }); + + it('should return the amount of deleted locations', async() => { + const tx = await app.models.Zone.beginTransaction({}); + + try { + const options = {transaction: tx}; + + await app.models.Zone.toggleIsIncluded(1, 20, false, options); + + let result = await app.models.Zone.toggleIsIncluded(1, 20, undefined, options); + + expect(result).toEqual({count: 1}); + + await tx.rollback(); + } catch (e) { + await tx.rollback(); + throw e; + } + }); +});