2021-12-15 14:29:22 +00:00
|
|
|
const models = require('vn-loopback/server/server').models;
|
2018-08-07 13:48:55 +00:00
|
|
|
|
2018-10-24 12:10:08 +00:00
|
|
|
describe('order removes()', () => {
|
2018-08-07 13:48:55 +00:00
|
|
|
it('should throw an error if rows property is empty', async() => {
|
2021-12-15 14:29:22 +00:00
|
|
|
const tx = await models.Order.beginTransaction({});
|
|
|
|
|
2018-08-07 13:48:55 +00:00
|
|
|
let error;
|
|
|
|
try {
|
2021-12-15 14:29:22 +00:00
|
|
|
const options = {transaction: tx};
|
|
|
|
|
|
|
|
await models.OrderRow.removes({rows: []}, options);
|
|
|
|
|
|
|
|
await tx.rollback();
|
2018-08-07 13:48:55 +00:00
|
|
|
} catch (e) {
|
2021-12-15 14:29:22 +00:00
|
|
|
await tx.rollback();
|
2018-08-07 13:48:55 +00:00
|
|
|
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() => {
|
2021-12-15 14:29:22 +00:00
|
|
|
const tx = await models.Order.beginTransaction({});
|
|
|
|
|
2018-08-07 13:48:55 +00:00
|
|
|
let error;
|
|
|
|
try {
|
2021-12-15 14:29:22 +00:00
|
|
|
const options = {transaction: tx};
|
|
|
|
|
|
|
|
await models.OrderRow.removes({rows: [2]}, options);
|
|
|
|
|
|
|
|
await tx.rollback();
|
2018-08-07 13:48:55 +00:00
|
|
|
} catch (e) {
|
2021-12-15 14:29:22 +00:00
|
|
|
await tx.rollback();
|
2018-08-07 13:48:55 +00:00
|
|
|
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() => {
|
2021-12-15 14:29:22 +00:00
|
|
|
const tx = await models.Order.beginTransaction({});
|
|
|
|
|
|
|
|
try {
|
|
|
|
const options = {transaction: tx};
|
|
|
|
|
|
|
|
const params = {
|
|
|
|
rows: [12],
|
|
|
|
actualOrderId: 16
|
|
|
|
};
|
2018-10-24 12:10:08 +00:00
|
|
|
|
2021-12-15 14:29:22 +00:00
|
|
|
const res = await models.OrderRow.removes(params, options);
|
2018-10-24 12:10:08 +00:00
|
|
|
|
2021-12-15 14:29:22 +00:00
|
|
|
expect(res).toEqual([{count: 1}]);
|
|
|
|
|
|
|
|
await tx.rollback();
|
|
|
|
} catch (e) {
|
|
|
|
await tx.rollback();
|
|
|
|
throw e;
|
|
|
|
}
|
2018-10-24 12:10:08 +00:00
|
|
|
});
|
2018-08-07 13:48:55 +00:00
|
|
|
});
|