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: [{
|
returns: [{
|
||||||
arg: 'saleVolume',
|
arg: 'saleVolume',
|
||||||
type: ['Object']
|
type: ['object']
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
arg: 'packingTypeVolume',
|
arg: 'packingTypeVolume',
|
||||||
type: ['Object']
|
type: ['object']
|
||||||
}],
|
}],
|
||||||
http: {
|
http: {
|
||||||
path: `/:id/getVolume`,
|
path: `/:id/getVolume`,
|
||||||
|
@ -44,6 +44,6 @@ module.exports = Self => {
|
||||||
WHERE s.ticketFk = ?
|
WHERE s.ticketFk = ?
|
||||||
GROUP BY s.itemPackingTypeFk`, [ticketFk], myOptions);
|
GROUP BY s.itemPackingTypeFk`, [ticketFk], myOptions);
|
||||||
|
|
||||||
return [saleVolume, packingTypeVolume]
|
return [saleVolume, packingTypeVolume];
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
|
@ -8,12 +8,15 @@ describe('ticket getVolume()', () => {
|
||||||
const options = {transaction: tx};
|
const options = {transaction: tx};
|
||||||
|
|
||||||
const ticketId = 1;
|
const ticketId = 1;
|
||||||
const result = await models.Ticket.getVolume(ticketId, options);
|
const expectedSaleVolume = 1.09;
|
||||||
const saleVolume = result[0];
|
const expectedPackingTypeVolume = 0.028;
|
||||||
const packingTypeVolume = result[1];
|
|
||||||
|
|
||||||
expect(saleVolume).toBeDefined;
|
const result = await models.Ticket.getVolume(ticketId, options);
|
||||||
expect(packingTypeVolume).toBeDefined;
|
const [saleVolume] = result[0];
|
||||||
|
const [packingTypeVolume] = result[1];
|
||||||
|
|
||||||
|
expect(saleVolume.volume).toEqual(expectedSaleVolume);
|
||||||
|
expect(packingTypeVolume.volume).toEqual(expectedPackingTypeVolume);
|
||||||
|
|
||||||
await tx.rollback();
|
await tx.rollback();
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
|
|
|
@ -24,15 +24,18 @@ class Controller extends Section {
|
||||||
}
|
}
|
||||||
|
|
||||||
applyVolumes() {
|
applyVolumes() {
|
||||||
const ticket = this.sales[0].ticketFk
|
const ticket = this.sales[0].ticketFk;
|
||||||
this.$http.get(`Tickets/${ticket}/getVolume`).then(res => {
|
this.$http.get(`Tickets/${ticket}/getVolume`).then(res => {
|
||||||
this.sales.forEach(sale => {
|
const saleVolume = res.data.saleVolume;
|
||||||
res.data.saleVolume.forEach(volume => {
|
|
||||||
if (sale.id === volume.saleFk)
|
const volumes = new Map();
|
||||||
sale.saleVolume = volume;
|
for (const volume of saleVolume)
|
||||||
});
|
volumes.set(volume.saleFk, volume);
|
||||||
});
|
|
||||||
this.packingTypeVolume = res.data.packingTypeVolume
|
for (const sale of this.sales)
|
||||||
|
sale.saleVolume = volumes.get(sale.id);
|
||||||
|
|
||||||
|
this.packingTypeVolume = res.data.packingTypeVolume;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -35,7 +35,7 @@ describe('ticket', () => {
|
||||||
|
|
||||||
describe('applyVolumes()', () => {
|
describe('applyVolumes()', () => {
|
||||||
const ticket = 1;
|
const ticket = 1;
|
||||||
const respondGet =
|
const response =
|
||||||
{
|
{
|
||||||
saleVolume: [
|
saleVolume: [
|
||||||
{saleFk: 1, volume: 0.012},
|
{saleFk: 1, volume: 0.012},
|
||||||
|
@ -43,7 +43,7 @@ describe('ticket', () => {
|
||||||
],
|
],
|
||||||
packingTypeVolume: [
|
packingTypeVolume: [
|
||||||
{code: 'V', volume: 1},
|
{code: 'V', volume: 1},
|
||||||
{code: 'H',volume: 2},
|
{code: 'H', volume: 2}
|
||||||
]
|
]
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -61,45 +61,32 @@ describe('ticket', () => {
|
||||||
});
|
});
|
||||||
|
|
||||||
it(`should apply volumes to the sales if sales and volumes properties are defined on controller`, () => {
|
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 = [
|
controller.sales = [
|
||||||
{id: 1, name: 'Sale one', ticketFk: ticket},
|
{id: 1, name: 'Sale one', ticketFk: ticket},
|
||||||
{id: 2, name: 'Sale two'}
|
{id: 2, name: 'Sale two'}
|
||||||
];
|
];
|
||||||
$httpBackend.flush();
|
$httpBackend.flush();
|
||||||
|
|
||||||
expect(controller.sales[0].saleVolume.volume).toEqual(0.012);
|
expect(controller.sales[0].saleVolume.volume).toEqual(expectedResultOne);
|
||||||
expect(controller.sales[1].saleVolume.volume).toEqual(0.015);
|
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`, () => {
|
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 = [
|
controller.sales = [
|
||||||
{id: 1, name: 'Sale one', ticketFk: ticket},
|
{id: 1, name: 'Sale one', ticketFk: ticket},
|
||||||
{id: 2, name: 'Sale two'}
|
{id: 2, name: 'Sale two'}
|
||||||
];
|
];
|
||||||
$httpBackend.flush();
|
$httpBackend.flush();
|
||||||
|
|
||||||
expect(controller.packingTypeVolume[0]).toBeDefined;
|
expect(controller.packingTypeVolume[0].code).toEqual(expectedResultOne);
|
||||||
expect(controller.packingTypeVolume[1]).toBeDefined
|
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