const app = require('vn-loopback/server/server'); describe('Termograph createThermograph()', () => { const models = app.models; const thermographId = '99999-1'; const model = 'DISPOSABLE'; const temperature = 'COOL'; const warehouseId = 1; let createdThermograph; afterAll(async done => { let travelThermograpToDelete = await models.TravelThermograph.findOne({where: {thermographFk: createdThermograph.id}}); let thermograpToDelete = await models.Thermograph.findById(createdThermograph.id); await travelThermograpToDelete.destroy(); await thermograpToDelete.destroy(); done(); }); it(`should be able to create just once a thermograph which is saved in both thermograph and travelThermograph`, async() => { let createdTravelThermograpth = await models.TravelThermograph.findOne({where: {thermographFk: thermographId}}); expect(createdTravelThermograpth).toBeNull(); createdThermograph = await models.Thermograph.createThermograph(thermographId, model, temperature, warehouseId); expect(createdThermograph.id).toEqual(thermographId); expect(createdThermograph.model).toEqual(model); createdTravelThermograpth = await models.TravelThermograph.findOne({where: {thermographFk: thermographId}}); expect(createdTravelThermograpth.warehouseFk).toEqual(warehouseId); expect(createdTravelThermograpth.temperature).toEqual(temperature); let error; try { await models.Thermograph.createThermograph(thermographId, model, temperature, warehouseId); } catch (e) { error = e; } expect(error).toBeDefined(); expect(error.message).toBe('This thermograph id already exists'); }); });