salix/loopback/common/methods/vn-model/specs/rewriteDbError.spec.js

30 lines
881 B
JavaScript
Raw Normal View History

const models = require('vn-loopback/server/server').models;
describe('Model rewriteDbError()', () => {
it('should extend rewriteDbError properties to any model passed', () => {
const exampleModel = models.ItemTag;
expect(exampleModel.rewriteDbError).toBeDefined();
});
it('should handle a duplicated warehouse error', async() => {
const tx = await models.Ticket.beginTransaction({});
let error;
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();
error = e;
}
2022-08-04 11:52:59 +00:00
expect(error.message).toEqual(`The tag or priority can't be repeated for an item`);
});
});