Merge branch 'dev' of https://git.verdnatura.es/salix into dev

This commit is contained in:
Javi Gallego 2018-10-24 14:11:28 +02:00
commit 5532dedcc3
5 changed files with 41 additions and 14 deletions

View File

@ -7,4 +7,3 @@ describe('client getMana()', () => {
expect(result.mana).toEqual(151.33); expect(result.mana).toEqual(151.33);
}); });
}); });

View File

@ -1,14 +1,13 @@
const app = require(`${servicesDir}/ticket/server/server`); const app = require(`${servicesDir}/ticket/server/server`);
xdescribe('sale removes()', () => { describe('sale removes()', () => {
let sale; let sale;
let newsale;
beforeAll(async() => { beforeAll(async() => {
sale = await app.models.Sale.findOne({where: {id: 1}}); sale = await app.models.Sale.findOne({where: {id: 9}});
}); sale.id = null;
newsale = await app.models.Sale.create(sale);
afterAll(async() => {
await app.models.Sale.create(sale);
}); });
it('should throw an error if the ticket of the given sales is not editable', async() => { it('should throw an error if the ticket of the given sales is not editable', async() => {
@ -30,8 +29,8 @@ xdescribe('sale removes()', () => {
it('should delete the sales', async() => { it('should delete the sales', async() => {
let params = { let params = {
sales: [{id: 1, instance: 0}], sales: [{id: newsale.id, instance: 0}],
actualTicketFk: 1 actualTicketFk: 16
}; };
let res = await app.models.Sale.removes(params); let res = await app.models.Sale.removes(params);

View File

@ -23,9 +23,12 @@ module.exports = Self => {
Self.removes = async params => { Self.removes = async params => {
if (!params.rows || !params.rows.length) if (!params.rows || !params.rows.length)
throw new UserError('There is nothing delete'); throw new UserError('There is nothing to delete');
await Self.app.models.Order.isEditable(params.actualOrderId); let isEditable = await Self.app.models.Order.isEditable(params.actualOrderId);
if (!isEditable)
throw new UserError('This order is not editable');
let promises = []; let promises = [];
for (let i = 0; i < params.rows.length; i++) { for (let i = 0; i < params.rows.length; i++) {

View File

@ -1,6 +1,11 @@
const app = require(`../../../../server/server`); const app = require(`../../../../server/server`);
describe('order addToOrder()', () => { describe('order addToOrder()', () => {
let rowToDelete;
afterAll(async() => {
await app.models.OrderRow.removes({rows: [rowToDelete], actualOrderId: 16});
});
it('should add a row to a given order', async() => { it('should add a row to a given order', async() => {
let unmodifiedRows = await app.models.OrderRow.find({where: {orderFk: 16}}); let unmodifiedRows = await app.models.OrderRow.find({where: {orderFk: 16}});
@ -19,7 +24,8 @@ describe('order addToOrder()', () => {
let modifiedRows = await app.models.OrderRow.find({where: {orderFk: 16}}); let modifiedRows = await app.models.OrderRow.find({where: {orderFk: 16}});
rowToDelete = modifiedRows[modifiedRows.length - 1].id;
expect(modifiedRows.length).toBe(5); expect(modifiedRows.length).toBe(5);
await app.models.OrderRow.removes({rows: [modifiedRows[modifiedRows.length - 1].id]});
}); });
}); });

View File

@ -1,6 +1,15 @@
const app = require(`../../../../server/server`); const app = require(`../../../../server/server`);
xdescribe('order removes()', () => { describe('order removes()', () => {
let row;
let newRow;
beforeAll(async() => {
row = await app.models.OrderRow.findOne({where: {id: 12}});
row.id = null;
newRow = await app.models.OrderRow.create(row);
});
it('should throw an error if rows property is empty', async() => { it('should throw an error if rows property is empty', async() => {
let error; let error;
try { try {
@ -9,7 +18,7 @@ xdescribe('order removes()', () => {
error = e; error = e;
} }
expect(error).toEqual(new Error('There is nothing delete')); expect(error).toEqual(new Error('There is nothing to delete'));
}); });
it('should throw an error if the row selected is not editable', async() => { it('should throw an error if the row selected is not editable', async() => {
@ -22,4 +31,15 @@ xdescribe('order removes()', () => {
expect(error).toEqual(new Error('This order is not editable')); expect(error).toEqual(new Error('This order is not editable'));
}); });
it('should delete the row', async() => {
let params = {
rows: [newRow.id],
actualOrderId: 16
};
let res = await app.models.OrderRow.removes(params);
expect(res).toEqual([{count: 1}]);
});
}); });