salix/modules/travel/back/methods/thermograph/specs/createThermograph.spec.js

53 lines
1.9 KiB
JavaScript
Raw Normal View History

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