From b3fa8697574edb4e18be1237ec79181808258bea Mon Sep 17 00:00:00 2001 From: Jon Date: Tue, 11 Jun 2024 10:00:30 +0200 Subject: [PATCH] refactor: refs #6436 second wave --- .../specs/getStarredModules.spec.js | 7 ------ .../starred-module/specs/setPosition.spec.js | 7 ------ .../specs/toggleStarredModule.spec.js | 7 ------ .../back/methods/claim/specs/filter.spec.js | 10 +------- .../claim/specs/regularizeClaim.spec.js | 14 ++--------- .../methods/claim/specs/updateClaim.spec.js | 15 ++---------- .../claim/specs/updateClaimAction.spec.js | 14 ++--------- .../agency-term/specs/createInvoiceIn.spec.js | 17 ++------------ .../back/methods/route/specs/clone.spec.js | 15 ++---------- .../methods/route/specs/guessPriority.spec.js | 23 ++++++++----------- .../route/specs/updateWorkCenter.spec.js | 14 ++--------- 11 files changed, 23 insertions(+), 120 deletions(-) diff --git a/back/methods/starred-module/specs/getStarredModules.spec.js b/back/methods/starred-module/specs/getStarredModules.spec.js index 25b4989fa..cce353f93 100644 --- a/back/methods/starred-module/specs/getStarredModules.spec.js +++ b/back/methods/starred-module/specs/getStarredModules.spec.js @@ -1,15 +1,8 @@ const {models} = require('vn-loopback/server/server'); -// const LoopBackContext = require('loopback-context'); describe('getStarredModules()', () => { const {ctx} = beforeAll; - // beforeEach(() => { - // spyOn(LoopBackContext, 'getCurrentContext').and.returnValue({ - // active: ctx - // }); - // }); - it(`should return the starred modules for a given user`, async() => { const newStarred = await models.StarredModule.create({workerFk: 9, moduleFk: 'customer', position: 1}); const starredModules = await models.StarredModule.getStarredModules(ctx); diff --git a/back/methods/starred-module/specs/setPosition.spec.js b/back/methods/starred-module/specs/setPosition.spec.js index 61b99440e..495bc8384 100644 --- a/back/methods/starred-module/specs/setPosition.spec.js +++ b/back/methods/starred-module/specs/setPosition.spec.js @@ -1,15 +1,8 @@ const {models} = require('vn-loopback/server/server'); -// const LoopBackContext = require('loopback-context'); describe('setPosition()', () => { const {ctx} = beforeAll; - // beforeEach(() => { - // spyOn(LoopBackContext, 'getCurrentContext').and.returnValue({ - // active: activeCtx - // }); - // }); - it('should increase the orders module position by replacing it with clients and vice versa', async() => { const tx = await models.StarredModule.beginTransaction({}); diff --git a/back/methods/starred-module/specs/toggleStarredModule.spec.js b/back/methods/starred-module/specs/toggleStarredModule.spec.js index 10dd0492c..d5a5c8ab3 100644 --- a/back/methods/starred-module/specs/toggleStarredModule.spec.js +++ b/back/methods/starred-module/specs/toggleStarredModule.spec.js @@ -1,15 +1,8 @@ const {models} = require('vn-loopback/server/server'); -// const LoopBackContext = require('loopback-context'); describe('toggleStarredModule()', () => { const {ctx} = beforeAll; - // beforeEach(() => { - // spyOn(LoopBackContext, 'getCurrentContext').and.returnValue({ - // active: activeCtx - // }); - // }); - it('should create a new starred module and then remove it by calling the method again with same args', async() => { const starredModule = await models.StarredModule.toggleStarredModule(ctx, 'order'); let starredModules = await models.StarredModule.getStarredModules(ctx); diff --git a/modules/claim/back/methods/claim/specs/filter.spec.js b/modules/claim/back/methods/claim/specs/filter.spec.js index 872f49aa3..b55e554b9 100644 --- a/modules/claim/back/methods/claim/specs/filter.spec.js +++ b/modules/claim/back/methods/claim/specs/filter.spec.js @@ -2,15 +2,7 @@ const app = require('vn-loopback/server/server'); const models = require('vn-loopback/server/server').models; describe('claim filter()', () => { - let ctx; - beforeEach(() => { - ctx = { - req: { - accessToken: {userId: 9}, - headers: {origin: 'http://localhost'} - } - }; - }); + const {ctx} = beforeAll; it('should return 1 result filtering by id', async() => { const tx = await app.models.Claim.beginTransaction({}); diff --git a/modules/claim/back/methods/claim/specs/regularizeClaim.spec.js b/modules/claim/back/methods/claim/specs/regularizeClaim.spec.js index 95c356374..224adc997 100644 --- a/modules/claim/back/methods/claim/specs/regularizeClaim.spec.js +++ b/modules/claim/back/methods/claim/specs/regularizeClaim.spec.js @@ -1,5 +1,5 @@ const models = require('vn-loopback/server/server').models; -const LoopBackContext = require('loopback-context'); +const {mockLoopBackContext} = require('vn-loopback/../../back/vn-jasmine'); describe('claim regularizeClaim()', () => { const userId = 18; @@ -41,17 +41,7 @@ describe('claim regularizeClaim()', () => { } beforeAll(async() => { - const activeCtx = { - accessToken: {userId: 9}, - http: { - req: { - headers: {origin: 'http://localhost'} - } - } - }; - spyOn(LoopBackContext, 'getCurrentContext').and.returnValue({ - active: activeCtx - }); + mockLoopBackContext(); }); it('should send a chat message with value "Trash" and then change claim state to resolved', async() => { diff --git a/modules/claim/back/methods/claim/specs/updateClaim.spec.js b/modules/claim/back/methods/claim/specs/updateClaim.spec.js index b7725e7f8..5c8f08132 100644 --- a/modules/claim/back/methods/claim/specs/updateClaim.spec.js +++ b/modules/claim/back/methods/claim/specs/updateClaim.spec.js @@ -1,22 +1,11 @@ const app = require('vn-loopback/server/server'); -const LoopBackContext = require('loopback-context'); +const {mockLoopBackContext} = require('vn-loopback/../../back/vn-jasmine'); const i18n = require('i18n'); describe('Update Claim', () => { let url; let claimStatesMap = {}; beforeAll(async() => { - url = await app.models.Url.getUrl(); - const activeCtx = { - accessToken: {userId: 9}, - http: { - req: { - headers: {origin: 'http://localhost'} - } - } - }; - spyOn(LoopBackContext, 'getCurrentContext').and.returnValue({ - active: activeCtx - }); + mockLoopBackContext(); const claimStates = await app.models.ClaimState.find(); claimStatesMap = claimStates.reduce((acc, state) => ({...acc, [state.code]: state.id}), {}); }); diff --git a/modules/claim/back/methods/claim/specs/updateClaimAction.spec.js b/modules/claim/back/methods/claim/specs/updateClaimAction.spec.js index 99436fed6..c939f59de 100644 --- a/modules/claim/back/methods/claim/specs/updateClaimAction.spec.js +++ b/modules/claim/back/methods/claim/specs/updateClaimAction.spec.js @@ -1,19 +1,9 @@ const app = require('vn-loopback/server/server'); -const LoopBackContext = require('loopback-context'); +const {mockLoopBackContext} = require('vn-loopback/../../back/vn-jasmine'); describe('Update Claim', () => { beforeAll(async() => { - const activeCtx = { - accessToken: {userId: 9}, - http: { - req: { - headers: {origin: 'http://localhost'} - } - } - }; - spyOn(LoopBackContext, 'getCurrentContext').and.returnValue({ - active: activeCtx - }); + mockLoopBackContext(); }); const newDate = Date.vnNew(); const original = { diff --git a/modules/route/back/methods/agency-term/specs/createInvoiceIn.spec.js b/modules/route/back/methods/agency-term/specs/createInvoiceIn.spec.js index d3a0755ef..a625605d2 100644 --- a/modules/route/back/methods/agency-term/specs/createInvoiceIn.spec.js +++ b/modules/route/back/methods/agency-term/specs/createInvoiceIn.spec.js @@ -1,21 +1,8 @@ const models = require('vn-loopback/server/server').models; -const LoopBackContext = require('loopback-context'); +// const LoopBackContext = require('loopback-context'); describe('AgencyTerm createInvoiceIn()', () => { - const ctx = {req: {accessToken: {userId: 9}}}; - beforeAll(async() => { - const activeCtx = { - accessToken: {userId: 9}, - http: { - req: { - headers: {origin: 'http://localhost'} - } - } - }; - spyOn(LoopBackContext, 'getCurrentContext').and.returnValue({ - active: activeCtx - }); - }); + const {ctx} = beforeAll; const rows = [ { routeFk: 2, diff --git a/modules/route/back/methods/route/specs/clone.spec.js b/modules/route/back/methods/route/specs/clone.spec.js index 496ae1c89..98240488c 100644 --- a/modules/route/back/methods/route/specs/clone.spec.js +++ b/modules/route/back/methods/route/specs/clone.spec.js @@ -1,20 +1,9 @@ const app = require('vn-loopback/server/server'); -const LoopBackContext = require('loopback-context'); +const {mockLoopBackContext} = require('vn-loopback/../../back/vn-jasmine'); describe('route clone()', () => { beforeAll(async() => { - const activeCtx = { - accessToken: {userId: 9}, - http: { - req: { - headers: {origin: 'http://localhost'} - } - } - }; - - spyOn(LoopBackContext, 'getCurrentContext').and.returnValue({ - active: activeCtx - }); + mockLoopBackContext(); }); const createdDate = Date.vnNew(); diff --git a/modules/route/back/methods/route/specs/guessPriority.spec.js b/modules/route/back/methods/route/specs/guessPriority.spec.js index 902647ba1..d73db6379 100644 --- a/modules/route/back/methods/route/specs/guessPriority.spec.js +++ b/modules/route/back/methods/route/specs/guessPriority.spec.js @@ -1,20 +1,17 @@ const app = require('vn-loopback/server/server'); -const LoopBackContext = require('loopback-context'); +// const LoopBackContext = require('loopback-context'); describe('route guessPriority()', () => { const targetRouteId = 7; let routeTicketsToRestore; - const activeCtx = { - accessToken: {userId: 9}, - __: () => {} - }; + const {ctx} = beforeAll; - beforeAll(() => { - spyOn(LoopBackContext, 'getCurrentContext').and.returnValue({ - active: activeCtx - }); - }); + // beforeAll(() => { + // spyOn(LoopBackContext, 'getCurrentContext').and.returnValue({ + // active: activeCtx + // }); + // }); afterAll(async() => { let restoreFixtures = []; @@ -25,9 +22,9 @@ describe('route guessPriority()', () => { }); it('should call guessPriority() then check all tickets in that route have their priorities defined', async() => { - const ctx = { - req: activeCtx - }; + // const ctx = { + // req: activeCtx + // }; routeTicketsToRestore = await app.models.Ticket.find({where: {routeFk: targetRouteId}}); await app.models.Route.guessPriority(ctx, targetRouteId); diff --git a/modules/route/back/methods/route/specs/updateWorkCenter.spec.js b/modules/route/back/methods/route/specs/updateWorkCenter.spec.js index a1c716299..315460d4a 100644 --- a/modules/route/back/methods/route/specs/updateWorkCenter.spec.js +++ b/modules/route/back/methods/route/specs/updateWorkCenter.spec.js @@ -1,19 +1,9 @@ const models = require('vn-loopback/server/server').models; -const LoopBackContext = require('loopback-context'); +const {mockLoopBackContext} = require('vn-loopback/../../back/vn-jasmine'); describe('route updateWorkCenter()', () => { beforeAll(async() => { - const activeCtx = { - accessToken: {userId: 9}, - http: { - req: { - headers: {origin: 'http://localhost'} - } - } - }; - spyOn(LoopBackContext, 'getCurrentContext').and.returnValue({ - active: activeCtx - }); + mockLoopBackContext(); }); const routeId = 1;