test(thermograph): e2e and unit tests for the backend of thermograph

This commit is contained in:
Carlos Jimenez Ruiz 2021-09-06 16:39:04 +02:00
parent 1f0bcb63f1
commit 56276783db
4 changed files with 66 additions and 62 deletions

View File

@ -1005,7 +1005,7 @@ export default {
newThermographId: 'vn-textfield[ng-model="$ctrl.newThermograph.thermographId"]',
newThermographModel: 'vn-autocomplete[ng-model="$ctrl.newThermograph.model"]',
newThermographWarehouse: 'vn-autocomplete[ng-model="$ctrl.newThermograph.warehouseId"]',
newThermographTemperature: 'vn-autocomplete[ng-model="$ctrl.newThermograph.temperature"]',
newThermographTemperature: 'vn-autocomplete[ng-model="$ctrl.newThermograph.temperatureFk"]',
createThermographButton: 'form button[response="accept"]',
uploadIcon: 'vn-travel-thermograph-create vn-icon[icon="icon-attach"]',
createdThermograph: 'vn-travel-thermograph-index vn-tbody > vn-tr',

View File

@ -32,7 +32,7 @@ describe('Travel thermograph path', () => {
await page.write(selectors.travelThermograph.newThermographId, thermographName);
await page.autocompleteSearch(selectors.travelThermograph.newThermographModel, 'TEMPMATE');
await page.autocompleteSearch(selectors.travelThermograph.newThermographWarehouse, 'Warehouse Two');
await page.autocompleteSearch(selectors.travelThermograph.newThermographTemperature, 'WARM');
await page.autocompleteSearch(selectors.travelThermograph.newThermographTemperature, 'Warm');
await page.waitToClick(selectors.travelThermograph.createThermographButton);
});

View File

@ -1,47 +1,51 @@
const app = require('vn-loopback/server/server');
const models = require('vn-loopback/server/server').models;
describe('Termograph createThermograph()', () => {
const models = app.models;
const thermographId = '99999-1';
const model = 'DISPOSABLE';
const temperature = 'COOL';
const temperatureFk = '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);
it(`should create a thermograph which is saved in both thermograph and travelThermograph`, async() => {
const tx = await models.Thermograph.beginTransaction({});
await travelThermograpToDelete.destroy();
await thermograpToDelete.destroy();
try {
const options = {transaction: tx};
done();
const createdThermograph = await models.Thermograph.createThermograph(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 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);
it(`should throw an error when trying to created repeated thermograph`, async() => {
const tx = await models.Thermograph.beginTransaction({});
let error;
try {
await models.Thermograph.createThermograph(thermographId, model, temperature, warehouseId);
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();
} catch (e) {
await tx.rollback();
error = e;
}
expect(error).toBeDefined();
expect(error.message).toBe('This thermograph id already exists');
});
});

View File

@ -1,50 +1,50 @@
const app = require('vn-loopback/server/server');
const models = require('vn-loopback/server/server').models;
describe('Travel createThermograph()', () => {
const models = app.models;
const travelId = 3;
const currentUserId = 1102;
const thermographId = '138350-0';
const ctx = {req: {accessToken: {userId: currentUserId}}, args: {dmsTypeId: 1}};
let travelThermographBefore;
afterAll(async done => {
await app.models.TravelThermograph.rawSql(`
UPDATE travelThermograph
SET travelFk = NULL, dmsFk = NULL
WHERE id = ?`, [travelThermographBefore.id]);
done();
});
it(`should set the travelFk and dmsFk properties to the travel thermograph`, async() => {
spyOn(app.models.Dms, 'uploadFile').and.returnValue([{id: 5}]);
const tx = await models.Travel.beginTransaction({});
travelThermographBefore = await models.TravelThermograph.findOne({
where: {
thermographFk: thermographId,
travelFk: null
}
});
try {
const options = {transaction: tx};
await models.Travel.createThermograph(ctx, travelId, thermographId);
spyOn(models.Dms, 'uploadFile').and.returnValue([{id: 5}]);
const travelThermographAfter = await models.TravelThermograph.findOne({
where: {
thermographFk: thermographId,
travelFk: travelId
}
});
travelThermographBefore = await models.TravelThermograph.findOne({
where: {
thermographFk: thermographId,
travelFk: null
}
}, options);
expect(app.models.Dms.uploadFile).toHaveBeenCalledWith(ctx, jasmine.any(Object));
await models.Travel.createThermograph(ctx, travelId, thermographId, options);
expect(travelThermographBefore).toBeDefined();
expect(travelThermographBefore.thermographFk).toEqual(thermographId);
expect(travelThermographBefore.travelFk).toBeNull();
expect(travelThermographAfter).toBeDefined();
const travelThermographAfter = await models.TravelThermograph.findOne({
where: {
thermographFk: thermographId,
travelFk: travelId
}
}, options);
expect(travelThermographAfter.thermographFk).toEqual(thermographId);
expect(travelThermographAfter.travelFk).toEqual(travelId);
expect(travelThermographAfter.dmsFk).toEqual(5);
expect(models.Dms.uploadFile).toHaveBeenCalledWith(ctx, jasmine.any(Object));
expect(travelThermographBefore).toBeDefined();
expect(travelThermographBefore.thermographFk).toEqual(thermographId);
expect(travelThermographBefore.travelFk).toBeNull();
expect(travelThermographAfter).toBeDefined();
expect(travelThermographAfter.thermographFk).toEqual(thermographId);
expect(travelThermographAfter.travelFk).toEqual(travelId);
expect(travelThermographAfter.dmsFk).toEqual(5);
await tx.rollback();
} catch (e) {
await tx.rollback();
throw e;
}
});
});