2019-01-24 08:08:28 +00:00
|
|
|
const app = require('vn-loopback/server/server');
|
2018-08-07 13:48:55 +00:00
|
|
|
|
2018-10-24 12:10:08 +00:00
|
|
|
describe('order removes()', () => {
|
|
|
|
let row;
|
|
|
|
let newRow;
|
|
|
|
|
2019-03-01 10:50:26 +00:00
|
|
|
beforeAll(async done => {
|
2018-10-24 12:10:08 +00:00
|
|
|
row = await app.models.OrderRow.findOne({where: {id: 12}});
|
|
|
|
row.id = null;
|
|
|
|
newRow = await app.models.OrderRow.create(row);
|
2019-03-01 10:50:26 +00:00
|
|
|
|
|
|
|
done();
|
2018-10-24 12:10:08 +00:00
|
|
|
});
|
|
|
|
|
2018-08-07 13:48:55 +00:00
|
|
|
it('should throw an error if rows property is empty', async() => {
|
|
|
|
let error;
|
|
|
|
try {
|
|
|
|
await app.models.OrderRow.removes({rows: []});
|
|
|
|
} catch (e) {
|
|
|
|
error = e;
|
|
|
|
}
|
|
|
|
|
2018-10-24 12:10:08 +00:00
|
|
|
expect(error).toEqual(new Error('There is nothing to delete'));
|
2018-08-07 13:48:55 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
it('should throw an error if the row selected is not editable', async() => {
|
|
|
|
let error;
|
|
|
|
try {
|
|
|
|
await app.models.OrderRow.removes({rows: [2]});
|
|
|
|
} catch (e) {
|
|
|
|
error = e;
|
|
|
|
}
|
|
|
|
|
|
|
|
expect(error).toEqual(new Error('This order is not editable'));
|
|
|
|
});
|
2018-10-24 12:10:08 +00:00
|
|
|
|
|
|
|
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}]);
|
|
|
|
});
|
2018-08-07 13:48:55 +00:00
|
|
|
});
|