From 979ee1d9568767f2069fb9164eb1af3b336937e1 Mon Sep 17 00:00:00 2001 From: vicent Date: Tue, 5 Jul 2022 10:19:22 +0200 Subject: [PATCH] feat: add backTest --- .../route/specs/updateWorkCenter.spec.js | 51 +++++++++++++++++++ 1 file changed, 51 insertions(+) create mode 100644 modules/route/back/methods/route/specs/updateWorkCenter.spec.js 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 0000000000..a7d0f0caa6 --- /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; + } + }); +});