82 lines
2.6 KiB
JavaScript
82 lines
2.6 KiB
JavaScript
const app = require('vn-loopback/server/server');
|
|
|
|
describe('agency editPrices()', () => {
|
|
const zoneId = 1;
|
|
let originalZone;
|
|
|
|
beforeAll(async done => {
|
|
originalZone = await app.models.Zone.findById(zoneId);
|
|
done();
|
|
});
|
|
|
|
afterAll(async done => {
|
|
await await app.models.ZoneCalendar.updateAll({zoneFk: zoneId}, {
|
|
price: originalZone.price,
|
|
bonus: originalZone.bonus
|
|
});
|
|
done();
|
|
});
|
|
|
|
it('should apply price and bonus for a selected day', async() => {
|
|
const delivered = new Date();
|
|
delivered.setHours(0, 0, 0, 0);
|
|
await app.models.Zone.editPrices(zoneId, delivered, 4.00, 2.00, 'Only this day');
|
|
|
|
const editedDays = await app.models.ZoneCalendar.find({
|
|
where: {
|
|
zoneFk: zoneId,
|
|
delivered: delivered
|
|
}
|
|
});
|
|
const firstEditedDay = editedDays[0];
|
|
|
|
expect(editedDays.length).toEqual(1);
|
|
expect(firstEditedDay.price).toEqual(4.00);
|
|
expect(firstEditedDay.bonus).toEqual(2.00);
|
|
});
|
|
|
|
it('should apply price and bonus for all delivery days starting from selected day', async() => {
|
|
const delivered = new Date();
|
|
delivered.setHours(0, 0, 0, 0);
|
|
await app.models.Zone.editPrices(1, delivered, 5.50, 1.00, 'From this day');
|
|
|
|
const editedDays = await app.models.ZoneCalendar.find({
|
|
where: {
|
|
zoneFk: zoneId,
|
|
delivered: {
|
|
gte: delivered
|
|
}
|
|
}
|
|
});
|
|
const firstEditedDay = editedDays[0];
|
|
const lastEditedDay = editedDays[editedDays.length - 1];
|
|
|
|
expect(editedDays.length).toEqual(5);
|
|
expect(firstEditedDay.price).toEqual(5.50);
|
|
expect(firstEditedDay.bonus).toEqual(1.00);
|
|
expect(lastEditedDay.price).toEqual(5.50);
|
|
expect(lastEditedDay.bonus).toEqual(1.00);
|
|
});
|
|
|
|
it('should apply price and bonus for all delivery days', async() => {
|
|
const delivered = new Date();
|
|
delivered.setHours(0, 0, 0, 0);
|
|
await app.models.Zone.editPrices(1, delivered, 7.00, 0.00, 'All days');
|
|
|
|
const editedDays = await app.models.ZoneCalendar.find({
|
|
where: {
|
|
zoneFk: zoneId
|
|
}
|
|
});
|
|
const firstEditedDay = editedDays[0];
|
|
const lastEditedDay = editedDays[editedDays.length - 1];
|
|
|
|
expect(editedDays.length).toEqual(5);
|
|
expect(firstEditedDay.price).toEqual(7.00);
|
|
expect(firstEditedDay.bonus).toEqual(0.00);
|
|
expect(lastEditedDay.price).toEqual(7.00);
|
|
expect(lastEditedDay.bonus).toEqual(0.00);
|
|
});
|
|
});
|
|
|