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

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)
.then(res => {
this.zoneClosing = res.data;
});
.then(res => this.zoneClosing = res.data);
}
preview(zone) {

View File

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