back test for getComponentsSum
This commit is contained in:
parent
174cea7bc3
commit
d79cffb2c3
|
@ -20,11 +20,11 @@ module.exports = Self => {
|
||||||
});
|
});
|
||||||
Self.getComponentsSum = async id => {
|
Self.getComponentsSum = async id => {
|
||||||
const models = Self.app.models;
|
const models = Self.app.models;
|
||||||
let sales = await models.Sale.find({where: {ticketFk: id}});
|
|
||||||
let components = await models.Component.find();
|
|
||||||
let salesComponents = [];
|
let salesComponents = [];
|
||||||
let componentsSum = [];
|
let componentsSum = [];
|
||||||
|
let sales = await models.Sale.find({where: {ticketFk: id}});
|
||||||
|
let components = await models.Component.find();
|
||||||
|
if (sales.length > 0) {
|
||||||
for (let sale of sales) {
|
for (let sale of sales) {
|
||||||
let myComponents = await models.SaleComponent.find({where: {saleFk: sale.id}});
|
let myComponents = await models.SaleComponent.find({where: {saleFk: sale.id}});
|
||||||
salesComponents = salesComponents.concat(myComponents);
|
salesComponents = salesComponents.concat(myComponents);
|
||||||
|
@ -47,6 +47,7 @@ module.exports = Self => {
|
||||||
|
|
||||||
return acumulator;
|
return acumulator;
|
||||||
});
|
});
|
||||||
|
}
|
||||||
return componentsSum;
|
return componentsSum;
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
|
@ -0,0 +1,18 @@
|
||||||
|
const app = require('vn-loopback/server/server');
|
||||||
|
|
||||||
|
fdescribe('ticket getComponentsSum()', () => {
|
||||||
|
it('should get the list of component of their sales of a given ticket', async() => {
|
||||||
|
let ticketId = 7;
|
||||||
|
let mana = await app.models.Ticket.getComponentsSum(ticketId);
|
||||||
|
|
||||||
|
expect(mana.length).toBeGreaterThan(0);
|
||||||
|
expect(mana[0].componentFk).toBe(22);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should return 0 if the given ticket does not have sales', async() => {
|
||||||
|
let ticketWithoutSales = 21;
|
||||||
|
let mana = await app.models.Ticket.getComponentsSum(ticketWithoutSales);
|
||||||
|
|
||||||
|
expect(mana.length).toEqual(0);
|
||||||
|
});
|
||||||
|
});
|
Loading…
Reference in New Issue