adapted a test that was using the niches model

This commit is contained in:
Carlos Jimenez Ruiz 2021-08-30 13:27:51 +02:00
parent 5ca795adb3
commit 0b331c4026
1 changed files with 17 additions and 7 deletions

View File

@ -1,19 +1,29 @@
const app = require('vn-loopback/server/server');
const models = require('vn-loopback/server/server').models;
describe('Model rewriteDbError()', () => {
it('should extend rewriteDbError properties to any model passed', () => {
let exampleModel = app.models.ItemNiche;
const exampleModel = models.ItemTag;
expect(exampleModel.rewriteDbError).toBeDefined();
});
it('should handle a duplicated warehouse error', async() => {
let itemNiche = {itemFk: 1, warehouseFK: 1, code: 'A11'};
const tx = await models.Ticket.beginTransaction({});
let error;
await app.models.ItemNiche.create(itemNiche).catch(e => {
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;
}).finally(() => {
expect(error.message).toEqual(`The warehouse can't be repeated`);
});
}
expect(error.message).toEqual(`The tag can't be repeated`);
});
});