diff --git a/loopback/common/methods/vn-model/specs/rewriteDbError.spec.js b/loopback/common/methods/vn-model/specs/rewriteDbError.spec.js index 5319b185a..e2f842a15 100644 --- a/loopback/common/methods/vn-model/specs/rewriteDbError.spec.js +++ b/loopback/common/methods/vn-model/specs/rewriteDbError.spec.js @@ -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`); }); });