diff --git a/modules/route/back/methods/route/specs/updateWorkCenter.spec.js b/modules/route/back/methods/route/specs/updateWorkCenter.spec.js new file mode 100644 index 000000000..a7d0f0caa --- /dev/null +++ b/modules/route/back/methods/route/specs/updateWorkCenter.spec.js @@ -0,0 +1,51 @@ +const models = require('vn-loopback/server/server').models; + +describe('route updateWorkCenter()', () => { + const routeId = 1; + + it('should update the commissionWorkCenterFk from workerLabour.workCenterFK', async() => { + const tx = await models.Defaulter.beginTransaction({}); + try { + const developerId = 9; + const ctx = { + req: { + accessToken: {userId: developerId} + } + }; + const options = {transaction: tx}; + + const expectedResult = 1; + const updatedRoute = await models.Route.updateWorkCenter(ctx, routeId, options); + + expect(updatedRoute.commissionWorkCenterFk).toEqual(expectedResult); + + await tx.rollback(); + } catch (e) { + await tx.rollback(); + throw e; + } + }); + + it('should update the commissionWorkCenterFk from defaultWorkCenterFk if workerLabour.workCenterFK is null', async() => { + const tx = await models.Defaulter.beginTransaction({}); + try { + const noExistentId = 2; + const ctx = { + req: { + accessToken: {userId: noExistentId} + } + }; + const options = {transaction: tx}; + + const expectedResult = 9; + const updatedRoute = await models.Route.updateWorkCenter(ctx, routeId, options); + + expect(updatedRoute.commissionWorkCenterFk).toEqual(expectedResult); + + await tx.rollback(); + } catch (e) { + await tx.rollback(); + throw e; + } + }); +});