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"]', newThermographId: 'vn-textfield[ng-model="$ctrl.newThermograph.thermographId"]',
newThermographModel: 'vn-autocomplete[ng-model="$ctrl.newThermograph.model"]', newThermographModel: 'vn-autocomplete[ng-model="$ctrl.newThermograph.model"]',
newThermographWarehouse: 'vn-autocomplete[ng-model="$ctrl.newThermograph.warehouseId"]', 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"]', createThermographButton: 'form button[response="accept"]',
uploadIcon: 'vn-travel-thermograph-create vn-icon[icon="icon-attach"]', uploadIcon: 'vn-travel-thermograph-create vn-icon[icon="icon-attach"]',
createdThermograph: 'vn-travel-thermograph-index vn-tbody > vn-tr', 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.write(selectors.travelThermograph.newThermographId, thermographName);
await page.autocompleteSearch(selectors.travelThermograph.newThermographModel, 'TEMPMATE'); await page.autocompleteSearch(selectors.travelThermograph.newThermographModel, 'TEMPMATE');
await page.autocompleteSearch(selectors.travelThermograph.newThermographWarehouse, 'Warehouse Two'); 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); 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()', () => { describe('Termograph createThermograph()', () => {
const models = app.models;
const thermographId = '99999-1'; const thermographId = '99999-1';
const model = 'DISPOSABLE'; const model = 'DISPOSABLE';
const temperature = 'COOL'; const temperatureFk = 'COOL';
const warehouseId = 1; const warehouseId = 1;
let createdThermograph;
afterAll(async done => { it(`should create a thermograph which is saved in both thermograph and travelThermograph`, async() => {
let travelThermograpToDelete = await models.TravelThermograph.findOne({where: {thermographFk: createdThermograph.id}}); const tx = await models.Thermograph.beginTransaction({});
let thermograpToDelete = await models.Thermograph.findById(createdThermograph.id);
await travelThermograpToDelete.destroy(); try {
await thermograpToDelete.destroy(); 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() => { it(`should throw an error when trying to created repeated thermograph`, async() => {
let createdTravelThermograpth = await models.TravelThermograph.findOne({where: {thermographFk: thermographId}}); const tx = await models.Thermograph.beginTransaction({});
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; let error;
try { 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) { } catch (e) {
await tx.rollback();
error = e; error = e;
} }
expect(error).toBeDefined();
expect(error.message).toBe('This thermograph id already exists'); 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()', () => { describe('Travel createThermograph()', () => {
const models = app.models;
const travelId = 3; const travelId = 3;
const currentUserId = 1102; const currentUserId = 1102;
const thermographId = '138350-0'; const thermographId = '138350-0';
const ctx = {req: {accessToken: {userId: currentUserId}}, args: {dmsTypeId: 1}}; 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() => { 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({ try {
where: { const options = {transaction: tx};
thermographFk: thermographId,
travelFk: null
}
});
await models.Travel.createThermograph(ctx, travelId, thermographId); spyOn(models.Dms, 'uploadFile').and.returnValue([{id: 5}]);
const travelThermographAfter = await models.TravelThermograph.findOne({ travelThermographBefore = await models.TravelThermograph.findOne({
where: { where: {
thermographFk: thermographId, thermographFk: thermographId,
travelFk: travelId travelFk: null
} }
}); }, options);
expect(app.models.Dms.uploadFile).toHaveBeenCalledWith(ctx, jasmine.any(Object)); await models.Travel.createThermograph(ctx, travelId, thermographId, options);
expect(travelThermographBefore).toBeDefined(); const travelThermographAfter = await models.TravelThermograph.findOne({
expect(travelThermographBefore.thermographFk).toEqual(thermographId); where: {
expect(travelThermographBefore.travelFk).toBeNull(); thermographFk: thermographId,
expect(travelThermographAfter).toBeDefined(); travelFk: travelId
}
}, options);
expect(travelThermographAfter.thermographFk).toEqual(thermographId); expect(models.Dms.uploadFile).toHaveBeenCalledWith(ctx, jasmine.any(Object));
expect(travelThermographAfter.travelFk).toEqual(travelId);
expect(travelThermographAfter.dmsFk).toEqual(5); 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;
}
}); });
}); });