32 lines
919 B
JavaScript
32 lines
919 B
JavaScript
const models = require('vn-loopback/server/server').models;
|
|
|
|
describe('Model rewriteDbError()', () => {
|
|
beforeAll.mockLoopBackContext();
|
|
|
|
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;
|
|
}
|
|
|
|
expect(error.message).toEqual(`The tag or priority can't be repeated for an item`);
|
|
});
|
|
});
|