From bd45352215ef383240669ccbfc4c16a6b5cf789b Mon Sep 17 00:00:00 2001 From: Jon Date: Tue, 11 Jun 2024 12:02:15 +0200 Subject: [PATCH] refactor: refs #6436 fourth wave --- .../item/back/methods/item/specs/new.spec.js | 5 +--- .../back/methods/tag/specs/onSubmit.spec.js | 14 ++--------- .../specs/deleteExpeditions.spec.js | 13 ++--------- .../expedition/specs/moveExpeditions.spec.js | 14 ++--------- .../back/methods/sale/specs/canEdit.spec.js | 14 ++--------- .../methods/sale/specs/deleteSales.spec.js | 14 ++--------- .../back/methods/sale/specs/reserve.spec.js | 14 ++--------- .../methods/sale/specs/updateConcept.spec.js | 14 ++--------- .../ticket-request/specs/confirm.spec.js | 23 ++----------------- .../ticket/specs/componentUpdate.spec.js | 14 ++--------- .../back/methods/ticket/specs/merge.spec.js | 14 ++--------- .../ticket/specs/updateDiscount.spec.js | 14 ++--------- .../models/specs/ticket-packaging.spec.js | 14 ++--------- 13 files changed, 25 insertions(+), 156 deletions(-) diff --git a/modules/item/back/methods/item/specs/new.spec.js b/modules/item/back/methods/item/specs/new.spec.js index 7a3612ebc..5611b28ab 100644 --- a/modules/item/back/methods/item/specs/new.spec.js +++ b/modules/item/back/methods/item/specs/new.spec.js @@ -1,10 +1,7 @@ const models = require('vn-loopback/server/server').models; -const {mockLoopBackContext} = require('vn-loopback/../../back/vn-jasmine'); describe('item new()', () => { - beforeAll(async() => { - mockLoopBackContext(); - }); + const {ctx} = beforeAll; it('should create a new item, adding the name as a tag', async() => { const tx = await models.Item.beginTransaction({}); diff --git a/modules/item/back/methods/tag/specs/onSubmit.spec.js b/modules/item/back/methods/tag/specs/onSubmit.spec.js index 1e96d9e81..1830aafcf 100644 --- a/modules/item/back/methods/tag/specs/onSubmit.spec.js +++ b/modules/item/back/methods/tag/specs/onSubmit.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('tag onSubmit()', () => { beforeAll(async() => { - const activeCtx = { - accessToken: {userId: 9}, - http: { - req: { - headers: {origin: 'http://localhost'} - } - } - }; - spyOn(LoopBackContext, 'getCurrentContext').and.returnValue({ - active: activeCtx - }); + mockLoopBackContext(); }); it('should delete a tag', async() => { diff --git a/modules/ticket/back/methods/expedition/specs/deleteExpeditions.spec.js b/modules/ticket/back/methods/expedition/specs/deleteExpeditions.spec.js index bf8bafe34..2c34c994b 100644 --- a/modules/ticket/back/methods/expedition/specs/deleteExpeditions.spec.js +++ b/modules/ticket/back/methods/expedition/specs/deleteExpeditions.spec.js @@ -1,18 +1,9 @@ const models = require('vn-loopback/server/server').models; -const LoopBackContext = require('loopback-context'); +const {mockLoopBackContext} = require('vn-loopback/../../back/vn-jasmine'); describe('ticket deleteExpeditions()', () => { - let ctx; beforeAll(async() => { - ctx = { - accessToken: {userId: 9}, - req: { - headers: {origin: 'http://localhost'} - } - }; - spyOn(LoopBackContext, 'getCurrentContext').and.returnValue({ - active: ctx - }); + mockLoopBackContext(); }); it('should delete the selected expeditions', async() => { diff --git a/modules/ticket/back/methods/expedition/specs/moveExpeditions.spec.js b/modules/ticket/back/methods/expedition/specs/moveExpeditions.spec.js index 5f211543e..27b20bcd2 100644 --- a/modules/ticket/back/methods/expedition/specs/moveExpeditions.spec.js +++ b/modules/ticket/back/methods/expedition/specs/moveExpeditions.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('ticket moveExpeditions()', () => { beforeAll(async() => { - const activeCtx = { - accessToken: {userId: 9}, - http: { - req: { - headers: {origin: 'http://localhost'} - } - } - }; - spyOn(LoopBackContext, 'getCurrentContext').and.returnValue({ - active: activeCtx - }); + mockLoopBackContext(); }); it('should move the selected expeditions to new ticket', async() => { diff --git a/modules/ticket/back/methods/sale/specs/canEdit.spec.js b/modules/ticket/back/methods/sale/specs/canEdit.spec.js index 200ea24cc..3185b01e7 100644 --- a/modules/ticket/back/methods/sale/specs/canEdit.spec.js +++ b/modules/ticket/back/methods/sale/specs/canEdit.spec.js @@ -1,20 +1,10 @@ const models = require('vn-loopback/server/server').models; -const LoopBackContext = require('loopback-context'); +const {mockLoopBackContext} = require('vn-loopback/../../back/vn-jasmine'); describe('sale canEdit()', () => { const employeeId = 1; beforeAll(async() => { - const activeCtx = { - accessToken: {userId: 9}, - http: { - req: { - headers: {origin: 'http://localhost'} - } - } - }; - spyOn(LoopBackContext, 'getCurrentContext').and.returnValue({ - active: activeCtx - }); + mockLoopBackContext(); }); describe('sale not exists', () => { diff --git a/modules/ticket/back/methods/sale/specs/deleteSales.spec.js b/modules/ticket/back/methods/sale/specs/deleteSales.spec.js index 3d3e06e22..8d0e4bd4e 100644 --- a/modules/ticket/back/methods/sale/specs/deleteSales.spec.js +++ b/modules/ticket/back/methods/sale/specs/deleteSales.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('sale deleteSales()', () => { beforeAll(async() => { - const activeCtx = { - accessToken: {userId: 9}, - http: { - req: { - headers: {origin: 'http://localhost'} - } - } - }; - spyOn(LoopBackContext, 'getCurrentContext').and.returnValue({ - active: activeCtx - }); + mockLoopBackContext(); }); it('should throw an error if the ticket of the given sales is not editable', async() => { diff --git a/modules/ticket/back/methods/sale/specs/reserve.spec.js b/modules/ticket/back/methods/sale/specs/reserve.spec.js index 7ba5999b3..37ebf10ab 100644 --- a/modules/ticket/back/methods/sale/specs/reserve.spec.js +++ b/modules/ticket/back/methods/sale/specs/reserve.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('sale reserve()', () => { const ctx = { @@ -11,17 +11,7 @@ describe('sale reserve()', () => { }; beforeAll(async() => { - const activeCtx = { - accessToken: {userId: 9}, - http: { - req: { - headers: {origin: 'http://localhost'} - } - } - }; - spyOn(LoopBackContext, 'getCurrentContext').and.returnValue({ - active: activeCtx - }); + mockLoopBackContext(); }); it('should throw an error if the ticket can not be modified', async() => { diff --git a/modules/ticket/back/methods/sale/specs/updateConcept.spec.js b/modules/ticket/back/methods/sale/specs/updateConcept.spec.js index 1b42e7140..0610e9eab 100644 --- a/modules/ticket/back/methods/sale/specs/updateConcept.spec.js +++ b/modules/ticket/back/methods/sale/specs/updateConcept.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('sale updateConcept()', () => { beforeAll(async() => { - const activeCtx = { - accessToken: {userId: 9}, - http: { - req: { - headers: {origin: 'http://localhost'} - } - } - }; - spyOn(LoopBackContext, 'getCurrentContext').and.returnValue({ - active: activeCtx - }); + mockLoopBackContext(); }); const ctx = {req: {accessToken: {userId: 9}}}; diff --git a/modules/ticket/back/methods/ticket-request/specs/confirm.spec.js b/modules/ticket/back/methods/ticket-request/specs/confirm.spec.js index 668a991f4..8a1130e7d 100644 --- a/modules/ticket/back/methods/ticket-request/specs/confirm.spec.js +++ b/modules/ticket/back/methods/ticket-request/specs/confirm.spec.js @@ -1,29 +1,10 @@ const models = require('vn-loopback/server/server').models; -const LoopBackContext = require('loopback-context'); +const {mockLoopBackContext} = require('vn-loopback/../../back/vn-jasmine'); describe('ticket-request confirm()', () => { beforeAll(async() => { - const activeCtx = { - accessToken: {userId: 9}, - http: { - req: { - headers: {origin: 'http://localhost'} - } - } - }; - spyOn(LoopBackContext, 'getCurrentContext').and.returnValue({ - active: activeCtx - }); + mockLoopBackContext(); }); - let ctx = { - req: { - accessToken: {userId: 9}, - headers: {origin: 'http://localhost'} - } - }; - ctx.req.__ = value => { - return value; - }; it(`should throw an error if the item doesn't exist`, async() => { const tx = await models.TicketRequest.beginTransaction({}); diff --git a/modules/ticket/back/methods/ticket/specs/componentUpdate.spec.js b/modules/ticket/back/methods/ticket/specs/componentUpdate.spec.js index 8abb1a4a1..b138b88ea 100644 --- a/modules/ticket/back/methods/ticket/specs/componentUpdate.spec.js +++ b/modules/ticket/back/methods/ticket/specs/componentUpdate.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('ticket componentUpdate()', () => { const userID = 1101; @@ -17,17 +17,7 @@ describe('ticket componentUpdate()', () => { let componentValue; beforeAll(async() => { - const activeCtx = { - accessToken: {userId: 9}, - http: { - req: { - headers: {origin: 'http://localhost'} - } - } - }; - spyOn(LoopBackContext, 'getCurrentContext').and.returnValue({ - active: activeCtx - }); + mockLoopBackContext(); const deliveryComponenet = await models.Component.findOne({where: {code: 'delivery'}}); deliveryComponentId = deliveryComponenet.id; componentOfSaleSeven = `SELECT value diff --git a/modules/ticket/back/methods/ticket/specs/merge.spec.js b/modules/ticket/back/methods/ticket/specs/merge.spec.js index 646b9739f..702b496af 100644 --- a/modules/ticket/back/methods/ticket/specs/merge.spec.js +++ b/modules/ticket/back/methods/ticket/specs/merge.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('ticket merge()', () => { const tickets = { @@ -11,17 +11,7 @@ describe('ticket merge()', () => { }; beforeAll(async() => { - const activeCtx = { - accessToken: {userId: 9}, - http: { - req: { - headers: {origin: 'http://localhost'} - } - } - }; - spyOn(LoopBackContext, 'getCurrentContext').and.returnValue({ - active: activeCtx - }); + mockLoopBackContext(); }); const ctx = { diff --git a/modules/ticket/back/methods/ticket/specs/updateDiscount.spec.js b/modules/ticket/back/methods/ticket/specs/updateDiscount.spec.js index 41de1fd6e..c0c5333ba 100644 --- a/modules/ticket/back/methods/ticket/specs/updateDiscount.spec.js +++ b/modules/ticket/back/methods/ticket/specs/updateDiscount.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('sale updateDiscount()', () => { beforeAll(async() => { - const activeCtx = { - accessToken: {userId: 9}, - http: { - req: { - headers: {origin: 'http://localhost'} - } - } - }; - spyOn(LoopBackContext, 'getCurrentContext').and.returnValue({ - active: activeCtx - }); + mockLoopBackContext(); }); const originalSaleId = 8; diff --git a/modules/ticket/back/models/specs/ticket-packaging.spec.js b/modules/ticket/back/models/specs/ticket-packaging.spec.js index 6d59456a3..97a936018 100644 --- a/modules/ticket/back/models/specs/ticket-packaging.spec.js +++ b/modules/ticket/back/models/specs/ticket-packaging.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('ticket model TicketTracking', () => { beforeAll(async() => { - const activeCtx = { - accessToken: {userId: 9}, - http: { - req: { - headers: {origin: 'http://localhost'} - } - } - }; - spyOn(LoopBackContext, 'getCurrentContext').and.returnValue({ - active: activeCtx - }); + mockLoopBackContext(); }); let ticketTrackingId;