const models = require('vn-loopback/server/server').models; describe('Termograph createThermograph()', () => { const thermographId = '99999-1'; const model = 'DISPOSABLE'; const temperatureFk = 'COOL'; const warehouseId = 1; const ctx = beforeAll.getCtx(); let tx; beforeEach(async() => { tx = await models.Thermograph.beginTransaction({}); }); afterEach(async() => { await tx.rollback(); }); it(`should create a thermograph which is saved in both thermograph and travelThermograph`, async() => { const options = {transaction: tx}; const createdThermograph = await models.Thermograph.createThermograph( ctx, thermographId, model, temperatureFk, warehouseId, options); expect(createdThermograph.thermographFk).toEqual(thermographId); const createdTravelThermograph = await models.TravelThermograph.findOne({where: {thermographFk: thermographId}}, options); expect(createdTravelThermograph.warehouseFk).toEqual(warehouseId); expect(createdTravelThermograph.temperatureFk).toEqual(temperatureFk); }); it(`should throw an error when trying to create a repeated thermograph`, async() => { try { const options = {transaction: tx}; await models.Thermograph.createThermograph( ctx, thermographId, model, temperatureFk, warehouseId, options); await models.Thermograph.createThermograph( ctx, thermographId, model, temperatureFk, warehouseId, options); fail('Expected an error to be thrown when trying to create a repeated thermograph'); } catch (e) { expect(e.message).toBe('This thermograph id already exists'); } }); });