2021-08-30 11:27:51 +00:00
|
|
|
const models = require('vn-loopback/server/server').models;
|
2018-09-18 08:11:51 +00:00
|
|
|
|
|
|
|
describe('Model rewriteDbError()', () => {
|
|
|
|
it('should extend rewriteDbError properties to any model passed', () => {
|
2021-08-30 11:27:51 +00:00
|
|
|
const exampleModel = models.ItemTag;
|
2018-09-18 08:11:51 +00:00
|
|
|
|
|
|
|
expect(exampleModel.rewriteDbError).toBeDefined();
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should handle a duplicated warehouse error', async() => {
|
2021-08-30 11:27:51 +00:00
|
|
|
const tx = await models.Ticket.beginTransaction({});
|
|
|
|
|
2018-09-18 08:11:51 +00:00
|
|
|
let error;
|
2021-08-30 11:27:51 +00:00
|
|
|
|
|
|
|
try {
|
|
|
|
const options = {transaction: tx};
|
|
|
|
|
|
|
|
const itemTag = {itemFk: 1, tagFk: 56, value: 'Ranged weapon', priority: 1};
|
|
|
|
await models.ItemTag.create(itemTag, options);
|
|
|
|
|
|
|
|
await tx.rollback();
|
|
|
|
} catch (e) {
|
|
|
|
await tx.rollback();
|
2018-09-18 08:11:51 +00:00
|
|
|
error = e;
|
2021-08-30 11:27:51 +00:00
|
|
|
}
|
|
|
|
|
2022-08-04 11:52:59 +00:00
|
|
|
expect(error.message).toEqual(`The tag or priority can't be repeated for an item`);
|
2018-09-18 08:11:51 +00:00
|
|
|
});
|
|
|
|
});
|