Tarea #533 /sale/removes.js Backend unit tests
This commit is contained in:
parent
ea785bd9a1
commit
6f8fa86786
|
@ -22,12 +22,15 @@ module.exports = Self => {
|
||||||
});
|
});
|
||||||
|
|
||||||
Self.removes = async params => {
|
Self.removes = async params => {
|
||||||
|
console.log(params);
|
||||||
let thisTicketIsEditable = await Self.app.models.Ticket.isEditable(params.actualTicketFk);
|
let thisTicketIsEditable = await Self.app.models.Ticket.isEditable(params.actualTicketFk);
|
||||||
if (!thisTicketIsEditable)
|
if (!thisTicketIsEditable)
|
||||||
throw new UserError(`The sales of this ticket can't be modified`);
|
throw new UserError(`The sales of this ticket can't be modified`);
|
||||||
|
|
||||||
|
let promises = [];
|
||||||
for (let i = 0; i < params.sales.length; i++) {
|
for (let i = 0; i < params.sales.length; i++) {
|
||||||
await Self.app.models.Sale.destroyById(params.sales[i].id);
|
promises.push(Self.app.models.Sale.destroyById(params.sales[i].id));
|
||||||
}
|
}
|
||||||
|
return Promise.all(promises);
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
|
@ -0,0 +1,41 @@
|
||||||
|
const app = require(`${servicesDir}/ticket/server/server`);
|
||||||
|
const restoreFixtures = require(`${servicesDir}/db/testing_fixtures`);
|
||||||
|
|
||||||
|
describe('sale removes()', () => {
|
||||||
|
let sqlStatements = {deletes: ``, inserts: `
|
||||||
|
INSERT INTO vn2008.Movimientos (Id_Movimiento, Id_Article, Id_Ticket, Concepte, Cantidad, Preu, Descuento, CostFixat, Reservado, OK, PrecioFijado, odbc_date) VALUES ('1', '1', '1', 'Gem of Time', '5.00', '23.50', '0', '0.00', '0', '0', '0', '2018-08-20 00:00:00');
|
||||||
|
INSERT INTO vn2008.Movimientos (Id_Movimiento, Id_Article, Id_Ticket, Concepte, Cantidad, Preu, Descuento, CostFixat, Reservado, OK, PrecioFijado, odbc_date) VALUES ('2', '2', '1', 'Gem of Mind', '10.00', '4.50', '0', '0.00', '0', '0', '0', '2018-08-20 00:00:00');
|
||||||
|
`, updates: ``};
|
||||||
|
|
||||||
|
afterAll(() => {
|
||||||
|
restoreFixtures(sqlStatements);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should throw an error if the ticket of the given sales is not editable', async() => {
|
||||||
|
let error;
|
||||||
|
|
||||||
|
let params = {
|
||||||
|
sales: [{id: 1, instance: 0}, {id: 2, instance: 1}],
|
||||||
|
actualTicketFk: 2
|
||||||
|
};
|
||||||
|
|
||||||
|
try {
|
||||||
|
await app.models.Sale.removes(params);
|
||||||
|
} catch (e) {
|
||||||
|
error = e;
|
||||||
|
}
|
||||||
|
|
||||||
|
expect(error).toEqual(new Error(`The sales of this ticket can't be modified`));
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should delete the sales', async() => {
|
||||||
|
let params = {
|
||||||
|
sales: [{id: 1, instance: 0}, {id: 2, instance: 1}],
|
||||||
|
actualTicketFk: 1
|
||||||
|
};
|
||||||
|
|
||||||
|
let res = await app.models.Sale.removes(params);
|
||||||
|
|
||||||
|
expect(res).toEqual([{count: 1}, {count: 1}]);
|
||||||
|
});
|
||||||
|
});
|
Loading…
Reference in New Issue