2021-09-06 14:39:04 +00:00
|
|
|
const models = require('vn-loopback/server/server').models;
|
2020-05-27 11:11:41 +00:00
|
|
|
|
|
|
|
describe('Termograph createThermograph()', () => {
|
|
|
|
const thermographId = '99999-1';
|
|
|
|
const model = 'DISPOSABLE';
|
2021-09-06 14:39:04 +00:00
|
|
|
const temperatureFk = 'COOL';
|
2020-05-27 11:11:41 +00:00
|
|
|
const warehouseId = 1;
|
|
|
|
|
2021-09-06 14:39:04 +00:00
|
|
|
it(`should create a thermograph which is saved in both thermograph and travelThermograph`, async() => {
|
|
|
|
const tx = await models.Thermograph.beginTransaction({});
|
2020-05-27 11:11:41 +00:00
|
|
|
|
2021-09-06 14:39:04 +00:00
|
|
|
try {
|
|
|
|
const options = {transaction: tx};
|
2020-05-27 11:11:41 +00:00
|
|
|
|
2021-09-06 14:39:04 +00:00
|
|
|
const createdThermograph = await models.Thermograph.createThermograph(thermographId, model, temperatureFk, warehouseId, options);
|
2020-05-27 11:11:41 +00:00
|
|
|
|
2021-09-06 14:39:04 +00:00
|
|
|
expect(createdThermograph.id).toEqual(thermographId);
|
|
|
|
expect(createdThermograph.model).toEqual(model);
|
2020-05-27 11:11:41 +00:00
|
|
|
|
2021-09-06 14:39:04 +00:00
|
|
|
const createdTravelThermograpth = await models.TravelThermograph.findOne({where: {thermographFk: thermographId}}, options);
|
2020-05-27 11:11:41 +00:00
|
|
|
|
2021-09-06 14:39:04 +00:00
|
|
|
expect(createdTravelThermograpth.warehouseFk).toEqual(warehouseId);
|
|
|
|
expect(createdTravelThermograpth.temperatureFk).toEqual(temperatureFk);
|
2020-05-27 11:11:41 +00:00
|
|
|
|
2021-09-06 14:39:04 +00:00
|
|
|
await tx.rollback();
|
|
|
|
} catch (e) {
|
|
|
|
await tx.rollback();
|
|
|
|
throw e;
|
|
|
|
}
|
|
|
|
});
|
2020-05-27 11:11:41 +00:00
|
|
|
|
2021-09-06 14:39:04 +00:00
|
|
|
it(`should throw an error when trying to created repeated thermograph`, async() => {
|
|
|
|
const tx = await models.Thermograph.beginTransaction({});
|
2020-05-27 11:11:41 +00:00
|
|
|
|
|
|
|
let error;
|
|
|
|
|
|
|
|
try {
|
2021-09-06 14:39:04 +00:00
|
|
|
const options = {transaction: tx};
|
|
|
|
|
|
|
|
await models.Thermograph.createThermograph(thermographId, model, temperatureFk, warehouseId, options);
|
|
|
|
await models.Thermograph.createThermograph(thermographId, model, temperatureFk, warehouseId, options);
|
|
|
|
|
|
|
|
await tx.rollback();
|
2020-05-27 11:11:41 +00:00
|
|
|
} catch (e) {
|
2021-09-06 14:39:04 +00:00
|
|
|
await tx.rollback();
|
2020-05-27 11:11:41 +00:00
|
|
|
error = e;
|
|
|
|
}
|
|
|
|
|
|
|
|
expect(error.message).toBe('This thermograph id already exists');
|
|
|
|
});
|
|
|
|
});
|