refacto(ticket_volume): tests and front js
gitea/salix/pipeline/head This commit looks good
Details
gitea/salix/pipeline/head This commit looks good
Details
This commit is contained in:
parent
b05f464517
commit
83d2dd2d80
|
@ -11,11 +11,11 @@ module.exports = Self => {
|
|||
}],
|
||||
returns: [{
|
||||
arg: 'saleVolume',
|
||||
type: ['Object']
|
||||
type: ['object']
|
||||
},
|
||||
{
|
||||
arg: 'packingTypeVolume',
|
||||
type: ['Object']
|
||||
type: ['object']
|
||||
}],
|
||||
http: {
|
||||
path: `/:id/getVolume`,
|
||||
|
@ -43,7 +43,7 @@ module.exports = Self => {
|
|||
ON i.code = s.itemPackingTypeFk
|
||||
WHERE s.ticketFk = ?
|
||||
GROUP BY s.itemPackingTypeFk`, [ticketFk], myOptions);
|
||||
|
||||
return [saleVolume, packingTypeVolume]
|
||||
|
||||
return [saleVolume, packingTypeVolume];
|
||||
};
|
||||
};
|
||||
|
|
|
@ -8,12 +8,15 @@ describe('ticket getVolume()', () => {
|
|||
const options = {transaction: tx};
|
||||
|
||||
const ticketId = 1;
|
||||
const result = await models.Ticket.getVolume(ticketId, options);
|
||||
const saleVolume = result[0];
|
||||
const packingTypeVolume = result[1];
|
||||
const expectedSaleVolume = 1.09;
|
||||
const expectedPackingTypeVolume = 0.028;
|
||||
|
||||
expect(saleVolume).toBeDefined;
|
||||
expect(packingTypeVolume).toBeDefined;
|
||||
const result = await models.Ticket.getVolume(ticketId, options);
|
||||
const [saleVolume] = result[0];
|
||||
const [packingTypeVolume] = result[1];
|
||||
|
||||
expect(saleVolume.volume).toEqual(expectedSaleVolume);
|
||||
expect(packingTypeVolume.volume).toEqual(expectedPackingTypeVolume);
|
||||
|
||||
await tx.rollback();
|
||||
} catch (e) {
|
||||
|
|
|
@ -24,15 +24,18 @@ class Controller extends Section {
|
|||
}
|
||||
|
||||
applyVolumes() {
|
||||
const ticket = this.sales[0].ticketFk
|
||||
const ticket = this.sales[0].ticketFk;
|
||||
this.$http.get(`Tickets/${ticket}/getVolume`).then(res => {
|
||||
this.sales.forEach(sale => {
|
||||
res.data.saleVolume.forEach(volume => {
|
||||
if (sale.id === volume.saleFk)
|
||||
sale.saleVolume = volume;
|
||||
});
|
||||
});
|
||||
this.packingTypeVolume = res.data.packingTypeVolume
|
||||
const saleVolume = res.data.saleVolume;
|
||||
|
||||
const volumes = new Map();
|
||||
for (const volume of saleVolume)
|
||||
volumes.set(volume.saleFk, volume);
|
||||
|
||||
for (const sale of this.sales)
|
||||
sale.saleVolume = volumes.get(sale.id);
|
||||
|
||||
this.packingTypeVolume = res.data.packingTypeVolume;
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
|
@ -35,18 +35,18 @@ describe('ticket', () => {
|
|||
|
||||
describe('applyVolumes()', () => {
|
||||
const ticket = 1;
|
||||
const respondGet =
|
||||
const response =
|
||||
{
|
||||
saleVolume: [
|
||||
{saleFk: 1, volume: 0.012},
|
||||
{saleFk: 1, volume: 0.012},
|
||||
{saleFk: 2, volume: 0.015}
|
||||
],
|
||||
packingTypeVolume: [
|
||||
{code: 'V', volume: 1},
|
||||
{code: 'H',volume: 2},
|
||||
{code: 'V', volume: 1},
|
||||
{code: 'H', volume: 2}
|
||||
]
|
||||
};
|
||||
|
||||
|
||||
it(`should not apply volumes to the sales if sales property is not defined on controller`, () => {
|
||||
controller.sales = [{id: 1, name: 'Sale one'}, {id: 2, name: 'Sale two'}];
|
||||
|
||||
|
@ -61,45 +61,32 @@ describe('ticket', () => {
|
|||
});
|
||||
|
||||
it(`should apply volumes to the sales if sales and volumes properties are defined on controller`, () => {
|
||||
$httpBackend.expectGET(`Tickets/${ticket}/getVolume`).respond(respondGet);
|
||||
const expectedResultOne = response.saleVolume[0].volume;
|
||||
const expectedResultTwo = response.saleVolume[1].volume;
|
||||
$httpBackend.expectGET(`Tickets/${ticket}/getVolume`).respond(response);
|
||||
controller.sales = [
|
||||
{id: 1, name: 'Sale one', ticketFk: ticket},
|
||||
{id: 1, name: 'Sale one', ticketFk: ticket},
|
||||
{id: 2, name: 'Sale two'}
|
||||
];
|
||||
$httpBackend.flush();
|
||||
|
||||
expect(controller.sales[0].saleVolume.volume).toEqual(0.012);
|
||||
expect(controller.sales[1].saleVolume.volume).toEqual(0.015);
|
||||
expect(controller.sales[0].saleVolume.volume).toEqual(expectedResultOne);
|
||||
expect(controller.sales[1].saleVolume.volume).toEqual(expectedResultTwo);
|
||||
});
|
||||
|
||||
it(`should apply packing volumes to the sales if sales and volumes properties are defined on controller`, () => {
|
||||
$httpBackend.expectGET(`Tickets/${ticket}/getVolume`).respond(respondGet);
|
||||
const expectedResultOne = response.packingTypeVolume[0].code;
|
||||
const expectedResultTwo = response.packingTypeVolume[1].code;
|
||||
$httpBackend.expectGET(`Tickets/${ticket}/getVolume`).respond(response);
|
||||
controller.sales = [
|
||||
{id: 1, name: 'Sale one', ticketFk: ticket},
|
||||
{id: 1, name: 'Sale one', ticketFk: ticket},
|
||||
{id: 2, name: 'Sale two'}
|
||||
];
|
||||
$httpBackend.flush();
|
||||
|
||||
expect(controller.packingTypeVolume[0]).toBeDefined;
|
||||
expect(controller.packingTypeVolume[1]).toBeDefined
|
||||
expect(controller.packingTypeVolume[0].code).toEqual(expectedResultOne);
|
||||
expect(controller.packingTypeVolume[1].code).toEqual(expectedResultTwo);
|
||||
});
|
||||
});
|
||||
|
||||
/*
|
||||
it('should join the sale volumes to its respective sale', () => {
|
||||
controller.ticket = {id: 1};
|
||||
let response = {volumes: [
|
||||
{saleFk: 1, m3: 0.008},
|
||||
{saleFk: 2, m3: 0.003}
|
||||
]};
|
||||
|
||||
$httpBackend.expectGET(`tickets/1/getVolume`).respond(response);
|
||||
controller.onDataChange();
|
||||
$httpBackend.flush();
|
||||
|
||||
expect($scope.model.data[0].volume.m3).toBe(0.008);
|
||||
expect($scope.model.data[1].volume.m3).toBe(0.003);
|
||||
});
|
||||
*/
|
||||
});
|
||||
});
|
||||
|
|
Loading…
Reference in New Issue