test(zone): getZoneClosing() front and back
gitea/salix/pipeline/head This commit looks good Details

This commit is contained in:
Alex Moreno 2022-03-07 08:02:59 +01:00
parent a658969afa
commit 2c853a7885
4 changed files with 33 additions and 10 deletions

View File

@ -45,7 +45,6 @@ module.exports = Self => {
DISTINCT z.id, DISTINCT z.id,
z.name, z.name,
am.name agencyModeName, am.name agencyModeName,
type,
IFNULL(ze.hour, z.hour) as hour, IFNULL(ze.hour, z.hour) as hour,
IFNULL(ze.price, z.price) as price IFNULL(ze.price, z.price) as price
FROM vn.zone z FROM vn.zone z
@ -62,7 +61,6 @@ module.exports = Self => {
GROUP BY z.id GROUP BY z.id
`; `;
const zones = await Self.rawSql(query, paramsSql, myOptions); return await Self.rawSql(query, paramsSql, myOptions);
return zones;
}; };
}; };

View File

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

View File

@ -81,9 +81,7 @@ class Controller extends Section {
}; };
this.$http.post(`Zones/getZoneClosing`, params) this.$http.post(`Zones/getZoneClosing`, params)
.then(res => { .then(res => this.zoneClosing = res.data);
this.zoneClosing = res.data;
});
} }
preview(zone) { preview(zone) {

View File

@ -96,12 +96,14 @@ describe('Zone Component vnZoneDeliveryDays', () => {
expect(controller.$.zoneEvents.show).not.toHaveBeenCalled(); 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'); jest.spyOn(controller.$.zoneEvents, 'show');
const event = new Event('click'); const event = new Event('click');
const target = document.createElement('div'); const target = document.createElement('div');
target.dispatchEvent(event); target.dispatchEvent(event);
const day = new Date();
const events = [ const events = [
{zoneFk: 1}, {zoneFk: 1},
{zoneFk: 2}, {zoneFk: 2},
@ -111,12 +113,14 @@ describe('Zone Component vnZoneDeliveryDays', () => {
zonesId: [1, 2, 8], zonesId: [1, 2, 8],
date: [day][0] date: [day][0]
}; };
const day = new Date(); const response = [{id: 1, hour: ''}];
$httpBackend.expect('POST', 'Zones/getZoneClosing', params).respond({});
$httpBackend.when('POST', 'Zones/getZoneClosing', params).respond({response});
controller.onSelection(event, events, [day]); controller.onSelection(event, events, [day]);
$httpBackend.flush();
expect(controller.$.zoneEvents.show).toHaveBeenCalledWith(target); expect(controller.$.zoneEvents.show).toHaveBeenCalledWith(target);
expect(controller.zoneClosing).toBeDefined(); expect(controller.zoneClosing.id).toEqual(response.id);
}); });
}); });
}); });