50 lines
1.8 KiB
JavaScript
50 lines
1.8 KiB
JavaScript
|
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 create 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);
|
||
|
});
|
||
|
|
||
|
it(`should not be able to created duplicated entries`, async() => {
|
||
|
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');
|
||
|
});
|
||
|
});
|