From 2c853a7885cd7f9412d335ff8a5b9a85374001e5 Mon Sep 17 00:00:00 2001 From: alexm Date: Mon, 7 Mar 2022 08:02:59 +0100 Subject: [PATCH] test(zone): getZoneClosing() front and back --- .../zone/back/methods/zone/getZoneClosing.js | 4 +--- .../methods/zone/specs/getZoneClosing.spec.js | 23 +++++++++++++++++++ modules/zone/front/delivery-days/index.js | 4 +--- .../zone/front/delivery-days/index.spec.js | 12 ++++++---- 4 files changed, 33 insertions(+), 10 deletions(-) create mode 100644 modules/zone/back/methods/zone/specs/getZoneClosing.spec.js diff --git a/modules/zone/back/methods/zone/getZoneClosing.js b/modules/zone/back/methods/zone/getZoneClosing.js index 02286e6d5..8d9ccdb21 100644 --- a/modules/zone/back/methods/zone/getZoneClosing.js +++ b/modules/zone/back/methods/zone/getZoneClosing.js @@ -45,7 +45,6 @@ module.exports = Self => { DISTINCT z.id, z.name, am.name agencyModeName, - type, IFNULL(ze.hour, z.hour) as hour, IFNULL(ze.price, z.price) as price FROM vn.zone z @@ -62,7 +61,6 @@ module.exports = Self => { GROUP BY z.id `; - const zones = await Self.rawSql(query, paramsSql, myOptions); - return zones; + return await Self.rawSql(query, paramsSql, myOptions); }; }; diff --git a/modules/zone/back/methods/zone/specs/getZoneClosing.spec.js b/modules/zone/back/methods/zone/specs/getZoneClosing.spec.js new file mode 100644 index 000000000..0c479dda0 --- /dev/null +++ b/modules/zone/back/methods/zone/specs/getZoneClosing.spec.js @@ -0,0 +1,23 @@ +const models = require('vn-loopback/server/server').models; + +describe('zone getZoneClosing()', () => { + it('should return closing time of zones', async() => { + const tx = await models.Zone.beginTransaction({}); + + try { + const options = {transaction: tx}; + const date = new Date(); + const today = date.toISOString().split('T')[0]; + + const result = await models.Zone.getZoneClosing([1, 2, 3], today, options); + + expect(result.length).toEqual(3); + expect(result[0].hour).toBeDefined(); + + await tx.rollback(); + } catch (e) { + await tx.rollback(); + throw e; + } + }); +}); diff --git a/modules/zone/front/delivery-days/index.js b/modules/zone/front/delivery-days/index.js index d4bb3b335..21c65678f 100644 --- a/modules/zone/front/delivery-days/index.js +++ b/modules/zone/front/delivery-days/index.js @@ -81,9 +81,7 @@ class Controller extends Section { }; this.$http.post(`Zones/getZoneClosing`, params) - .then(res => { - this.zoneClosing = res.data; - }); + .then(res => this.zoneClosing = res.data); } preview(zone) { diff --git a/modules/zone/front/delivery-days/index.spec.js b/modules/zone/front/delivery-days/index.spec.js index c03da585f..3d71bc93f 100644 --- a/modules/zone/front/delivery-days/index.spec.js +++ b/modules/zone/front/delivery-days/index.spec.js @@ -96,12 +96,14 @@ describe('Zone Component vnZoneDeliveryDays', () => { expect(controller.$.zoneEvents.show).not.toHaveBeenCalled(); }); - xit('should call the show() method and call getZoneClosing with the expected ids', () => { + it('should call the show() method and call getZoneClosing() with the expected ids', () => { jest.spyOn(controller.$.zoneEvents, 'show'); const event = new Event('click'); const target = document.createElement('div'); target.dispatchEvent(event); + + const day = new Date(); const events = [ {zoneFk: 1}, {zoneFk: 2}, @@ -111,12 +113,14 @@ describe('Zone Component vnZoneDeliveryDays', () => { zonesId: [1, 2, 8], date: [day][0] }; - const day = new Date(); - $httpBackend.expect('POST', 'Zones/getZoneClosing', params).respond({}); + const response = [{id: 1, hour: ''}]; + + $httpBackend.when('POST', 'Zones/getZoneClosing', params).respond({response}); controller.onSelection(event, events, [day]); + $httpBackend.flush(); expect(controller.$.zoneEvents.show).toHaveBeenCalledWith(target); - expect(controller.zoneClosing).toBeDefined(); + expect(controller.zoneClosing.id).toEqual(response.id); }); }); });