diff --git a/e2e/helpers/selectors.js b/e2e/helpers/selectors.js index b22b0363d..6f257774a 100644 --- a/e2e/helpers/selectors.js +++ b/e2e/helpers/selectors.js @@ -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', diff --git a/e2e/paths/10-travel/05_thermograph.spec.js b/e2e/paths/10-travel/05_thermograph.spec.js index 97077554f..a99dc8352 100644 --- a/e2e/paths/10-travel/05_thermograph.spec.js +++ b/e2e/paths/10-travel/05_thermograph.spec.js @@ -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); }); diff --git a/modules/travel/back/methods/thermograph/specs/createThermograph.spec.js b/modules/travel/back/methods/thermograph/specs/createThermograph.spec.js index a3fc98aa6..32014e303 100644 --- a/modules/travel/back/methods/thermograph/specs/createThermograph.spec.js +++ b/modules/travel/back/methods/thermograph/specs/createThermograph.spec.js @@ -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'); }); }); diff --git a/modules/travel/back/methods/travel/specs/createThermograph.spec.js b/modules/travel/back/methods/travel/specs/createThermograph.spec.js index 36221e479..742e2dc18 100644 --- a/modules/travel/back/methods/travel/specs/createThermograph.spec.js +++ b/modules/travel/back/methods/travel/specs/createThermograph.spec.js @@ -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; + } }); });