const app = require('vn-loopback/server/server'); describe('Model rewriteDbError()', () => { it('should extend rewriteDbError properties to any model passed', () => { let exampleModel = app.models.ItemNiche; expect(exampleModel.rewriteDbError).toBeDefined(); }); it('should handle a duplicated warehouse error', async() => { let itemNiche = {itemFk: 1, warehouseFK: 1, code: 'A1'}; let error; await app.models.ItemNiche.create(itemNiche).catch(e => { error = e; }).finally(() => { expect(error.message).toEqual(`The warehouse can't be repeated`); }); }); });