From 3a6d4753dbf9ebb2484416049cfc3b56b66a7cc9 Mon Sep 17 00:00:00 2001 From: robert Date: Thu, 15 Feb 2024 12:48:17 +0100 Subject: [PATCH 01/61] feat: refs #5855 drop temporary table --- db/routines/bi/procedures/claim_ratio_routine.sql | 2 ++ .../cache/procedures/availableNoRaids_refresh.sql | 2 +- db/routines/cache/procedures/available_refresh.sql | 2 +- .../edi/procedures/floramondo_offerRefresh.sql | 11 ++++++----- db/routines/hedera/procedures/item_calcCatalog.sql | 3 ++- .../vn/procedures/copyComponentsFromSaleList.sql | 1 + db/routines/vn/procedures/itemShelvingRadar.sql | 2 +- db/routines/vn/procedures/itemShelving_inventory.sql | 2 ++ db/routines/vn/procedures/item_getMinacum.sql | 2 ++ db/routines/vn/procedures/productionSectorList.sql | 1 + db/routines/vn/procedures/ticket_DelayTruck.sql | 1 + db/routines/vn/procedures/ticket_add.sql | 2 ++ db/routines/vn/procedures/ticket_cloneWeekly.sql | 2 +- db/routines/vn/procedures/zone_getCollisions.sql | 3 ++- 14 files changed, 25 insertions(+), 11 deletions(-) diff --git a/db/routines/bi/procedures/claim_ratio_routine.sql b/db/routines/bi/procedures/claim_ratio_routine.sql index 10cb717cf..4ad028433 100644 --- a/db/routines/bi/procedures/claim_ratio_routine.sql +++ b/db/routines/bi/procedures/claim_ratio_routine.sql @@ -164,5 +164,7 @@ BEGIN ) sub SET cr.recobro = sub.recobro WHERE Id_Cliente IN ( 5189,8942); + + DROP TEMPORARY TABLE tmp.ticket_list; END$$ DELIMITER ; diff --git a/db/routines/cache/procedures/availableNoRaids_refresh.sql b/db/routines/cache/procedures/availableNoRaids_refresh.sql index 383e35436..37715d270 100644 --- a/db/routines/cache/procedures/availableNoRaids_refresh.sql +++ b/db/routines/cache/procedures/availableNoRaids_refresh.sql @@ -117,7 +117,7 @@ proc: BEGIN )sub GROUP BY sub.itemFk; - DROP TEMPORARY TABLE tmp.itemCalc, tItemRange; + DROP TEMPORARY TABLE tmp.itemCalc, tItemRange, tmp.itemList; CALL cache_calc_end (vCalc); END$$ DELIMITER ; diff --git a/db/routines/cache/procedures/available_refresh.sql b/db/routines/cache/procedures/available_refresh.sql index d0939e568..abf023a41 100644 --- a/db/routines/cache/procedures/available_refresh.sql +++ b/db/routines/cache/procedures/available_refresh.sql @@ -121,7 +121,7 @@ proc: BEGIN )sub GROUP BY sub.itemFk; - DROP TEMPORARY TABLE tmp.itemCalc, itemRange; + DROP TEMPORARY TABLE tmp.itemCalc, itemRange, tmp.itemList; CALL cache_calc_end (vCalc); END$$ DELIMITER ; diff --git a/db/routines/edi/procedures/floramondo_offerRefresh.sql b/db/routines/edi/procedures/floramondo_offerRefresh.sql index 26e09ebaf..6fdd1b3bb 100644 --- a/db/routines/edi/procedures/floramondo_offerRefresh.sql +++ b/db/routines/edi/procedures/floramondo_offerRefresh.sql @@ -1,5 +1,5 @@ -DELIMITER $$ -CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `edi`.`floramondo_offerRefresh`() +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `edi`.`floramondo_offerRefresh`() proc: BEGIN DECLARE vLanded DATETIME; DECLARE vDone INT DEFAULT FALSE; @@ -484,7 +484,8 @@ proc: BEGIN DROP TEMPORARY TABLE edi.offer, - itemToInsert; + itemToInsert, + tmp.buyRecalc; SET @isTriggerDisabled = FALSE; @@ -518,5 +519,5 @@ proc: BEGIN fieldValue = TIMEDIFF(util.VN_NOW(), vStartingTime); DO RELEASE_LOCK('edi.floramondo_offerRefresh'); -END$$ -DELIMITER ; +END$$ +DELIMITER ; diff --git a/db/routines/hedera/procedures/item_calcCatalog.sql b/db/routines/hedera/procedures/item_calcCatalog.sql index 81b3adf5a..6db11c034 100644 --- a/db/routines/hedera/procedures/item_calcCatalog.sql +++ b/db/routines/hedera/procedures/item_calcCatalog.sql @@ -30,6 +30,7 @@ BEGIN tmp.ticketComponentPrice, tmp.ticketComponent, tmp.ticketLot, - tmp.zoneGetShipped; + tmp.zoneGetShipped, + tmp.item; END$$ DELIMITER ; diff --git a/db/routines/vn/procedures/copyComponentsFromSaleList.sql b/db/routines/vn/procedures/copyComponentsFromSaleList.sql index 17cf487b1..13487af17 100644 --- a/db/routines/vn/procedures/copyComponentsFromSaleList.sql +++ b/db/routines/vn/procedures/copyComponentsFromSaleList.sql @@ -30,5 +30,6 @@ BEGIN JOIN tmp.saleList s ON s.saleFk = sc.saleFk JOIN tmp.newSaleList ns ON ns.orden = s.orden; + DROP TEMPORARY TABLE IF EXISTS tmp.newSaleList; END$$ DELIMITER ; diff --git a/db/routines/vn/procedures/itemShelvingRadar.sql b/db/routines/vn/procedures/itemShelvingRadar.sql index c89a190ae..db56c07a0 100644 --- a/db/routines/vn/procedures/itemShelvingRadar.sql +++ b/db/routines/vn/procedures/itemShelvingRadar.sql @@ -188,7 +188,7 @@ proc:BEGIN SELECT * FROM tmp.itemShelvingRadar; END IF; - DROP TEMPORARY TABLE tmp.itemShelvingRadar; + DROP TEMPORARY TABLE tmp.itemShelvingRadar, tmp.itemOutTime; END$$ DELIMITER ; diff --git a/db/routines/vn/procedures/itemShelving_inventory.sql b/db/routines/vn/procedures/itemShelving_inventory.sql index ce2934426..89adc0be4 100644 --- a/db/routines/vn/procedures/itemShelving_inventory.sql +++ b/db/routines/vn/procedures/itemShelving_inventory.sql @@ -58,5 +58,7 @@ BEGIN WHERE p.pickingOrder BETWEEN vPickingOrderFrom AND vPickingOrderTo AND p.sectorFk = vSectorFk ORDER BY p.pickingOrder; + + DROP TEMPORARY TABLE IF EXISTS tmp.stockMisfit; END$$ DELIMITER ; diff --git a/db/routines/vn/procedures/item_getMinacum.sql b/db/routines/vn/procedures/item_getMinacum.sql index ed987637c..ddf2ae2c6 100644 --- a/db/routines/vn/procedures/item_getMinacum.sql +++ b/db/routines/vn/procedures/item_getMinacum.sql @@ -75,5 +75,7 @@ BEGIN i.quantity amount FROM tmp.itemAtp i HAVING amount != 0; + + DROP TEMPORARY TABLE tmp.itemAtp; END$$ DELIMITER ; diff --git a/db/routines/vn/procedures/productionSectorList.sql b/db/routines/vn/procedures/productionSectorList.sql index 5447f10d0..e1445ca52 100644 --- a/db/routines/vn/procedures/productionSectorList.sql +++ b/db/routines/vn/procedures/productionSectorList.sql @@ -104,5 +104,6 @@ BEGIN ) sub; DROP TEMPORARY TABLE tmp.whiteTicket; DROP TEMPORARY TABLE tmp.sectorTypeTicket; + DROP TEMPORARY TABLE tmp.productionBuffer; END$$ DELIMITER ; diff --git a/db/routines/vn/procedures/ticket_DelayTruck.sql b/db/routines/vn/procedures/ticket_DelayTruck.sql index 7a3170d68..20006fa65 100644 --- a/db/routines/vn/procedures/ticket_DelayTruck.sql +++ b/db/routines/vn/procedures/ticket_DelayTruck.sql @@ -30,5 +30,6 @@ BEGIN END LOOP; CLOSE cur1; + DROP TEMPORARY TABLE tmp.ticket, tmp.productionBuffer; END$$ DELIMITER ; diff --git a/db/routines/vn/procedures/ticket_add.sql b/db/routines/vn/procedures/ticket_add.sql index 5c3c28081..c85000218 100644 --- a/db/routines/vn/procedures/ticket_add.sql +++ b/db/routines/vn/procedures/ticket_add.sql @@ -65,6 +65,8 @@ BEGIN IF (vZoneFk IS NULL OR vZoneFk = 0) AND vIsRequiredZone THEN CALL util.throw ('NOT_ZONE_WITH_THIS_PARAMETERS'); END IF; + + DROP TEMPORARY TABLE IF EXISTS tmp.zoneGetShipped; END IF; INSERT INTO ticket ( diff --git a/db/routines/vn/procedures/ticket_cloneWeekly.sql b/db/routines/vn/procedures/ticket_cloneWeekly.sql index 6bceb2fdf..f9e8d2cb6 100644 --- a/db/routines/vn/procedures/ticket_cloneWeekly.sql +++ b/db/routines/vn/procedures/ticket_cloneWeekly.sql @@ -197,6 +197,6 @@ BEGIN END; END LOOP; CLOSE rsTicket; - DROP TEMPORARY TABLE IF EXISTS tmp.time; + DROP TEMPORARY TABLE IF EXISTS tmp.time, tmp.zoneGetLanded; END$$ DELIMITER ; diff --git a/db/routines/vn/procedures/zone_getCollisions.sql b/db/routines/vn/procedures/zone_getCollisions.sql index f6779e1b7..4f104eaad 100644 --- a/db/routines/vn/procedures/zone_getCollisions.sql +++ b/db/routines/vn/procedures/zone_getCollisions.sql @@ -120,6 +120,7 @@ BEGIN DROP TEMPORARY TABLE geoCollision, tmp.zone, - tmp.zoneNodes; + tmp.zoneNodes, + tmp.zoneOption; END$$ DELIMITER ; From a5d262671d5c23624d3fb2031daccb4e313dbad1 Mon Sep 17 00:00:00 2001 From: Javier Segarra Date: Fri, 29 Mar 2024 22:19:23 +0100 Subject: [PATCH 02/61] refs #6436 feat: extend BeforeAll --- back/tests-helper.js | 14 ++++++++++++-- back/tests.js | 3 +-- 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/back/tests-helper.js b/back/tests-helper.js index b88fa1fd6..e4878c4a2 100644 --- a/back/tests-helper.js +++ b/back/tests-helper.js @@ -10,7 +10,7 @@ async function init() { host: process.env.DB_HOST, port: process.env.DB_PORT }); - + customBeforeAll(); const bootOptions = {dataSources}; await new Promise((resolve, reject) => { app.boot(bootOptions, @@ -24,7 +24,16 @@ async function deinit() { console.log('Stopping backend.'); await app.disconnect(); } - +function customBeforeAll() { + Object.assign(beforeAll, { + ctx: { + req: { + accessToken: {userId: 9}, + headers: {origin: 'http://localhost'}, + } + } + }); +} module.exports = { init, deinit @@ -32,3 +41,4 @@ module.exports = { if (require.main === module) init(); + diff --git a/back/tests.js b/back/tests.js index 50698eb92..f446b3483 100644 --- a/back/tests.js +++ b/back/tests.js @@ -84,13 +84,12 @@ async function test() { 'loopback/**/*[sS]pec.js', 'modules/*/back/**/*.[sS]pec.js' ], - helpers: [] + helpers: [`back/tests-helper.js`] }; if (PARALLEL) { const ParallelRunner = require('jasmine/parallel'); runner = new ParallelRunner({numWorkers: 1}); - config.helpers.push(`back/tests-helper.js`); } else { const Jasmine = require('jasmine'); runner = new Jasmine(); From 48cc499f379e1b6645ae24292b4f44de9c643132 Mon Sep 17 00:00:00 2001 From: Javier Segarra Date: Fri, 29 Mar 2024 22:19:36 +0100 Subject: [PATCH 03/61] refs #6436 perf: example to use --- back/methods/collection/spec/getSales.spec.js | 10 +--------- 1 file changed, 1 insertion(+), 9 deletions(-) diff --git a/back/methods/collection/spec/getSales.spec.js b/back/methods/collection/spec/getSales.spec.js index e6205cc79..f276d07d0 100644 --- a/back/methods/collection/spec/getSales.spec.js +++ b/back/methods/collection/spec/getSales.spec.js @@ -4,15 +4,7 @@ describe('collection getSales()', () => { const collectionOrTicketFk = 999999; const print = true; const source = 'CHECKER'; - - beforeAll(() => { - ctx = { - req: { - accessToken: {userId: 9}, - headers: {origin: 'http://localhost'}, - } - }; - }); + const {ctx} = beforeAll; it('should return a collection with tickets, placements and barcodes settled correctly', async() => { const tx = await models.Collection.beginTransaction({}); From cb55740b68cdfc26948ff38de166fb8ad79fa9c6 Mon Sep 17 00:00:00 2001 From: Javier Segarra Date: Mon, 1 Apr 2024 10:57:53 +0200 Subject: [PATCH 04/61] refs #6436 rollback --- back/tests-helper.js | 12 +----------- 1 file changed, 1 insertion(+), 11 deletions(-) diff --git a/back/tests-helper.js b/back/tests-helper.js index e4878c4a2..97554ae0d 100644 --- a/back/tests-helper.js +++ b/back/tests-helper.js @@ -10,7 +10,6 @@ async function init() { host: process.env.DB_HOST, port: process.env.DB_PORT }); - customBeforeAll(); const bootOptions = {dataSources}; await new Promise((resolve, reject) => { app.boot(bootOptions, @@ -24,16 +23,7 @@ async function deinit() { console.log('Stopping backend.'); await app.disconnect(); } -function customBeforeAll() { - Object.assign(beforeAll, { - ctx: { - req: { - accessToken: {userId: 9}, - headers: {origin: 'http://localhost'}, - } - } - }); -} + module.exports = { init, deinit From d6ee5d571e6712f050533427946b91a7d92b6a7f Mon Sep 17 00:00:00 2001 From: Javier Segarra Date: Mon, 1 Apr 2024 10:58:04 +0200 Subject: [PATCH 05/61] refs #6436 feat: jasmine helper --- back/tests.js | 3 ++- back/vn-jasmine.js | 48 ++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 50 insertions(+), 1 deletion(-) create mode 100644 back/vn-jasmine.js diff --git a/back/tests.js b/back/tests.js index f446b3483..2e89cfd05 100644 --- a/back/tests.js +++ b/back/tests.js @@ -84,12 +84,13 @@ async function test() { 'loopback/**/*[sS]pec.js', 'modules/*/back/**/*.[sS]pec.js' ], - helpers: [`back/tests-helper.js`] + helpers: [`back/vn-jasmine.js`] }; if (PARALLEL) { const ParallelRunner = require('jasmine/parallel'); runner = new ParallelRunner({numWorkers: 1}); + config.helpers.push(`back/tests-helper.js`); } else { const Jasmine = require('jasmine'); runner = new Jasmine(); diff --git a/back/vn-jasmine.js b/back/vn-jasmine.js new file mode 100644 index 000000000..88dc55dc0 --- /dev/null +++ b/back/vn-jasmine.js @@ -0,0 +1,48 @@ + +const LoopBackContext = require('loopback-context'); +const DEFAULT_ACCESS_TOKEN = {accessToken: {userId: 9}}; +const DEFAULT_HEADERS = {headers: {origin: 'http://localhost'}}; +const DEFAULT_BEFORE_ALL = { + ctx: { + req: { + ...DEFAULT_ACCESS_TOKEN, + ...DEFAULT_HEADERS + + }, + args: {} + } +}; +const DEFAULT_LOOPBACK_CTX = { + ...DEFAULT_ACCESS_TOKEN, + http: { + req: { + ...DEFAULT_HEADERS + } + }, + args: {} +}; + +function vnBeforeAll(value = DEFAULT_BEFORE_ALL) { + Object.assign(beforeAll, value); +} +function mockBeforeAll(value = DEFAULT_BEFORE_ALL) { + const origin = beforeAll.ctx; + Object.assign(origin, value); + return origin; +} + +const mockLoopBackContext = (value = DEFAULT_LOOPBACK_CTX) => { + const activeCtx = value; + + spyOn(LoopBackContext, 'getCurrentContext').and.returnValue({ + active: activeCtx + }); + return activeCtx; +}; +module.exports = { + mockBeforeAll, mockLoopBackContext +}; + +(function init() { + vnBeforeAll(); +})(); From 8ab9063b50b4003b0cb1cea62b81a33deae3454f Mon Sep 17 00:00:00 2001 From: Javier Segarra Date: Mon, 1 Apr 2024 11:00:55 +0200 Subject: [PATCH 06/61] refs #6436 feat: use mocks --- .../collection/spec/getTickets.spec.js | 10 +--------- .../client/specs/createWithUser.spec.js | 15 ++------------- .../invoice-in/specs/corrective.spec.js | 15 +-------------- .../item-shelving/specs/upsertItem.spec.js | 16 ++-------------- .../back/methods/sale/specs/clone.spec.js | 19 +++++-------------- .../ticket/specs/addSaleByCode.spec.js | 17 +++-------------- .../back/methods/ticket/specs/clone.spec.js | 15 +-------------- .../ticket/specs/transferClient.spec.js | 11 ++--------- 8 files changed, 17 insertions(+), 101 deletions(-) diff --git a/back/methods/collection/spec/getTickets.spec.js b/back/methods/collection/spec/getTickets.spec.js index e6b9e6a17..c066ead8c 100644 --- a/back/methods/collection/spec/getTickets.spec.js +++ b/back/methods/collection/spec/getTickets.spec.js @@ -1,15 +1,7 @@ const models = require('vn-loopback/server/server').models; describe('collection getTickets()', () => { - let ctx; - beforeAll(async() => { - ctx = { - req: { - accessToken: {userId: 9}, - headers: {origin: 'http://localhost'} - } - }; - }); + const {ctx} = beforeAll; it('should get tickets, sales and barcodes from collection', async() => { const tx = await models.Collection.beginTransaction({}); diff --git a/modules/client/back/methods/client/specs/createWithUser.spec.js b/modules/client/back/methods/client/specs/createWithUser.spec.js index 074cb289a..584c49d5c 100644 --- a/modules/client/back/methods/client/specs/createWithUser.spec.js +++ b/modules/client/back/methods/client/specs/createWithUser.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('Client Create', () => { const newAccount = { @@ -17,18 +17,7 @@ describe('Client Create', () => { delete newAccountWithoutEmail.email; beforeAll(async() => { - const activeCtx = { - accessToken: {userId: 9}, - http: { - req: { - headers: {origin: 'http://localhost'} - } - } - }; - - spyOn(LoopBackContext, 'getCurrentContext').and.returnValue({ - active: activeCtx - }); + mockLoopBackContext(); }); it(`should not find Deadpool as he's not created yet`, async() => { diff --git a/modules/invoiceIn/back/methods/invoice-in/specs/corrective.spec.js b/modules/invoiceIn/back/methods/invoice-in/specs/corrective.spec.js index 1047cd028..ff547f1c8 100644 --- a/modules/invoiceIn/back/methods/invoice-in/specs/corrective.spec.js +++ b/modules/invoiceIn/back/methods/invoice-in/specs/corrective.spec.js @@ -1,24 +1,11 @@ const models = require('vn-loopback/server/server').models; -const LoopBackContext = require('loopback-context'); describe('invoiceIn corrective()', () => { - let ctx; + const {ctx} = beforeAll; let options; let tx; beforeEach(async() => { - ctx = { - req: { - accessToken: {userId: 9}, - headers: {origin: 'http://localhost'} - }, - args: {} - }; - - spyOn(LoopBackContext, 'getCurrentContext').and.returnValue({ - active: ctx.req - }); - options = {transaction: tx}; tx = await models.Sale.beginTransaction({}); options.transaction = tx; diff --git a/modules/item/back/methods/item-shelving/specs/upsertItem.spec.js b/modules/item/back/methods/item-shelving/specs/upsertItem.spec.js index 9042b743d..e7f2ab015 100644 --- a/modules/item/back/methods/item-shelving/specs/upsertItem.spec.js +++ b/modules/item/back/methods/item-shelving/specs/upsertItem.spec.js @@ -1,26 +1,14 @@ const {models} = require('vn-loopback/server/server'); -const LoopBackContext = require('loopback-context'); // #6276 describe('ItemShelving upsertItem()', () => { const warehouseFk = 1; - let ctx; + + const {ctx} = beforeAll; let options; let tx; beforeEach(async() => { - ctx = { - req: { - accessToken: {userId: 9}, - headers: {origin: 'http://localhost'} - }, - args: {} - }; - - spyOn(LoopBackContext, 'getCurrentContext').and.returnValue({ - active: ctx.req - }); - options = {transaction: tx}; tx = await models.ItemShelving.beginTransaction({}); options.transaction = tx; diff --git a/modules/ticket/back/methods/sale/specs/clone.spec.js b/modules/ticket/back/methods/sale/specs/clone.spec.js index e2220c028..ef2c6a9a3 100644 --- a/modules/ticket/back/methods/sale/specs/clone.spec.js +++ b/modules/ticket/back/methods/sale/specs/clone.spec.js @@ -1,24 +1,15 @@ const models = require('vn-loopback/server/server').models; -const LoopBackContext = require('loopback-context'); +const {mockLoopBackContext, mockBeforeAll} = require('vn-loopback/../../back/vn-jasmine'); describe('Ticket cloning - clone function', () => { - let ctx; + let ctx = mockBeforeAll({ejemploe: true}); let options; let tx; + beforeAll(async() => { + mockLoopBackContext(); + }); beforeEach(async() => { - ctx = { - req: { - accessToken: {userId: 9}, - headers: {origin: 'http://localhost'} - }, - args: {} - }; - - spyOn(LoopBackContext, 'getCurrentContext').and.returnValue({ - active: ctx.req - }); - options = {transaction: tx}; tx = await models.Sale.beginTransaction({}); options.transaction = tx; diff --git a/modules/ticket/back/methods/ticket/specs/addSaleByCode.spec.js b/modules/ticket/back/methods/ticket/specs/addSaleByCode.spec.js index b97139178..29af66752 100644 --- a/modules/ticket/back/methods/ticket/specs/addSaleByCode.spec.js +++ b/modules/ticket/back/methods/ticket/specs/addSaleByCode.spec.js @@ -1,22 +1,11 @@ const {models} = require('vn-loopback/server/server'); -const LoopBackContext = require('loopback-context'); describe('Ticket addSaleByCode()', () => { const quantity = 3; const ticketFk = 13; const warehouseFk = 1; - beforeAll(async() => { - activeCtx = { - req: { - accessToken: {userId: 9}, - headers: {origin: 'http://localhost'}, - __: value => value - } - }; - spyOn(LoopBackContext, 'getCurrentContext').and.returnValue({ - active: activeCtx - }); - }); + + const {ctx} = beforeAll; it('should add a new sale', async() => { const tx = await models.Ticket.beginTransaction({}); @@ -26,7 +15,7 @@ describe('Ticket addSaleByCode()', () => { const code = '1111111111'; const salesBefore = await models.Sale.find(null, options); - await models.Ticket.addSaleByCode(activeCtx, code, quantity, ticketFk, warehouseFk, options); + await models.Ticket.addSaleByCode(ctx, code, quantity, ticketFk, warehouseFk, options); const salesAfter = await models.Sale.find(null, options); expect(salesAfter.length).toEqual(salesBefore.length + 1); diff --git a/modules/ticket/back/methods/ticket/specs/clone.spec.js b/modules/ticket/back/methods/ticket/specs/clone.spec.js index 26114bd58..cf222ab8d 100644 --- a/modules/ticket/back/methods/ticket/specs/clone.spec.js +++ b/modules/ticket/back/methods/ticket/specs/clone.spec.js @@ -1,26 +1,13 @@ const models = require('vn-loopback/server/server').models; -const LoopBackContext = require('loopback-context'); describe('Ticket cloning - clone function', () => { - let ctx; + const {ctx} = beforeAll; let options; let tx; const ticketId = 1; const shipped = Date.vnNew(); beforeEach(async() => { - ctx = { - req: { - accessToken: {userId: 9}, - headers: {origin: 'http://localhost'} - }, - args: {} - }; - - spyOn(LoopBackContext, 'getCurrentContext').and.returnValue({ - active: ctx.req - }); - options = {transaction: tx}; tx = await models.Ticket.beginTransaction({}); options.transaction = tx; diff --git a/modules/ticket/back/methods/ticket/specs/transferClient.spec.js b/modules/ticket/back/methods/ticket/specs/transferClient.spec.js index 5f1c09776..4aac0833a 100644 --- a/modules/ticket/back/methods/ticket/specs/transferClient.spec.js +++ b/modules/ticket/back/methods/ticket/specs/transferClient.spec.js @@ -4,18 +4,11 @@ describe('Ticket transferClient()', () => { const originalTicketId = 8; const refundTicketId = 24; const clientId = 1; - let ctx; + + const {ctx} = beforeAll; let options; let tx; beforeEach(async() => { - ctx = { - req: { - accessToken: {userId: 9}, - headers: {origin: 'http://localhost'} - }, - args: {} - }; - options = {transaction: tx}; tx = await models.Ticket.beginTransaction({}); options.transaction = tx; From 914d3b2c67ad4aaceb4968be15d1c40bd669c6da Mon Sep 17 00:00:00 2001 From: jorgep Date: Wed, 10 Apr 2024 11:41:08 +0200 Subject: [PATCH 07/61] feat: refs #6449 add showId column --- .../10986-pinkChrysanthemum/00-addSummaryId.sql | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 db/versions/10986-pinkChrysanthemum/00-addSummaryId.sql diff --git a/db/versions/10986-pinkChrysanthemum/00-addSummaryId.sql b/db/versions/10986-pinkChrysanthemum/00-addSummaryId.sql new file mode 100644 index 000000000..3dd330c68 --- /dev/null +++ b/db/versions/10986-pinkChrysanthemum/00-addSummaryId.sql @@ -0,0 +1,17 @@ +ALTER TABLE vn.claimLog ADD COLUMN IF NOT EXISTS showId BOOLEAN NOT NULL DEFAULT FALSE; +ALTER TABLE vn.clientLog ADD COLUMN IF NOT EXISTS showId BOOLEAN NOT NULL DEFAULT FALSE; +ALTER TABLE vn.deviceProductionLog ADD COLUMN IF NOT EXISTS showId BOOLEAN NOT NULL DEFAULT FALSE; +ALTER TABLE vn.entryLog ADD COLUMN IF NOT EXISTS showId BOOLEAN NOT NULL DEFAULT FALSE; +ALTER TABLE vn.invoiceInLog ADD COLUMN IF NOT EXISTS showId BOOLEAN NOT NULL DEFAULT FALSE; +ALTER TABLE vn.itemLog ADD COLUMN IF NOT EXISTS showId BOOLEAN NOT NULL DEFAULT FALSE; +ALTER TABLE vn.packingSiteDeviceLog ADD COLUMN IF NOT EXISTS showId BOOLEAN NOT NULL DEFAULT FALSE; +ALTER TABLE vn.parkingLog ADD COLUMN IF NOT EXISTS showId BOOLEAN NOT NULL DEFAULT FALSE; +ALTER TABLE vn.rateLog ADD COLUMN IF NOT EXISTS showId BOOLEAN NOT NULL DEFAULT FALSE; +ALTER TABLE vn.routeLog ADD COLUMN IF NOT EXISTS showId BOOLEAN NOT NULL DEFAULT FALSE; +ALTER TABLE vn.shelvingLog ADD COLUMN IF NOT EXISTS showId BOOLEAN NOT NULL DEFAULT FALSE; +ALTER TABLE vn.supplierLog ADD COLUMN IF NOT EXISTS showId BOOLEAN NOT NULL DEFAULT FALSE; +ALTER TABLE vn.ticketLog ADD COLUMN IF NOT EXISTS showId BOOLEAN NOT NULL DEFAULT FALSE; +ALTER TABLE vn.travelLog ADD COLUMN IF NOT EXISTS showId BOOLEAN NOT NULL DEFAULT FALSE; +ALTER TABLE vn.userLog ADD COLUMN IF NOT EXISTS showId BOOLEAN NOT NULL DEFAULT FALSE; +ALTER TABLE vn.workerLog ADD COLUMN IF NOT EXISTS showId BOOLEAN NOT NULL DEFAULT FALSE; +ALTER TABLE vn.zoneLog ADD COLUMN IF NOT EXISTS showId BOOLEAN NOT NULL DEFAULT FALSE; \ No newline at end of file From 841a5fcd5b762b293fa1bcc2b28bfcb0afc52c44 Mon Sep 17 00:00:00 2001 From: jorgep Date: Thu, 11 Apr 2024 15:08:33 +0200 Subject: [PATCH 08/61] feat: refs #6449 add summaryId column --- .../00-addSummaryId.sql | 39 +++++++++++-------- 1 file changed, 22 insertions(+), 17 deletions(-) diff --git a/db/versions/10986-pinkChrysanthemum/00-addSummaryId.sql b/db/versions/10986-pinkChrysanthemum/00-addSummaryId.sql index 3dd330c68..288785191 100644 --- a/db/versions/10986-pinkChrysanthemum/00-addSummaryId.sql +++ b/db/versions/10986-pinkChrysanthemum/00-addSummaryId.sql @@ -1,17 +1,22 @@ -ALTER TABLE vn.claimLog ADD COLUMN IF NOT EXISTS showId BOOLEAN NOT NULL DEFAULT FALSE; -ALTER TABLE vn.clientLog ADD COLUMN IF NOT EXISTS showId BOOLEAN NOT NULL DEFAULT FALSE; -ALTER TABLE vn.deviceProductionLog ADD COLUMN IF NOT EXISTS showId BOOLEAN NOT NULL DEFAULT FALSE; -ALTER TABLE vn.entryLog ADD COLUMN IF NOT EXISTS showId BOOLEAN NOT NULL DEFAULT FALSE; -ALTER TABLE vn.invoiceInLog ADD COLUMN IF NOT EXISTS showId BOOLEAN NOT NULL DEFAULT FALSE; -ALTER TABLE vn.itemLog ADD COLUMN IF NOT EXISTS showId BOOLEAN NOT NULL DEFAULT FALSE; -ALTER TABLE vn.packingSiteDeviceLog ADD COLUMN IF NOT EXISTS showId BOOLEAN NOT NULL DEFAULT FALSE; -ALTER TABLE vn.parkingLog ADD COLUMN IF NOT EXISTS showId BOOLEAN NOT NULL DEFAULT FALSE; -ALTER TABLE vn.rateLog ADD COLUMN IF NOT EXISTS showId BOOLEAN NOT NULL DEFAULT FALSE; -ALTER TABLE vn.routeLog ADD COLUMN IF NOT EXISTS showId BOOLEAN NOT NULL DEFAULT FALSE; -ALTER TABLE vn.shelvingLog ADD COLUMN IF NOT EXISTS showId BOOLEAN NOT NULL DEFAULT FALSE; -ALTER TABLE vn.supplierLog ADD COLUMN IF NOT EXISTS showId BOOLEAN NOT NULL DEFAULT FALSE; -ALTER TABLE vn.ticketLog ADD COLUMN IF NOT EXISTS showId BOOLEAN NOT NULL DEFAULT FALSE; -ALTER TABLE vn.travelLog ADD COLUMN IF NOT EXISTS showId BOOLEAN NOT NULL DEFAULT FALSE; -ALTER TABLE vn.userLog ADD COLUMN IF NOT EXISTS showId BOOLEAN NOT NULL DEFAULT FALSE; -ALTER TABLE vn.workerLog ADD COLUMN IF NOT EXISTS showId BOOLEAN NOT NULL DEFAULT FALSE; -ALTER TABLE vn.zoneLog ADD COLUMN IF NOT EXISTS showId BOOLEAN NOT NULL DEFAULT FALSE; \ No newline at end of file +ALTER TABLE vn.claimLog ADD COLUMN IF NOT EXISTS summaryId varchar(30); +ALTER TABLE vn.clientLog ADD COLUMN IF NOT EXISTS summaryId varchar(30); +ALTER TABLE vn.deviceProductionLog ADD COLUMN IF NOT EXISTS summaryId varchar(30); +ALTER TABLE vn.entryLog ADD COLUMN IF NOT EXISTS summaryId varchar(30); +ALTER TABLE vn.invoiceInLog ADD COLUMN IF NOT EXISTS summaryId varchar(30); +ALTER TABLE vn.itemLog ADD COLUMN IF NOT EXISTS summaryId varchar(30); +ALTER TABLE vn.packingSiteDeviceLog ADD COLUMN IF NOT EXISTS summaryId varchar(30); +ALTER TABLE vn.parkingLog ADD COLUMN IF NOT EXISTS summaryId varchar(30); +ALTER TABLE vn.rateLog ADD COLUMN IF NOT EXISTS summaryId varchar(30); +ALTER TABLE vn.routeLog ADD COLUMN IF NOT EXISTS summaryId varchar(30); +ALTER TABLE vn.shelvingLog ADD COLUMN IF NOT EXISTS summaryId varchar(30); +ALTER TABLE vn.supplierLog ADD COLUMN IF NOT EXISTS summaryId varchar(30); +ALTER TABLE vn.ticketLog ADD COLUMN IF NOT EXISTS summaryId varchar(30); +ALTER TABLE vn.travelLog ADD COLUMN IF NOT EXISTS summaryId varchar(30); +ALTER TABLE vn.userLog ADD COLUMN IF NOT EXISTS summaryId varchar(30); +ALTER TABLE vn.workerLog ADD COLUMN IF NOT EXISTS summaryId varchar(30); +ALTER TABLE vn.zoneLog ADD COLUMN IF NOT EXISTS summaryId varchar(30); + +ALTER TABLE account.userLog ADD COLUMN IF NOT EXISTS summaryId varchar(30); +ALTER TABLE account.signInLog ADD COLUMN IF NOT EXISTS summaryId varchar(30); +ALTER TABLE account.roleLog ADD COLUMN IF NOT EXISTS summaryId varchar(30); +ALTER TABLE account.accountLog ADD COLUMN IF NOT EXISTS summaryId varchar(30); \ No newline at end of file From c161c122d01367fd22b6810a487a9ca3f7252a19 Mon Sep 17 00:00:00 2001 From: jorgep Date: Thu, 11 Apr 2024 15:56:17 +0200 Subject: [PATCH 09/61] feat: refs #6449 add column --- modules/ticket/back/models/ticket-log.json | 3 +++ 1 file changed, 3 insertions(+) diff --git a/modules/ticket/back/models/ticket-log.json b/modules/ticket/back/models/ticket-log.json index 32b4afd13..97722be96 100644 --- a/modules/ticket/back/models/ticket-log.json +++ b/modules/ticket/back/models/ticket-log.json @@ -39,6 +39,9 @@ }, "changedModelValue": { "type": "string" + }, + "summaryId": { + "type":"string" } } } From a21e3357743fbba4f3648db9c8b31667770c5a46 Mon Sep 17 00:00:00 2001 From: jorgep Date: Thu, 2 May 2024 17:23:04 +0200 Subject: [PATCH 10/61] feat: refs #6449 Add display of item ID in Ticket Logs --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index a672e7986..c24cefa4f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,6 +10,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Fixed - (Worker -> time-control) Corrección de errores - (InvoiceOut -> Crear factura) Cuando falla al crear una factura, se devuelve un error +- (Ticket -> Logs) Ahora se muestra el id del item de la línea de venta ## [24.18.01] - 2024-05-07 From 2985e1c9e80dd7ff9b879199b2a9e38d3f13c7e1 Mon Sep 17 00:00:00 2001 From: sergiodt Date: Fri, 31 May 2024 13:08:48 +0200 Subject: [PATCH 11/61] feat: roadMap refs #7195 --- back/models/warehouse.json | 33 +++++++++++++------ .../11081-wheatRaphis/00-firstScript.sql | 8 +++++ modules/route/back/models/roadmap.json | 12 +++---- 3 files changed, 37 insertions(+), 16 deletions(-) create mode 100644 db/versions/11081-wheatRaphis/00-firstScript.sql diff --git a/back/models/warehouse.json b/back/models/warehouse.json index dcbf7f2d2..69c74f153 100644 --- a/back/models/warehouse.json +++ b/back/models/warehouse.json @@ -9,21 +9,28 @@ }, "properties": { "id": { - "id": true, - "type": "number", - "forceId": false + "id": true, + "type": "number", + "forceId": false }, "name": { - "type": "string" + "type": "string" }, "code": { - "type": "string" + "type": "string" }, "isInventory": { - "type": "number" + "type": "number" }, - "isManaged":{ - "type": "boolean" + "isManaged": { + "type": "boolean" + } + }, + "relations": { + "address": { + "type": "belongsTo", + "model": "Address", + "foreignKey": "addressFk" } }, "acls": [ @@ -34,5 +41,11 @@ "permission": "ALLOW" } ], - "scope" : {"where": {"isForTicket": {"neq": 0}}} -} + "scope": { + "where": { + "isForTicket": { + "neq": 0 + } + } + } +} \ No newline at end of file diff --git a/db/versions/11081-wheatRaphis/00-firstScript.sql b/db/versions/11081-wheatRaphis/00-firstScript.sql new file mode 100644 index 000000000..70bbaabdb --- /dev/null +++ b/db/versions/11081-wheatRaphis/00-firstScript.sql @@ -0,0 +1,8 @@ +-- Place your SQL code here + +USE vn; + +ALTER TABLE vn.roadmap ADD kmStart mediumint(9) DEFAULT NULL NULL; +ALTER TABLE vn.roadmap ADD kmEnd mediumint(9) DEFAULT NULL NULL; +ALTER TABLE vn.roadmap ADD started DATETIME NULL; +ALTER TABLE vn.roadmap ADD finished DATETIME NULL; diff --git a/modules/route/back/models/roadmap.json b/modules/route/back/models/roadmap.json index 01572d718..ac6cdae9f 100644 --- a/modules/route/back/models/roadmap.json +++ b/modules/route/back/models/roadmap.json @@ -3,7 +3,7 @@ "base": "VnModel", "options": { "mysql": { - "table": "roadmap" + "table": "roadmap" } }, "properties": { @@ -43,8 +43,8 @@ "type": "string" } }, - "relations": { - "worker": { + "relations": { + "worker": { "type": "belongsTo", "model": "Worker", "foreignKey": "id" @@ -57,7 +57,7 @@ "roadmapStop": { "type": "hasMany", "model": "RoadmapStop", - "foreignKey": "roadmapFk" + "foreignKey": "roadMapFk" } - } -} + } +} \ No newline at end of file From 882d5bf036c731a2b74888fcee367d8a554299ff Mon Sep 17 00:00:00 2001 From: sergiodt Date: Mon, 3 Jun 2024 18:39:11 +0200 Subject: [PATCH 12/61] feat: roadMap refs #7195 --- .../roadmapStop/getPalletMatchState.js | 63 +++++++++++++++++++ .../specs/getPalletMatchState.spec.js | 12 ++++ modules/route/back/models/roadmap.json | 12 ++++ modules/route/back/models/roadmapStop.js | 3 + 4 files changed, 90 insertions(+) create mode 100644 modules/route/back/methods/roadmapStop/getPalletMatchState.js create mode 100644 modules/route/back/methods/roadmapStop/specs/getPalletMatchState.spec.js create mode 100644 modules/route/back/models/roadmapStop.js diff --git a/modules/route/back/methods/roadmapStop/getPalletMatchState.js b/modules/route/back/methods/roadmapStop/getPalletMatchState.js new file mode 100644 index 000000000..efed64327 --- /dev/null +++ b/modules/route/back/methods/roadmapStop/getPalletMatchState.js @@ -0,0 +1,63 @@ +module.exports = Self => { + Self.remoteMethod('getPalletMatchState', { + description: 'Get pallet', + accessType: 'WRITE', + accepts: [{ + arg: 'roadMapStopFk', + type: 'number', + required: true, + description: 'The roadmapFk id' + }, + { + arg: 'state', + type: 'string', + required: true, + description: 'State code' + }], + returns: { + type: 'object', + root: true + }, + http: { + path: `/getPalletMatchState`, + verb: 'GET' + } + }); + + Self.getPalletMatchState = async(roadMapStopFk, state, options) => { + const myOptions = {}; + + if (typeof options == 'object') + Object.assign(myOptions, options); + + const result = await Self.rawSql(` + WITH tPallet AS( + SELECT ep.truckFk roadMapStop,ep.id pallet, e.id expedition, e.stateTypeFk + FROM vn.expeditionPallet ep + JOIN vn.expeditionScan es ON es.palletFk = ep.id + JOIN expedition e ON e.id = es.expeditionFk + WHERE ep.truckFk = ? + ),totalPalletExpedition AS( + SELECT t.*, COUNT(expedition) totalPalletExpedition + FROM tPallet t + GROUP BY expedition + ),totalPalletExpeditionCode AS( + SELECT t.*, COUNT(expedition) totalPalletExpeditionCode + FROM tPallet t + JOIN vn.expeditionStateType est ON est.id = t.stateTypeFk + WHERE code = ? + GROUP BY expedition + ) + SELECT t.roadMapStop, + t.pallet, + IF (tpe.totalPalletExpedition = tpec.totalPalletExpeditionCode, 'TRUE', 'FALSE') hasMatchStateCode + FROM tPallet t + LEFT JOIN totalPalletExpedition tpe ON tpe.expedition = t.expedition + LEFT JOIN totalPalletExpeditionCode tpec ON tpec.expedition = t.expedition + GROUP BY t.pallet;`, + [roadMapStopFk, state], + myOptions); + + return result; + }; +}; diff --git a/modules/route/back/methods/roadmapStop/specs/getPalletMatchState.spec.js b/modules/route/back/methods/roadmapStop/specs/getPalletMatchState.spec.js new file mode 100644 index 000000000..ac782561a --- /dev/null +++ b/modules/route/back/methods/roadmapStop/specs/getPalletMatchState.spec.js @@ -0,0 +1,12 @@ + +const {models} = require('vn-loopback/server/server'); + +describe('roadMapStop getPalletMatchState()', () => { + fit('should return list of pallet with true or false if state is matched', async() => { + const roadmapStopFk = 1; + const state = 'ON DELIVERY'; + const result = await models.RoadmapStop.getPalletMatchState(roadmapStopFk, state); + + expect(result[0].hasMatchStateCode).toBe('TRUE'); + }); +}); diff --git a/modules/route/back/models/roadmap.json b/modules/route/back/models/roadmap.json index ac6cdae9f..5321af7c3 100644 --- a/modules/route/back/models/roadmap.json +++ b/modules/route/back/models/roadmap.json @@ -41,6 +41,18 @@ }, "driverName": { "type": "string" + }, + "kmStart": { + "type": "number" + }, + "kmEnd": { + "type": "number" + }, + "started": { + "type": "date" + }, + "finished": { + "type": "date" } }, "relations": { diff --git a/modules/route/back/models/roadmapStop.js b/modules/route/back/models/roadmapStop.js new file mode 100644 index 000000000..9e286776d --- /dev/null +++ b/modules/route/back/models/roadmapStop.js @@ -0,0 +1,3 @@ +module.exports = Self => { + require('../methods/roadmapStop/getPalletMatchState')(Self); +}; From f0ad012835aa14e67f0e48fc7f04446653dc5288 Mon Sep 17 00:00:00 2001 From: Jon Date: Tue, 11 Jun 2024 09:39:06 +0200 Subject: [PATCH 14/61] refactor: refs #6436 first wave --- .../collection/spec/setSaleQuantity.spec.js | 14 ++-------- .../specs/getStarredModules.spec.js | 22 +++++----------- .../starred-module/specs/setPosition.spec.js | 24 +++++------------ .../specs/toggleStarredModule.spec.js | 26 ++++++------------- db/.pullinfo.json | 2 +- .../methods/vn-model/specs/crud.spec.js | 14 ++-------- .../vn-model/specs/rewriteDbError.spec.js | 14 ++-------- .../entry/specs/editLatestBuys.spec.js | 15 ++--------- .../invoice-in-due-day/specs/new.spec.js | 9 ++----- .../back/models/specs/supplier.spec.js | 15 ++--------- .../travel/specs/createThermograph.spec.js | 14 ++-------- .../back/methods/worker/specs/new.spec.js | 15 ++--------- 12 files changed, 39 insertions(+), 145 deletions(-) diff --git a/back/methods/collection/spec/setSaleQuantity.spec.js b/back/methods/collection/spec/setSaleQuantity.spec.js index b563f5b19..7abcda36b 100644 --- a/back/methods/collection/spec/setSaleQuantity.spec.js +++ b/back/methods/collection/spec/setSaleQuantity.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('setSaleQuantity()', () => { beforeAll(async() => { - const activeCtx = { - accessToken: {userId: 9}, - http: { - req: { - headers: {origin: 'http://localhost'} - } - } - }; - spyOn(LoopBackContext, 'getCurrentContext').and.returnValue({ - active: activeCtx - }); + mockLoopBackContext(); }); it('should change quantity sale', async() => { diff --git a/back/methods/starred-module/specs/getStarredModules.spec.js b/back/methods/starred-module/specs/getStarredModules.spec.js index bf9bd1d73..25b4989fa 100644 --- a/back/methods/starred-module/specs/getStarredModules.spec.js +++ b/back/methods/starred-module/specs/getStarredModules.spec.js @@ -1,22 +1,14 @@ const {models} = require('vn-loopback/server/server'); -const LoopBackContext = require('loopback-context'); +// const LoopBackContext = require('loopback-context'); describe('getStarredModules()', () => { - const activeCtx = { - accessToken: {userId: 9}, - http: { - req: { - headers: {origin: 'http://localhost'} - } - } - }; - const ctx = {req: activeCtx}; + const {ctx} = beforeAll; - beforeEach(() => { - spyOn(LoopBackContext, 'getCurrentContext').and.returnValue({ - active: activeCtx - }); - }); + // 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}); diff --git a/back/methods/starred-module/specs/setPosition.spec.js b/back/methods/starred-module/specs/setPosition.spec.js index a428fcf22..61b99440e 100644 --- a/back/methods/starred-module/specs/setPosition.spec.js +++ b/back/methods/starred-module/specs/setPosition.spec.js @@ -1,24 +1,14 @@ const {models} = require('vn-loopback/server/server'); -const LoopBackContext = require('loopback-context'); +// const LoopBackContext = require('loopback-context'); describe('setPosition()', () => { - const activeCtx = { - accessToken: {userId: 9}, - http: { - req: { - headers: {origin: 'http://localhost'} - } - } - }; - const ctx = { - req: activeCtx - }; + const {ctx} = beforeAll; - beforeEach(() => { - spyOn(LoopBackContext, 'getCurrentContext').and.returnValue({ - active: activeCtx - }); - }); + // 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 848c1475a..10dd0492c 100644 --- a/back/methods/starred-module/specs/toggleStarredModule.spec.js +++ b/back/methods/starred-module/specs/toggleStarredModule.spec.js @@ -1,24 +1,14 @@ const {models} = require('vn-loopback/server/server'); -const LoopBackContext = require('loopback-context'); +// const LoopBackContext = require('loopback-context'); describe('toggleStarredModule()', () => { - const activeCtx = { - accessToken: {userId: 9}, - http: { - req: { - headers: {origin: 'http://localhost'} - } - } - }; - const ctx = { - req: activeCtx - }; + const {ctx} = beforeAll; - beforeEach(() => { - spyOn(LoopBackContext, 'getCurrentContext').and.returnValue({ - active: activeCtx - }); - }); + // 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'); @@ -26,7 +16,7 @@ describe('toggleStarredModule()', () => { expect(starredModules.length).toEqual(1); expect(starredModule.moduleFk).toEqual('order'); - expect(starredModule.workerFk).toEqual(activeCtx.accessToken.userId); + expect(starredModule.workerFk).toEqual(ctx.req.accessToken.userId); expect(starredModule.position).toEqual(starredModules.length); await models.StarredModule.toggleStarredModule(ctx, 'order'); diff --git a/db/.pullinfo.json b/db/.pullinfo.json index f4afbc5fb..0defed845 100644 --- a/db/.pullinfo.json +++ b/db/.pullinfo.json @@ -9,7 +9,7 @@ }, "vn": { "view": { - "expeditionPallet_Print": "288cbd6e8289df083ed5eb1a2c808f7a82ba4c90c8ad9781104808a7a54471fb" + "expeditionPallet_Print": "06613719475fcdba8309607c38cc78efc2e348cca7bc96b48dc3ae3c12426f54" } } } diff --git a/loopback/common/methods/vn-model/specs/crud.spec.js b/loopback/common/methods/vn-model/specs/crud.spec.js index 56af72bd9..d120db92a 100644 --- a/loopback/common/methods/vn-model/specs/crud.spec.js +++ b/loopback/common/methods/vn-model/specs/crud.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('Model crud()', () => { beforeAll(async() => { - const activeCtx = { - accessToken: {userId: 9}, - http: { - req: { - headers: {origin: 'http://localhost'} - } - } - }; - spyOn(LoopBackContext, 'getCurrentContext').and.returnValue({ - active: activeCtx - }); + mockLoopBackContext(); }); let insertId; const barcodeModel = app.models.ItemBarcode; diff --git a/loopback/common/methods/vn-model/specs/rewriteDbError.spec.js b/loopback/common/methods/vn-model/specs/rewriteDbError.spec.js index a3dba14d7..e3c24e74a 100644 --- a/loopback/common/methods/vn-model/specs/rewriteDbError.spec.js +++ b/loopback/common/methods/vn-model/specs/rewriteDbError.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('Model rewriteDbError()', () => { beforeAll(async() => { - const activeCtx = { - accessToken: {userId: 9}, - http: { - req: { - headers: {origin: 'http://localhost'} - } - } - }; - spyOn(LoopBackContext, 'getCurrentContext').and.returnValue({ - active: activeCtx - }); + mockLoopBackContext(); }); it('should extend rewriteDbError properties to any model passed', () => { diff --git a/modules/entry/back/methods/entry/specs/editLatestBuys.spec.js b/modules/entry/back/methods/entry/specs/editLatestBuys.spec.js index 885171ed5..bff758eea 100644 --- a/modules/entry/back/methods/entry/specs/editLatestBuys.spec.js +++ b/modules/entry/back/methods/entry/specs/editLatestBuys.spec.js @@ -1,20 +1,9 @@ const models = require('vn-loopback/server/server').models; -const LoopBackContext = require('loopback-context'); +const {mockLoopBackContext} = require('vn-loopback/../../back/vn-jasmine'); describe('Buy editLatestsBuys()', () => { beforeAll(async() => { - const activeCtx = { - accessToken: {userId: 9}, - http: { - req: { - headers: {origin: 'http://localhost'} - } - } - }; - - spyOn(LoopBackContext, 'getCurrentContext').and.returnValue({ - active: activeCtx - }); + mockLoopBackContext(); }); it('should change the value of a given column for the selected buys', async() => { diff --git a/modules/invoiceIn/back/methods/invoice-in-due-day/specs/new.spec.js b/modules/invoiceIn/back/methods/invoice-in-due-day/specs/new.spec.js index f21dad9f2..02a43d4af 100644 --- a/modules/invoiceIn/back/methods/invoice-in-due-day/specs/new.spec.js +++ b/modules/invoiceIn/back/methods/invoice-in-due-day/specs/new.spec.js @@ -1,14 +1,9 @@ -const LoopBackContext = require('loopback-context'); const models = require('vn-loopback/server/server').models; +const {mockLoopBackContext} = require('vn-loopback/../../back/vn-jasmine'); describe('invoiceInDueDay new()', () => { beforeAll(async() => { - const activeCtx = { - accessToken: {userId: 9}, - }; - spyOn(LoopBackContext, 'getCurrentContext').and.returnValue({ - active: activeCtx - }); + mockLoopBackContext(); }); it('should correctly create a new due day', async() => { diff --git a/modules/supplier/back/models/specs/supplier.spec.js b/modules/supplier/back/models/specs/supplier.spec.js index 05d78240d..2c0d1910f 100644 --- a/modules/supplier/back/models/specs/supplier.spec.js +++ b/modules/supplier/back/models/specs/supplier.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('loopback model Supplier', () => { let supplierOne; @@ -8,18 +8,7 @@ describe('loopback model Supplier', () => { beforeAll(async() => { supplierOne = await models.Supplier.findById(1); supplierTwo = await models.Supplier.findById(442); - const activeCtx = { - accessToken: {userId: 9}, - http: { - req: { - headers: {origin: 'http://localhost'} - } - } - }; - - spyOn(LoopBackContext, 'getCurrentContext').and.returnValue({ - active: activeCtx - }); + mockLoopBackContext(); }); describe('payMethodFk', () => { diff --git a/modules/travel/back/methods/travel/specs/createThermograph.spec.js b/modules/travel/back/methods/travel/specs/createThermograph.spec.js index e812eae70..9c93d6d52 100644 --- a/modules/travel/back/methods/travel/specs/createThermograph.spec.js +++ b/modules/travel/back/methods/travel/specs/createThermograph.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('Travel createThermograph()', () => { beforeAll(async() => { - const activeCtx = { - accessToken: {userId: 9}, - http: { - req: { - headers: {origin: 'http://localhost'} - } - } - }; - spyOn(LoopBackContext, 'getCurrentContext').and.returnValue({ - active: activeCtx - }); + mockLoopBackContext(); }); const travelId = 3; const currentUserId = 1102; diff --git a/modules/worker/back/methods/worker/specs/new.spec.js b/modules/worker/back/methods/worker/specs/new.spec.js index 66959e0a7..186e003cf 100644 --- a/modules/worker/back/methods/worker/specs/new.spec.js +++ b/modules/worker/back/methods/worker/specs/new.spec.js @@ -1,20 +1,9 @@ const models = require('vn-loopback/server/server').models; -const LoopBackContext = require('loopback-context'); +const {mockLoopBackContext} = require('vn-loopback/../../back/vn-jasmine'); describe('Worker new', () => { beforeAll(async() => { - const activeCtx = { - accessToken: {userId: 9}, - http: { - req: { - headers: {origin: 'http://localhost'} - } - } - }; - - spyOn(LoopBackContext, 'getCurrentContext').and.returnValue({ - active: activeCtx - }); + mockLoopBackContext(); }); const employeeId = 1; From b3fa8697574edb4e18be1237ec79181808258bea Mon Sep 17 00:00:00 2001 From: Jon Date: Tue, 11 Jun 2024 10:00:30 +0200 Subject: [PATCH 15/61] 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; From 093eaeb4751a150f2414ced30c93c18bf02bae83 Mon Sep 17 00:00:00 2001 From: Jon Date: Tue, 11 Jun 2024 10:45:46 +0200 Subject: [PATCH 16/61] refactor: refs #6436 third wave --- .../client/specs/addressesPropagateRe.spec.js | 15 ++------------- .../methods/client/specs/createAddress.spec.js | 15 ++------------- .../methods/client/specs/updateAddress.spec.js | 15 ++------------- modules/client/back/models/specs/address.spec.js | 15 ++------------- .../fixed-price/specs/upsertFixedPrice.spec.js | 14 ++------------ .../item/back/methods/item/specs/clone.spec.js | 14 ++------------ .../back/methods/item/specs/getBalance.spec.js | 7 ++----- modules/item/back/methods/item/specs/new.spec.js | 15 ++------------- .../back/methods/item/specs/updateTaxes.spec.js | 14 ++------------ .../zone/back/methods/zone/specs/clone.spec.js | 14 ++------------ .../back/methods/zone/specs/exclusionGeo.spec.js | 14 ++------------ .../methods/zone/specs/toggleIsIncluded.spec.js | 15 +++------------ 12 files changed, 25 insertions(+), 142 deletions(-) diff --git a/modules/client/back/methods/client/specs/addressesPropagateRe.spec.js b/modules/client/back/methods/client/specs/addressesPropagateRe.spec.js index 74d80b964..ec4ebe471 100644 --- a/modules/client/back/methods/client/specs/addressesPropagateRe.spec.js +++ b/modules/client/back/methods/client/specs/addressesPropagateRe.spec.js @@ -1,20 +1,9 @@ const models = require('vn-loopback/server/server').models; -const LoopBackContext = require('loopback-context'); +const {mockLoopBackContext} = require('vn-loopback/../../back/vn-jasmine'); describe('Client addressesPropagateRe', () => { beforeAll(async() => { - const activeCtx = { - accessToken: {userId: 9}, - http: { - req: { - headers: {origin: 'http://localhost'} - } - } - }; - - spyOn(LoopBackContext, 'getCurrentContext').and.returnValue({ - active: activeCtx - }); + mockLoopBackContext(); }); it('should propagate the isEqualizated on both addresses of Mr Wayne and set hasToInvoiceByAddress to false', async() => { diff --git a/modules/client/back/methods/client/specs/createAddress.spec.js b/modules/client/back/methods/client/specs/createAddress.spec.js index ae179cf6c..0556ce2cf 100644 --- a/modules/client/back/methods/client/specs/createAddress.spec.js +++ b/modules/client/back/methods/client/specs/createAddress.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('Address createAddress', () => { const clientFk = 1101; @@ -8,18 +8,7 @@ describe('Address createAddress', () => { const customAgentOneId = 1; beforeAll(async() => { - const activeCtx = { - accessToken: {userId: 9}, - http: { - req: { - headers: {origin: 'http://localhost'} - } - } - }; - - spyOn(LoopBackContext, 'getCurrentContext').and.returnValue({ - active: activeCtx - }); + mockLoopBackContext(); }); it('should throw a non uee member error if no incoterms is defined', async() => { diff --git a/modules/client/back/methods/client/specs/updateAddress.spec.js b/modules/client/back/methods/client/specs/updateAddress.spec.js index 6f02323c5..dd5142af0 100644 --- a/modules/client/back/methods/client/specs/updateAddress.spec.js +++ b/modules/client/back/methods/client/specs/updateAddress.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('Address updateAddress', () => { const clientId = 1101; @@ -15,18 +15,7 @@ describe('Address updateAddress', () => { }; beforeAll(async() => { - const activeCtx = { - accessToken: {userId: 9}, - http: { - req: { - headers: {origin: 'http://localhost'} - } - } - }; - - spyOn(LoopBackContext, 'getCurrentContext').and.returnValue({ - active: activeCtx - }); + mockLoopBackContext(); }); it('should throw the non uee member error if no incoterms is defined', async() => { diff --git a/modules/client/back/models/specs/address.spec.js b/modules/client/back/models/specs/address.spec.js index f0b421d35..4baa1bdca 100644 --- a/modules/client/back/models/specs/address.spec.js +++ b/modules/client/back/models/specs/address.spec.js @@ -1,23 +1,12 @@ const models = require('vn-loopback/server/server').models; -const LoopBackContext = require('loopback-context'); +const {mockLoopBackContext} = require('vn-loopback/../../back/vn-jasmine'); describe('loopback model address', () => { let createdAddressId; const clientId = 1101; - const activeCtx = { - accessToken: {userId: 9}, - http: { - req: { - headers: {origin: 'http://localhost'} - } - } - }; - beforeAll(() => { - spyOn(LoopBackContext, 'getCurrentContext').and.returnValue({ - active: activeCtx - }); + mockLoopBackContext(); }); afterAll(async() => { diff --git a/modules/item/back/methods/fixed-price/specs/upsertFixedPrice.spec.js b/modules/item/back/methods/fixed-price/specs/upsertFixedPrice.spec.js index 823406500..36a15849c 100644 --- a/modules/item/back/methods/fixed-price/specs/upsertFixedPrice.spec.js +++ b/modules/item/back/methods/fixed-price/specs/upsertFixedPrice.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('upsertFixedPrice()', () => { const now = Date.vnNew(); @@ -8,17 +8,7 @@ describe('upsertFixedPrice()', () => { beforeAll(async() => { originalFixedPrice = await models.FixedPrice.findById(fixedPriceId); - const activeCtx = { - accessToken: {userId: 9}, - http: { - req: { - headers: {origin: 'http://localhost'} - } - } - }; - spyOn(LoopBackContext, 'getCurrentContext').and.returnValue({ - active: activeCtx - }); + mockLoopBackContext(); }); it(`should toggle the hasMinPrice boolean if there's a minPrice and update the rest of the data`, async() => { diff --git a/modules/item/back/methods/item/specs/clone.spec.js b/modules/item/back/methods/item/specs/clone.spec.js index 01210677e..1a479cd84 100644 --- a/modules/item/back/methods/item/specs/clone.spec.js +++ b/modules/item/back/methods/item/specs/clone.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('item clone()', () => { let nextItemId; beforeAll(async() => { - const activeCtx = { - accessToken: {userId: 9}, - http: { - req: { - headers: {origin: 'http://localhost'} - } - } - }; - spyOn(LoopBackContext, 'getCurrentContext').and.returnValue({ - active: activeCtx - }); + mockLoopBackContext(); }); beforeEach(async() => { diff --git a/modules/item/back/methods/item/specs/getBalance.spec.js b/modules/item/back/methods/item/specs/getBalance.spec.js index 728b5f33e..d1bb65b75 100644 --- a/modules/item/back/methods/item/specs/getBalance.spec.js +++ b/modules/item/back/methods/item/specs/getBalance.spec.js @@ -2,17 +2,14 @@ const models = require('vn-loopback/server/server').models; const LoopBackContext = require('loopback-context'); describe('item getBalance()', () => { - const ctx = {req: {accessToken: {userId: 9}}}; + const {ctx} = beforeAll; it('should return the balance lines of a client type loses in which one has highlighted true', async() => { const tx = await models.Item.beginTransaction({}); const options = {transaction: tx}; try { - const activeCtx = { - accessToken: {userId: 9}, - }; spyOn(LoopBackContext, 'getCurrentContext').and.returnValue({ - active: activeCtx + active: ctx }); const losesClientId = 1111; const ticket = await models.Ticket.findById(7, null, options); diff --git a/modules/item/back/methods/item/specs/new.spec.js b/modules/item/back/methods/item/specs/new.spec.js index 2ffaf87a5..7a3612ebc 100644 --- a/modules/item/back/methods/item/specs/new.spec.js +++ b/modules/item/back/methods/item/specs/new.spec.js @@ -1,20 +1,9 @@ const models = require('vn-loopback/server/server').models; -const LoopBackContext = require('loopback-context'); +const {mockLoopBackContext} = require('vn-loopback/../../back/vn-jasmine'); describe('item new()', () => { - 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 - }); + mockLoopBackContext(); }); it('should create a new item, adding the name as a tag', async() => { diff --git a/modules/item/back/methods/item/specs/updateTaxes.spec.js b/modules/item/back/methods/item/specs/updateTaxes.spec.js index 793e43de8..49f95c1ed 100644 --- a/modules/item/back/methods/item/specs/updateTaxes.spec.js +++ b/modules/item/back/methods/item/specs/updateTaxes.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('item updateTaxes()', () => { 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 taxClassFk is blank', async() => { diff --git a/modules/zone/back/methods/zone/specs/clone.spec.js b/modules/zone/back/methods/zone/specs/clone.spec.js index 1b7393912..465abdc9c 100644 --- a/modules/zone/back/methods/zone/specs/clone.spec.js +++ b/modules/zone/back/methods/zone/specs/clone.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('agency clone()', () => { beforeAll(async() => { - const activeCtx = { - accessToken: {userId: 9}, - http: { - req: { - headers: {origin: 'http://localhost'} - } - } - }; - spyOn(LoopBackContext, 'getCurrentContext').and.returnValue({ - active: activeCtx - }); + mockLoopBackContext(); }); it('should clone a zone', async() => { diff --git a/modules/zone/back/methods/zone/specs/exclusionGeo.spec.js b/modules/zone/back/methods/zone/specs/exclusionGeo.spec.js index fbe96fc5f..746be502f 100644 --- a/modules/zone/back/methods/zone/specs/exclusionGeo.spec.js +++ b/modules/zone/back/methods/zone/specs/exclusionGeo.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('zone exclusionGeo()', () => { beforeAll(async() => { - const activeCtx = { - accessToken: {userId: 9}, - http: { - req: { - headers: {origin: 'http://localhost'} - } - } - }; - spyOn(LoopBackContext, 'getCurrentContext').and.returnValue({ - active: activeCtx - }); + mockLoopBackContext(); }); const zoneId = 1; const today = Date.vnNew(); diff --git a/modules/zone/back/methods/zone/specs/toggleIsIncluded.spec.js b/modules/zone/back/methods/zone/specs/toggleIsIncluded.spec.js index 2da176330..39986498e 100644 --- a/modules/zone/back/methods/zone/specs/toggleIsIncluded.spec.js +++ b/modules/zone/back/methods/zone/specs/toggleIsIncluded.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('zone toggleIsIncluded()', () => { beforeAll(async() => { - const activeCtx = { - accessToken: {userId: 9}, - http: { - req: { - headers: {origin: 'http://localhost'} - } - } - }; - spyOn(LoopBackContext, 'getCurrentContext').and.returnValue({ - active: activeCtx - }); + mockLoopBackContext(); }); it('should return the created location with isIncluded true', async() => { From 96366c475ad4b465108eca76401ac16e664ebf4c Mon Sep 17 00:00:00 2001 From: jorgep Date: Tue, 11 Jun 2024 10:48:28 +0200 Subject: [PATCH 17/61] fix: refs 6449 update changelog --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 6fc8cfc13..68868d17a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -22,6 +22,7 @@ - feat: refs #7438 Added volume to item_valuateInventory by:guillermo - feat: refs #7438 Requested changes and little changes by:guillermo - refs #6281 feat:buyFk in itemShelving by:sergiodt +- feat: refs #6449 item ID is displayed in the sale line by:jorgep ### Changed 📦 @@ -90,7 +91,6 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Fixed - (Worker -> time-control) Corrección de errores - (InvoiceOut -> Crear factura) Cuando falla al crear una factura, se devuelve un error -- (Ticket -> Logs) Ahora se muestra el id del item de la línea de venta - (Worker -> Ver albarán) Ya no aparece la página en blanco ### Changed From bd45352215ef383240669ccbfc4c16a6b5cf789b Mon Sep 17 00:00:00 2001 From: Jon Date: Tue, 11 Jun 2024 12:02:15 +0200 Subject: [PATCH 18/61] 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; From 665d03f0480601e3aa97d9f915b5cb66d902f015 Mon Sep 17 00:00:00 2001 From: Jon Date: Tue, 11 Jun 2024 12:35:44 +0200 Subject: [PATCH 19/61] refactor: refs #6436 user-config and some sections tests --- .../user-config/specs/getUserConfig.spec.js | 2 +- .../back/methods/client/specs/getCard.spec.js | 2 +- .../back/methods/client/specs/getDebt.spec.js | 2 +- .../back/methods/client/specs/sendSms.spec.js | 2 +- .../back/methods/client/specs/summary.spec.js | 2 +- .../methods/entry/specs/importBuysPreview.spec.js | 7 ++----- .../back/methods/invoiceOut/specs/book.spec.js | 2 +- .../methods/order-row/specs/addToOrder.spec.js | 2 +- .../order/back/methods/order/specs/filter.spec.js | 6 +----- modules/order/back/methods/order/specs/new.spec.js | 2 +- .../back/methods/order/specs/newFromTicket.spec.js | 2 +- .../specs/addExpeditionState.spec.js | 2 +- .../methods/sale/specs/recalculatePrice.spec.js | 3 +-- .../back/methods/sale/specs/updateConcept.spec.js | 7 +------ .../back/methods/ticket-request/specs/deny.spec.js | 14 ++------------ .../thermograph/specs/createThermograph.spec.js | 2 +- 16 files changed, 18 insertions(+), 41 deletions(-) diff --git a/back/methods/user-config/specs/getUserConfig.spec.js b/back/methods/user-config/specs/getUserConfig.spec.js index 8b510a706..c27018b07 100644 --- a/back/methods/user-config/specs/getUserConfig.spec.js +++ b/back/methods/user-config/specs/getUserConfig.spec.js @@ -1,12 +1,12 @@ const models = require('vn-loopback/server/server').models; describe('userConfig getUserConfig()', () => { + const {ctx} = beforeAll; it(`should return the configuration data of a given user`, async() => { const tx = await models.Item.beginTransaction({}); const options = {transaction: tx}; try { - const ctx = {req: {accessToken: {userId: 9}}}; const result = await models.UserConfig.getUserConfig(ctx, options); expect(result.warehouseFk).toEqual(1); diff --git a/modules/client/back/methods/client/specs/getCard.spec.js b/modules/client/back/methods/client/specs/getCard.spec.js index 962e0a2d4..1082b4009 100644 --- a/modules/client/back/methods/client/specs/getCard.spec.js +++ b/modules/client/back/methods/client/specs/getCard.spec.js @@ -1,11 +1,11 @@ const models = require('vn-loopback/server/server').models; describe('Client getCard()', () => { + const {ctx} = beforeAll; it('should receive a formated card of Bruce Wayne', async() => { const tx = await models.Client.beginTransaction({}); try { - const ctx = {req: {accessToken: {userId: 9}}}; const options = {transaction: tx}; const id = 1101; diff --git a/modules/client/back/methods/client/specs/getDebt.spec.js b/modules/client/back/methods/client/specs/getDebt.spec.js index b3b5286c0..7fc76ee94 100644 --- a/modules/client/back/methods/client/specs/getDebt.spec.js +++ b/modules/client/back/methods/client/specs/getDebt.spec.js @@ -1,9 +1,9 @@ const models = require('vn-loopback/server/server').models; describe('client getDebt()', () => { + const {ctx} = beforeAll; it('should return the client debt', async() => { const tx = await models.Client.beginTransaction({}); - const ctx = {req: {accessToken: {userId: 9}}}; try { const options = {transaction: tx}; diff --git a/modules/client/back/methods/client/specs/sendSms.spec.js b/modules/client/back/methods/client/specs/sendSms.spec.js index df680c55f..b6cb55062 100644 --- a/modules/client/back/methods/client/specs/sendSms.spec.js +++ b/modules/client/back/methods/client/specs/sendSms.spec.js @@ -1,12 +1,12 @@ const models = require('vn-loopback/server/server').models; describe('client sendSms()', () => { + const {ctx} = beforeAll; it('should now send a message and log it', async() => { const tx = await models.Client.beginTransaction({}); try { const options = {transaction: tx}; - const ctx = {req: {accessToken: {userId: 9}}}; const id = 1101; const destination = 222222222; const message = 'this is the message created in a test'; diff --git a/modules/client/back/methods/client/specs/summary.spec.js b/modules/client/back/methods/client/specs/summary.spec.js index 227f4c398..d15d183c6 100644 --- a/modules/client/back/methods/client/specs/summary.spec.js +++ b/modules/client/back/methods/client/specs/summary.spec.js @@ -1,7 +1,7 @@ const models = require('vn-loopback/server/server').models; describe('client summary()', () => { - const ctx = {req: {accessToken: {userId: 9}}}; + const {ctx} = beforeAll; it('should return a summary object containing data', async() => { const clientId = 1101; const tx = await models.Client.beginTransaction({}); diff --git a/modules/entry/back/methods/entry/specs/importBuysPreview.spec.js b/modules/entry/back/methods/entry/specs/importBuysPreview.spec.js index c860e228e..bab46ad59 100644 --- a/modules/entry/back/methods/entry/specs/importBuysPreview.spec.js +++ b/modules/entry/back/methods/entry/specs/importBuysPreview.spec.js @@ -1,13 +1,10 @@ const models = require('vn-loopback/server/server').models; -const LoopBackContext = require('loopback-context'); -const activeCtx = {accessToken: {userId: 9}}; +const {mockLoopBackContext} = require('vn-loopback/../../back/vn-jasmine'); describe('entry importBuysPreview()', () => { const entryId = 1; beforeAll(async() => { - spyOn(LoopBackContext, 'getCurrentContext').and.returnValue({ - active: activeCtx - }); + mockLoopBackContext(); }); it('should return the buys with the calculated packagingFk', async() => { diff --git a/modules/invoiceOut/back/methods/invoiceOut/specs/book.spec.js b/modules/invoiceOut/back/methods/invoiceOut/specs/book.spec.js index 3af7542ca..29e21a27c 100644 --- a/modules/invoiceOut/back/methods/invoiceOut/specs/book.spec.js +++ b/modules/invoiceOut/back/methods/invoiceOut/specs/book.spec.js @@ -1,7 +1,7 @@ const models = require('vn-loopback/server/server').models; describe('invoiceOut book()', () => { - const ctx = {req: {accessToken: {userId: 9}}}; + const {ctx} = beforeAll; const invoiceOutId = 5; it('should update the booked property', async() => { diff --git a/modules/order/back/methods/order-row/specs/addToOrder.spec.js b/modules/order/back/methods/order-row/specs/addToOrder.spec.js index 96544a1a9..327c86db0 100644 --- a/modules/order/back/methods/order-row/specs/addToOrder.spec.js +++ b/modules/order/back/methods/order-row/specs/addToOrder.spec.js @@ -1,7 +1,7 @@ const models = require('vn-loopback/server/server').models; describe('order addToOrder()', () => { - const ctx = {req: {accessToken: {userId: 9}}}; + const {ctx} = beforeAll; const orderId = 8; it('should add a row to a given order', async() => { const tx = await models.Order.beginTransaction({}); diff --git a/modules/order/back/methods/order/specs/filter.spec.js b/modules/order/back/methods/order/specs/filter.spec.js index 68de7fe04..95cb488c8 100644 --- a/modules/order/back/methods/order/specs/filter.spec.js +++ b/modules/order/back/methods/order/specs/filter.spec.js @@ -1,11 +1,7 @@ const models = require('vn-loopback/server/server').models; describe('order filter()', () => { - const ctx = { - req: {accessToken: {userId: 9}}, - args: {}, - params: {} - }; + const {ctx} = beforeAll; it('should call the filter method with a basic search', async() => { const myCtx = Object.assign({}, ctx); diff --git a/modules/order/back/methods/order/specs/new.spec.js b/modules/order/back/methods/order/specs/new.spec.js index c43527f66..6ed1fa4ae 100644 --- a/modules/order/back/methods/order/specs/new.spec.js +++ b/modules/order/back/methods/order/specs/new.spec.js @@ -2,7 +2,7 @@ const models = require('vn-loopback/server/server').models; const UserError = require('vn-loopback/util/user-error'); describe('order new()', () => { - const ctx = {req: {accessToken: {userId: 9}}}; + const {ctx} = beforeAll; it('should throw an error if the client isnt active', async() => { const tx = await models.Order.beginTransaction({}); diff --git a/modules/order/back/methods/order/specs/newFromTicket.spec.js b/modules/order/back/methods/order/specs/newFromTicket.spec.js index c509552fe..a592877cf 100644 --- a/modules/order/back/methods/order/specs/newFromTicket.spec.js +++ b/modules/order/back/methods/order/specs/newFromTicket.spec.js @@ -1,7 +1,7 @@ const models = require('vn-loopback/server/server').models; describe('order newFromTicket()', () => { - const ctx = {req: {accessToken: {userId: 9}}}; + const {ctx} = beforeAll; it('should create a new order from an existing ticket', async() => { const tx = await models.Order.beginTransaction({}); diff --git a/modules/ticket/back/methods/expedition-state/specs/addExpeditionState.spec.js b/modules/ticket/back/methods/expedition-state/specs/addExpeditionState.spec.js index 6c7739006..ce9049a95 100644 --- a/modules/ticket/back/methods/expedition-state/specs/addExpeditionState.spec.js +++ b/modules/ticket/back/methods/expedition-state/specs/addExpeditionState.spec.js @@ -1,7 +1,7 @@ const models = require('vn-loopback/server/server').models; describe('expeditionState addExpeditionState()', () => { - const ctx = {req: {accessToken: {userId: 9}}}; + const {ctx} = beforeAll; it('should update the expedition states', async() => { const tx = await models.ExpeditionState.beginTransaction({}); try { diff --git a/modules/ticket/back/methods/sale/specs/recalculatePrice.spec.js b/modules/ticket/back/methods/sale/specs/recalculatePrice.spec.js index 0fc68dee7..3c871dd6c 100644 --- a/modules/ticket/back/methods/sale/specs/recalculatePrice.spec.js +++ b/modules/ticket/back/methods/sale/specs/recalculatePrice.spec.js @@ -1,6 +1,7 @@ const models = require('vn-loopback/server/server').models; describe('sale recalculatePrice()', () => { + const {ctx} = beforeAll; it('should update the sale price', async() => { const tx = await models.Sale.beginTransaction({}); const sales = [ @@ -10,7 +11,6 @@ describe('sale recalculatePrice()', () => { try { const options = {transaction: tx}; - const ctx = {req: {accessToken: {userId: 9}}}; const response = await models.Sale.recalculatePrice(ctx, sales, options); expect(response[0].affectedRows).toBeDefined(); @@ -30,7 +30,6 @@ describe('sale recalculatePrice()', () => { try { const options = {transaction: tx}; - const ctx = {req: {accessToken: {userId: 9}}}; const immutableSale = [{id: 1, ticketFk: 1}]; await models.Sale.recalculatePrice(ctx, immutableSale, options); diff --git a/modules/ticket/back/methods/sale/specs/updateConcept.spec.js b/modules/ticket/back/methods/sale/specs/updateConcept.spec.js index 0610e9eab..be6ad77a3 100644 --- a/modules/ticket/back/methods/sale/specs/updateConcept.spec.js +++ b/modules/ticket/back/methods/sale/specs/updateConcept.spec.js @@ -1,12 +1,7 @@ const models = require('vn-loopback/server/server').models; -const {mockLoopBackContext} = require('vn-loopback/../../back/vn-jasmine'); describe('sale updateConcept()', () => { - beforeAll(async() => { - mockLoopBackContext(); - }); - - const ctx = {req: {accessToken: {userId: 9}}}; + const {ctx} = beforeAll; const saleId = 25; it('should throw if ID was undefined', async() => { diff --git a/modules/ticket/back/methods/ticket-request/specs/deny.spec.js b/modules/ticket/back/methods/ticket-request/specs/deny.spec.js index 875a75921..1259f1284 100644 --- a/modules/ticket/back/methods/ticket-request/specs/deny.spec.js +++ b/modules/ticket/back/methods/ticket-request/specs/deny.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-request deny()', () => { beforeAll(async() => { - const activeCtx = { - accessToken: {userId: 9}, - http: { - req: { - headers: {origin: 'http://localhost'} - } - } - }; - spyOn(LoopBackContext, 'getCurrentContext').and.returnValue({ - active: activeCtx - }); + mockLoopBackContext(); }); it('should return the denied ticket request', async() => { diff --git a/modules/travel/back/methods/thermograph/specs/createThermograph.spec.js b/modules/travel/back/methods/thermograph/specs/createThermograph.spec.js index 90855bf81..49eeb86c2 100644 --- a/modules/travel/back/methods/thermograph/specs/createThermograph.spec.js +++ b/modules/travel/back/methods/thermograph/specs/createThermograph.spec.js @@ -5,7 +5,7 @@ describe('Termograph createThermograph()', () => { const model = 'DISPOSABLE'; const temperatureFk = 'COOL'; const warehouseId = 1; - const ctx = {req: {accessToken: {userId: 9}}}; + const {ctx} = beforeAll; it(`should create a thermograph which is saved in both thermograph and travelThermograph`, async() => { const tx = await models.Thermograph.beginTransaction({}); From 944355d54f619ee0c14115e606d0bf443784b420 Mon Sep 17 00:00:00 2001 From: Jon Date: Tue, 11 Jun 2024 13:17:19 +0200 Subject: [PATCH 20/61] refactor: refs #6436 end first wave of changes in modules --- .../expedition/specs/moveExpeditions.spec.js | 14 +++----------- .../methods/ticket/specs/isEditableOrThrow.spec.js | 4 +--- .../ticket/back/methods/ticket/specs/merge.spec.js | 12 +----------- .../ticket/specs/recalculateComponents.spec.js | 3 +-- .../back/methods/ticket/specs/sendSms.spec.js | 2 +- .../back/methods/calendar/specs/absences.spec.js | 2 +- .../methods/department/specs/getLeaves.spec.js | 2 +- .../methods/worker/specs/mySubordinates.spec.js | 2 +- .../agency/specs/getAgenciesWithWarehouse.spec.js | 2 +- .../back/methods/agency/specs/landsThatDay.spec.js | 2 +- .../zone/back/methods/zone/specs/getEvents.spec.js | 2 +- .../zone/back/methods/zone/specs/getLeaves.spec.js | 2 +- .../zone/specs/getUpcomingDeliveries.spec.js | 2 +- 13 files changed, 15 insertions(+), 36 deletions(-) diff --git a/modules/ticket/back/methods/expedition/specs/moveExpeditions.spec.js b/modules/ticket/back/methods/expedition/specs/moveExpeditions.spec.js index 27b20bcd2..621992c5d 100644 --- a/modules/ticket/back/methods/expedition/specs/moveExpeditions.spec.js +++ b/modules/ticket/back/methods/expedition/specs/moveExpeditions.spec.js @@ -1,19 +1,11 @@ const models = require('vn-loopback/server/server').models; -const {mockLoopBackContext} = require('vn-loopback/../../back/vn-jasmine'); describe('ticket moveExpeditions()', () => { - beforeAll(async() => { - mockLoopBackContext(); - }); + const {ctx} = beforeAll; it('should move the selected expeditions to new ticket', async() => { const tx = await models.Expedition.beginTransaction({}); - const ctx = { - req: {accessToken: {userId: 9}}, - args: {}, - params: {} - }; - const myCtx = Object.assign({}, ctx); + const myCtx = ctx; try { const options = {transaction: tx}; @@ -28,7 +20,7 @@ describe('ticket moveExpeditions()', () => { }; - const ticket = await models.Expedition.moveExpeditions(myCtx, options); + const ticket = await models.Expedition.moveExpeditions(ctx, options); const newestTicketIdInFixtures = 27; diff --git a/modules/ticket/back/methods/ticket/specs/isEditableOrThrow.spec.js b/modules/ticket/back/methods/ticket/specs/isEditableOrThrow.spec.js index bdf547325..e78812bfe 100644 --- a/modules/ticket/back/methods/ticket/specs/isEditableOrThrow.spec.js +++ b/modules/ticket/back/methods/ticket/specs/isEditableOrThrow.spec.js @@ -1,14 +1,12 @@ const models = require('vn-loopback/server/server').models; describe('ticket isEditableOrThrow()', () => { + const {ctx} = beforeAll; it('should throw an error as the ticket does not exist', async() => { const tx = await models.Ticket.beginTransaction({}); let error; try { const options = {transaction: tx}; - const ctx = { - req: {accessToken: {userId: 9}} - }; await models.Ticket.isEditableOrThrow(ctx, 9999, options); await tx.rollback(); diff --git a/modules/ticket/back/methods/ticket/specs/merge.spec.js b/modules/ticket/back/methods/ticket/specs/merge.spec.js index 702b496af..21d4e5c75 100644 --- a/modules/ticket/back/methods/ticket/specs/merge.spec.js +++ b/modules/ticket/back/methods/ticket/specs/merge.spec.js @@ -1,7 +1,7 @@ const models = require('vn-loopback/server/server').models; -const {mockLoopBackContext} = require('vn-loopback/../../back/vn-jasmine'); describe('ticket merge()', () => { + const {ctx} = beforeAll; const tickets = { originId: 13, destinationId: 12, @@ -10,16 +10,6 @@ describe('ticket merge()', () => { workerFk: 1 }; - beforeAll(async() => { - mockLoopBackContext(); - }); - - const ctx = { - req: { - accessToken: {userId: 9}, - headers: {origin: 'http://localhost:5000'}, - } - }; ctx.req.__ = value => { return value; }; diff --git a/modules/ticket/back/methods/ticket/specs/recalculateComponents.spec.js b/modules/ticket/back/methods/ticket/specs/recalculateComponents.spec.js index d358a79f5..5c3811583 100644 --- a/modules/ticket/back/methods/ticket/specs/recalculateComponents.spec.js +++ b/modules/ticket/back/methods/ticket/specs/recalculateComponents.spec.js @@ -3,6 +3,7 @@ const ForbiddenError = require('vn-loopback/util/forbiddenError'); describe('ticket recalculateComponents()', () => { const ticketId = 11; + const {ctx} = beforeAll; it('should update the ticket components', async() => { const tx = await models.Ticket.beginTransaction({}); @@ -10,7 +11,6 @@ describe('ticket recalculateComponents()', () => { try { const options = {transaction: tx}; - const ctx = {req: {accessToken: {userId: 9}}}; const response = await models.Ticket.recalculateComponents(ctx, ticketId, options); expect(response.affectedRows).toBeDefined(); @@ -29,7 +29,6 @@ describe('ticket recalculateComponents()', () => { try { const options = {transaction: tx}; - const ctx = {req: {accessToken: {userId: 9}}}; const immutableTicketId = 1; await models.Ticket.recalculateComponents(ctx, immutableTicketId, options); diff --git a/modules/ticket/back/methods/ticket/specs/sendSms.spec.js b/modules/ticket/back/methods/ticket/specs/sendSms.spec.js index afc1ada54..b79e41d37 100644 --- a/modules/ticket/back/methods/ticket/specs/sendSms.spec.js +++ b/modules/ticket/back/methods/ticket/specs/sendSms.spec.js @@ -1,13 +1,13 @@ const models = require('vn-loopback/server/server').models; describe('ticket sendSms()', () => { + const {ctx} = beforeAll; it('should send a message and log it', async() => { const tx = await models.Ticket.beginTransaction({}); try { const options = {transaction: tx}; - const ctx = {req: {accessToken: {userId: 9}}}; const id = 11; const destination = 222222222; const message = 'this is the message created in a test'; diff --git a/modules/worker/back/methods/calendar/specs/absences.spec.js b/modules/worker/back/methods/calendar/specs/absences.spec.js index b27c9549c..0e6f21a5f 100644 --- a/modules/worker/back/methods/calendar/specs/absences.spec.js +++ b/modules/worker/back/methods/calendar/specs/absences.spec.js @@ -1,6 +1,7 @@ const app = require('vn-loopback/server/server'); describe('Worker absences()', () => { + const {ctx} = beforeAll; it('should get the absence calendar for a full year contract', async() => { const ctx = {req: {accessToken: {userId: 1106}}}; const workerId = 1106; @@ -20,7 +21,6 @@ describe('Worker absences()', () => { it('should get the absence calendar for a permanent contract', async() => { const businessId = 1106; - const ctx = {req: {accessToken: {userId: 9}}}; const now = Date.vnNew(); const year = now.getFullYear(); diff --git a/modules/worker/back/methods/department/specs/getLeaves.spec.js b/modules/worker/back/methods/department/specs/getLeaves.spec.js index fb7c84ff4..d7e934d20 100644 --- a/modules/worker/back/methods/department/specs/getLeaves.spec.js +++ b/modules/worker/back/methods/department/specs/getLeaves.spec.js @@ -1,7 +1,7 @@ const models = require('vn-loopback/server/server').models; describe('department getLeaves()', () => { - const ctx = {req: {accessToken: {userId: 9}}}; + const {ctx} = beforeAll; it('should return the department and the childs containing the search value', async() => { let result = await models.Department.getLeaves(ctx, null, 'INFORMATICA'); diff --git a/modules/worker/back/methods/worker/specs/mySubordinates.spec.js b/modules/worker/back/methods/worker/specs/mySubordinates.spec.js index 7eb118d9c..ecd668603 100644 --- a/modules/worker/back/methods/worker/specs/mySubordinates.spec.js +++ b/modules/worker/back/methods/worker/specs/mySubordinates.spec.js @@ -1,8 +1,8 @@ const app = require('vn-loopback/server/server'); describe('worker mySubordinates()', () => { + const {ctx} = beforeAll; it('should return an array of subordinates greather than 1', async() => { - let ctx = {req: {accessToken: {userId: 9}}}; let result = await app.models.Worker.mySubordinates(ctx); expect(result.length).toBeGreaterThan(1); diff --git a/modules/zone/back/methods/agency/specs/getAgenciesWithWarehouse.spec.js b/modules/zone/back/methods/agency/specs/getAgenciesWithWarehouse.spec.js index f760559cb..27a48a848 100644 --- a/modules/zone/back/methods/agency/specs/getAgenciesWithWarehouse.spec.js +++ b/modules/zone/back/methods/agency/specs/getAgenciesWithWarehouse.spec.js @@ -1,8 +1,8 @@ const app = require('vn-loopback/server/server'); describe('Agency getAgenciesWithWarehouse()', () => { + const {ctx} = beforeAll; const today = Date.vnNew(); - const ctx = {req: {accessToken: {userId: 9}}}; it('should return the agencies that can handle the given delivery request', async() => { const tx = await app.models.Zone.beginTransaction({}); diff --git a/modules/zone/back/methods/agency/specs/landsThatDay.spec.js b/modules/zone/back/methods/agency/specs/landsThatDay.spec.js index 1ec675071..27e71bc6f 100644 --- a/modules/zone/back/methods/agency/specs/landsThatDay.spec.js +++ b/modules/zone/back/methods/agency/specs/landsThatDay.spec.js @@ -1,7 +1,7 @@ const {models} = require('vn-loopback/server/server'); describe('Agency landsThatDay()', () => { - const ctx = {req: {accessToken: {userId: 9}}}; + const {ctx} = beforeAll; const today = Date.vnNew(); it('should return a list of agencies that can land a shipment on a day for an address', async() => { const tx = await models.Agency.beginTransaction({}); diff --git a/modules/zone/back/methods/zone/specs/getEvents.spec.js b/modules/zone/back/methods/zone/specs/getEvents.spec.js index c1dee3e0f..3c9dd76f2 100644 --- a/modules/zone/back/methods/zone/specs/getEvents.spec.js +++ b/modules/zone/back/methods/zone/specs/getEvents.spec.js @@ -1,7 +1,7 @@ const models = require('vn-loopback/server/server').models; describe('zone getEvents()', () => { - const ctx = {req: {accessToken: {userId: 9}}}; + const {ctx} = beforeAll; it('should return all events for the specified geo and agency mode', async() => { const tx = await models.Zone.beginTransaction({}); diff --git a/modules/zone/back/methods/zone/specs/getLeaves.spec.js b/modules/zone/back/methods/zone/specs/getLeaves.spec.js index 9342a0b50..4b8ab926c 100644 --- a/modules/zone/back/methods/zone/specs/getLeaves.spec.js +++ b/modules/zone/back/methods/zone/specs/getLeaves.spec.js @@ -1,7 +1,7 @@ const models = require('vn-loopback/server/server').models; describe('zone getLeaves()', () => { - const ctx = {req: {accessToken: {userId: 9}}}; + const {ctx} = beforeAll; it('should return the country and the childs containing the search value', async() => { const tx = await models.Zone.beginTransaction({}); diff --git a/modules/zone/back/methods/zone/specs/getUpcomingDeliveries.spec.js b/modules/zone/back/methods/zone/specs/getUpcomingDeliveries.spec.js index fe542fbf3..cf2a070f3 100644 --- a/modules/zone/back/methods/zone/specs/getUpcomingDeliveries.spec.js +++ b/modules/zone/back/methods/zone/specs/getUpcomingDeliveries.spec.js @@ -1,7 +1,7 @@ const models = require('vn-loopback/server/server').models; describe('zone getUpcomingDeliveries()', () => { - const ctx = {req: {accessToken: {userId: 9}}}; + const {ctx} = beforeAll; it('should check returns data', async() => { const tx = await models.Zone.beginTransaction({}); From 2b45c2c61a897562ee2e765d01ca7320e6246590 Mon Sep 17 00:00:00 2001 From: Jon Date: Wed, 12 Jun 2024 08:25:50 +0200 Subject: [PATCH 21/61] feat: refs #6436 new test changes, rollback order/filter and /ticket/clone --- .../methods/application/spec/execute.spec.js | 18 +++------------- .../entry/specs/addFromPackaging.spec.js | 16 +++----------- .../methods/invoice-in/specs/clone.spec.js | 21 +++++-------------- .../specs/getAlternative.spec.js | 7 ++----- .../methods/item/specs/regularize.spec.js | 14 ++----------- .../back/methods/order/specs/filter.spec.js | 6 +++++- .../supplier/specs/updateFiscalData.spec.js | 1 - .../specs/deleteExpeditions.spec.js | 6 ++---- .../back/methods/sale/specs/clone.spec.js | 19 ++++++++++++----- 9 files changed, 36 insertions(+), 72 deletions(-) diff --git a/loopback/common/methods/application/spec/execute.spec.js b/loopback/common/methods/application/spec/execute.spec.js index 1a0a8ace9..b697dbef9 100644 --- a/loopback/common/methods/application/spec/execute.spec.js +++ b/loopback/common/methods/application/spec/execute.spec.js @@ -2,18 +2,9 @@ const models = require('vn-loopback/server/server').models; describe('Application execute()/executeProc()/executeFunc()', () => { const userWithoutPrivileges = 1; - const userWithPrivileges = 9; const userWithInheritedPrivileges = 120; let tx; - - function getCtx(userId) { - return { - req: { - accessToken: {userId}, - headers: {origin: 'http://localhost'} - } - }; - } + const {ctx} = beforeAll; beforeEach(async() => { tx = await models.Application.beginTransaction({}); @@ -42,7 +33,7 @@ describe('Application execute()/executeProc()/executeFunc()', () => { }); it('should throw error when execute procedure and not have privileges', async() => { - const ctx = getCtx(userWithoutPrivileges); + const ctx = {req: {accessToken: {userId: userWithoutPrivileges}}}; let error; try { @@ -66,7 +57,6 @@ describe('Application execute()/executeProc()/executeFunc()', () => { }); it('should execute procedure and get data', async() => { - const ctx = getCtx(userWithPrivileges); try { const options = {transaction: tx}; @@ -90,7 +80,6 @@ describe('Application execute()/executeProc()/executeFunc()', () => { describe('Application executeProc()', () => { it('should execute procedure and get data (executeProc)', async() => { - const ctx = getCtx(userWithPrivileges); try { const options = {transaction: tx}; @@ -115,7 +104,6 @@ describe('Application execute()/executeProc()/executeFunc()', () => { describe('Application executeFunc()', () => { it('should execute function and get data', async() => { - const ctx = getCtx(userWithPrivileges); try { const options = {transaction: tx}; @@ -137,7 +125,7 @@ describe('Application execute()/executeProc()/executeFunc()', () => { }); it('should execute function and get data with user with inherited privileges', async() => { - const ctx = getCtx(userWithInheritedPrivileges); + const ctx = {req: {accessToken: {userId: userWithInheritedPrivileges}}}; try { const options = {transaction: tx}; diff --git a/modules/entry/back/methods/entry/specs/addFromPackaging.spec.js b/modules/entry/back/methods/entry/specs/addFromPackaging.spec.js index 1b0d4656f..21940d57e 100644 --- a/modules/entry/back/methods/entry/specs/addFromPackaging.spec.js +++ b/modules/entry/back/methods/entry/specs/addFromPackaging.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('entry addFromPackaging()', () => { const supplier = 442; @@ -8,21 +8,11 @@ describe('entry addFromPackaging()', () => { yesterday.setDate(today.getDate() - 1); beforeAll(async() => { - const activeCtx = { - accessToken: {userId: 49}, - http: { - req: { - headers: {origin: 'http://localhost'}, - }, - }, - }; - spyOn(LoopBackContext, 'getCurrentContext').and.returnValue({ - active: activeCtx, - }); + mockLoopBackContext(); }); it('should create an incoming travel', async() => { - const ctx = {args: {isTravelReception: true, supplier}}; + const ctx = {accessToken: {userId: 49}, args: {isTravelReception: true, supplier}}; const tx = await models.Entry.beginTransaction({}); const options = {transaction: tx}; diff --git a/modules/invoiceIn/back/methods/invoice-in/specs/clone.spec.js b/modules/invoiceIn/back/methods/invoice-in/specs/clone.spec.js index 436306aab..9fef506d4 100644 --- a/modules/invoiceIn/back/methods/invoice-in/specs/clone.spec.js +++ b/modules/invoiceIn/back/methods/invoice-in/specs/clone.spec.js @@ -1,24 +1,11 @@ const models = require('vn-loopback/server/server').models; -const LoopBackContext = require('loopback-context'); describe('invoiceIn clone()', () => { - let ctx; + const {ctx} = beforeAll; let options; let tx; beforeEach(async() => { - ctx = { - req: { - accessToken: {userId: 1}, - headers: {origin: 'http://localhost'} - }, - args: {} - }; - - spyOn(LoopBackContext, 'getCurrentContext').and.returnValue({ - active: ctx.req - }); - options = {transaction: tx}; tx = await models.Sale.beginTransaction({}); options.transaction = tx; @@ -28,7 +15,8 @@ describe('invoiceIn clone()', () => { await tx.rollback(); }); - it('should return the cloned invoiceIn and also clone invoiceInDueDays and invoiceInTaxes if there are any referencing the invoiceIn', async() => { + it('should return the cloned invoiceIn and also clone invoiceInDueDays ' + + 'and invoiceInTaxes if there are any referencing the invoiceIn', async() => { const clone = await models.InvoiceIn.clone(ctx, 1, false, options); expect(clone.supplierRef).toEqual('1234(2)'); @@ -51,7 +39,8 @@ describe('invoiceIn clone()', () => { expect(invoiceInDueDay.length).toEqual(2); }); - it('should return the cloned invoiceIn and also clone invoiceInIntrastat and invoiceInTaxes if it is rectificative', async() => { + it('should return the cloned invoiceIn and also clone invoiceInIntrastat ' + + 'and invoiceInTaxes if it is rectificative', async() => { const clone = await models.InvoiceIn.clone(ctx, 1, true, options); expect(clone.supplierRef).toEqual('1234(2)'); diff --git a/modules/item/back/methods/item-shelving/specs/getAlternative.spec.js b/modules/item/back/methods/item-shelving/specs/getAlternative.spec.js index 3f4917477..3082cabd1 100644 --- a/modules/item/back/methods/item-shelving/specs/getAlternative.spec.js +++ b/modules/item/back/methods/item-shelving/specs/getAlternative.spec.js @@ -1,12 +1,9 @@ const {models} = require('vn-loopback/server/server'); +const {mockLoopBackContext} = require('vn-loopback/../../back/vn-jasmine'); describe('itemShelving getAlternative()', () => { beforeAll(async() => { - ctx = { - req: { - headers: {origin: 'http://localhost'}, - } - }; + mockLoopBackContext(); }); it('should return a list of items without alternatives', async() => { diff --git a/modules/item/back/methods/item/specs/regularize.spec.js b/modules/item/back/methods/item/specs/regularize.spec.js index e7df9a003..b61dec995 100644 --- a/modules/item/back/methods/item/specs/regularize.spec.js +++ b/modules/item/back/methods/item/specs/regularize.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('regularize()', () => { beforeAll(async() => { - const activeCtx = { - accessToken: {userId: 18}, - http: { - req: { - headers: {origin: 'http://localhost'} - } - } - }; - spyOn(LoopBackContext, 'getCurrentContext').and.returnValue({ - active: activeCtx - }); + mockLoopBackContext(); }); it('should create a new ticket and add a line', async() => { diff --git a/modules/order/back/methods/order/specs/filter.spec.js b/modules/order/back/methods/order/specs/filter.spec.js index 95cb488c8..68de7fe04 100644 --- a/modules/order/back/methods/order/specs/filter.spec.js +++ b/modules/order/back/methods/order/specs/filter.spec.js @@ -1,7 +1,11 @@ const models = require('vn-loopback/server/server').models; describe('order filter()', () => { - const {ctx} = beforeAll; + const ctx = { + req: {accessToken: {userId: 9}}, + args: {}, + params: {} + }; it('should call the filter method with a basic search', async() => { const myCtx = Object.assign({}, ctx); diff --git a/modules/supplier/back/methods/supplier/specs/updateFiscalData.spec.js b/modules/supplier/back/methods/supplier/specs/updateFiscalData.spec.js index 7cb95f840..f1efbbbba 100644 --- a/modules/supplier/back/methods/supplier/specs/updateFiscalData.spec.js +++ b/modules/supplier/back/methods/supplier/specs/updateFiscalData.spec.js @@ -3,7 +3,6 @@ const LoopBackContext = require('loopback-context'); describe('Supplier updateFiscalData()', () => { const supplierId = 1; - const administrativeId = 5; const buyerId = 35; const name = 'NEW PLANTS'; diff --git a/modules/ticket/back/methods/expedition/specs/deleteExpeditions.spec.js b/modules/ticket/back/methods/expedition/specs/deleteExpeditions.spec.js index 2c34c994b..b72334142 100644 --- a/modules/ticket/back/methods/expedition/specs/deleteExpeditions.spec.js +++ b/modules/ticket/back/methods/expedition/specs/deleteExpeditions.spec.js @@ -1,10 +1,8 @@ const models = require('vn-loopback/server/server').models; -const {mockLoopBackContext} = require('vn-loopback/../../back/vn-jasmine'); +// const {mockLoopBackContext} = require('vn-loopback/../../back/vn-jasmine'); describe('ticket deleteExpeditions()', () => { - beforeAll(async() => { - mockLoopBackContext(); - }); + const {ctx} = beforeAll; it('should delete the selected expeditions', async() => { const tx = await models.Expedition.beginTransaction({}); diff --git a/modules/ticket/back/methods/sale/specs/clone.spec.js b/modules/ticket/back/methods/sale/specs/clone.spec.js index ef2c6a9a3..e2220c028 100644 --- a/modules/ticket/back/methods/sale/specs/clone.spec.js +++ b/modules/ticket/back/methods/sale/specs/clone.spec.js @@ -1,15 +1,24 @@ const models = require('vn-loopback/server/server').models; -const {mockLoopBackContext, mockBeforeAll} = require('vn-loopback/../../back/vn-jasmine'); +const LoopBackContext = require('loopback-context'); describe('Ticket cloning - clone function', () => { - let ctx = mockBeforeAll({ejemploe: true}); + let ctx; let options; let tx; - beforeAll(async() => { - mockLoopBackContext(); - }); beforeEach(async() => { + ctx = { + req: { + accessToken: {userId: 9}, + headers: {origin: 'http://localhost'} + }, + args: {} + }; + + spyOn(LoopBackContext, 'getCurrentContext').and.returnValue({ + active: ctx.req + }); + options = {transaction: tx}; tx = await models.Sale.beginTransaction({}); options.transaction = tx; From 84a51d3e8d0163ed7f83fa90d358922fc4366cc7 Mon Sep 17 00:00:00 2001 From: Jon Date: Wed, 12 Jun 2024 12:23:37 +0200 Subject: [PATCH 22/61] feat: refs #6436 changed tests --- back/methods/collection/spec/setSaleQuantity.spec.js | 6 +++--- back/tests.js | 11 +++++++++-- back/vn-jasmine.js | 2 ++ loopback/common/methods/vn-model/specs/crud.spec.js | 6 +++--- .../methods/vn-model/specs/rewriteDbError.spec.js | 6 +++--- .../back/methods/claim/specs/regularizeClaim.spec.js | 6 +++--- .../methods/claim/specs/updateClaimAction.spec.js | 6 +++--- .../methods/client/specs/addressesPropagateRe.spec.js | 9 +++++---- .../back/methods/client/specs/createAddress.spec.js | 6 +++--- .../back/methods/client/specs/createWithUser.spec.js | 6 +++--- .../back/methods/client/specs/updateAddress.spec.js | 6 +++--- modules/client/back/models/specs/address.spec.js | 6 +++--- .../back/methods/entry/specs/addFromPackaging.spec.js | 6 +++--- .../back/methods/entry/specs/editLatestBuys.spec.js | 6 +++--- .../methods/entry/specs/importBuysPreview.spec.js | 6 +++--- .../back/methods/invoice-in-due-day/specs/new.spec.js | 6 +++--- .../item-shelving/specs/getAlternative.spec.js | 6 +++--- modules/item/back/methods/item/specs/clone.spec.js | 6 +++--- .../item/back/methods/item/specs/regularize.spec.js | 6 +++--- .../item/back/methods/item/specs/updateTaxes.spec.js | 6 +++--- modules/item/back/methods/tag/specs/onSubmit.spec.js | 6 +++--- modules/order/back/methods/order/specs/filter.spec.js | 9 ++++----- .../methods/agency-term/specs/createInvoiceIn.spec.js | 1 - modules/route/back/methods/route/specs/clone.spec.js | 6 +++--- .../back/methods/route/specs/guessPriority.spec.js | 11 ----------- .../back/methods/route/specs/updateWorkCenter.spec.js | 6 +++--- .../expedition/specs/deleteExpeditions.spec.js | 1 - .../ticket/back/methods/sale/specs/canEdit.spec.js | 6 +++--- modules/ticket/back/methods/sale/specs/clone.spec.js | 1 - .../back/methods/sale/specs/deleteSales.spec.js | 6 +++--- .../ticket/back/methods/sale/specs/reserve.spec.js | 6 +++--- .../back/methods/ticket-request/specs/confirm.spec.js | 6 +++--- .../back/methods/ticket-request/specs/deny.spec.js | 6 +++--- .../back/methods/ticket/specs/updateDiscount.spec.js | 6 +++--- .../ticket/back/models/specs/ticket-packaging.spec.js | 6 +++--- .../methods/travel/specs/createThermograph.spec.js | 6 +++--- modules/worker/back/methods/worker/specs/new.spec.js | 6 +++--- modules/zone/back/methods/zone/specs/clone.spec.js | 6 +++--- .../zone/back/methods/zone/specs/exclusionGeo.spec.js | 6 +++--- .../back/methods/zone/specs/toggleIsIncluded.spec.js | 6 +++--- 40 files changed, 116 insertions(+), 121 deletions(-) diff --git a/back/methods/collection/spec/setSaleQuantity.spec.js b/back/methods/collection/spec/setSaleQuantity.spec.js index 7abcda36b..e26e25115 100644 --- a/back/methods/collection/spec/setSaleQuantity.spec.js +++ b/back/methods/collection/spec/setSaleQuantity.spec.js @@ -2,9 +2,9 @@ const models = require('vn-loopback/server/server').models; const {mockLoopBackContext} = require('vn-loopback/../../back/vn-jasmine'); describe('setSaleQuantity()', () => { - beforeAll(async() => { - mockLoopBackContext(); - }); + beforeAll(() => + mockLoopBackContext() + ); it('should change quantity sale', async() => { const tx = await models.Ticket.beginTransaction({}); diff --git a/back/tests.js b/back/tests.js index 2e89cfd05..bfbe9e681 100644 --- a/back/tests.js +++ b/back/tests.js @@ -84,7 +84,10 @@ async function test() { 'loopback/**/*[sS]pec.js', 'modules/*/back/**/*.[sS]pec.js' ], - helpers: [`back/vn-jasmine.js`] + helpers: [`back/vn-jasmine.js`], + asyncHelpers: {miHelperAsync + + } }; if (PARALLEL) { @@ -114,10 +117,14 @@ async function test() { if (opts.ci) runner.jasmine.DEFAULT_TIMEOUT_INTERVAL = SPEC_TIMEOUT; - // runner.loadConfigFile('back/jasmine.json'); runner.loadConfig(config); process.env.SPEC_IS_RUNNING = true; await runner.execute(); } test(); +function miHelperAsync() { + return new Promise((resolve, reject) => { + resolve('Resultado del helper'); + }); +} diff --git a/back/vn-jasmine.js b/back/vn-jasmine.js index 88dc55dc0..1c022637e 100644 --- a/back/vn-jasmine.js +++ b/back/vn-jasmine.js @@ -45,4 +45,6 @@ module.exports = { (function init() { vnBeforeAll(); + describe.$inject = () => { + }; })(); diff --git a/loopback/common/methods/vn-model/specs/crud.spec.js b/loopback/common/methods/vn-model/specs/crud.spec.js index d120db92a..a8923aed8 100644 --- a/loopback/common/methods/vn-model/specs/crud.spec.js +++ b/loopback/common/methods/vn-model/specs/crud.spec.js @@ -2,9 +2,9 @@ const app = require('vn-loopback/server/server'); const {mockLoopBackContext} = require('vn-loopback/../../back/vn-jasmine'); describe('Model crud()', () => { - beforeAll(async() => { - mockLoopBackContext(); - }); + beforeAll(() => + mockLoopBackContext() + ); let insertId; const barcodeModel = app.models.ItemBarcode; diff --git a/loopback/common/methods/vn-model/specs/rewriteDbError.spec.js b/loopback/common/methods/vn-model/specs/rewriteDbError.spec.js index e3c24e74a..d89508383 100644 --- a/loopback/common/methods/vn-model/specs/rewriteDbError.spec.js +++ b/loopback/common/methods/vn-model/specs/rewriteDbError.spec.js @@ -2,9 +2,9 @@ const models = require('vn-loopback/server/server').models; const {mockLoopBackContext} = require('vn-loopback/../../back/vn-jasmine'); describe('Model rewriteDbError()', () => { - beforeAll(async() => { - mockLoopBackContext(); - }); + beforeAll(() => + mockLoopBackContext() + ); it('should extend rewriteDbError properties to any model passed', () => { const exampleModel = models.ItemTag; diff --git a/modules/claim/back/methods/claim/specs/regularizeClaim.spec.js b/modules/claim/back/methods/claim/specs/regularizeClaim.spec.js index 224adc997..879979829 100644 --- a/modules/claim/back/methods/claim/specs/regularizeClaim.spec.js +++ b/modules/claim/back/methods/claim/specs/regularizeClaim.spec.js @@ -40,9 +40,9 @@ describe('claim regularizeClaim()', () => { return await models.ClaimEnd.create(claimEnds, options); } - beforeAll(async() => { - mockLoopBackContext(); - }); + beforeAll(() => + mockLoopBackContext() + ); it('should send a chat message with value "Trash" and then change claim state to resolved', async() => { const tx = await models.Claim.beginTransaction({}); diff --git a/modules/claim/back/methods/claim/specs/updateClaimAction.spec.js b/modules/claim/back/methods/claim/specs/updateClaimAction.spec.js index c939f59de..506c80abb 100644 --- a/modules/claim/back/methods/claim/specs/updateClaimAction.spec.js +++ b/modules/claim/back/methods/claim/specs/updateClaimAction.spec.js @@ -2,9 +2,9 @@ const app = require('vn-loopback/server/server'); const {mockLoopBackContext} = require('vn-loopback/../../back/vn-jasmine'); describe('Update Claim', () => { - beforeAll(async() => { - mockLoopBackContext(); - }); + beforeAll(() => + mockLoopBackContext() + ); const newDate = Date.vnNew(); const original = { ticketFk: 3, diff --git a/modules/client/back/methods/client/specs/addressesPropagateRe.spec.js b/modules/client/back/methods/client/specs/addressesPropagateRe.spec.js index ec4ebe471..be2732bdb 100644 --- a/modules/client/back/methods/client/specs/addressesPropagateRe.spec.js +++ b/modules/client/back/methods/client/specs/addressesPropagateRe.spec.js @@ -2,11 +2,12 @@ const models = require('vn-loopback/server/server').models; const {mockLoopBackContext} = require('vn-loopback/../../back/vn-jasmine'); describe('Client addressesPropagateRe', () => { - beforeAll(async() => { - mockLoopBackContext(); - }); + beforeAll(() => + mockLoopBackContext() + ); - it('should propagate the isEqualizated on both addresses of Mr Wayne and set hasToInvoiceByAddress to false', async() => { + it('should propagate the isEqualizated on both addresses of Mr Wayne' + + ' and set hasToInvoiceByAddress to false', async() => { const tx = await models.Client.beginTransaction({}); try { diff --git a/modules/client/back/methods/client/specs/createAddress.spec.js b/modules/client/back/methods/client/specs/createAddress.spec.js index 0556ce2cf..9c827a40e 100644 --- a/modules/client/back/methods/client/specs/createAddress.spec.js +++ b/modules/client/back/methods/client/specs/createAddress.spec.js @@ -7,9 +7,9 @@ describe('Address createAddress', () => { const incotermsFk = 'FAS'; const customAgentOneId = 1; - beforeAll(async() => { - mockLoopBackContext(); - }); + beforeAll(() => + mockLoopBackContext() + ); it('should throw a non uee member error if no incoterms is defined', async() => { const tx = await models.Client.beginTransaction({}); diff --git a/modules/client/back/methods/client/specs/createWithUser.spec.js b/modules/client/back/methods/client/specs/createWithUser.spec.js index cee8e0b38..47f2d34ce 100644 --- a/modules/client/back/methods/client/specs/createWithUser.spec.js +++ b/modules/client/back/methods/client/specs/createWithUser.spec.js @@ -16,9 +16,9 @@ describe('Client Create', () => { const newAccountWithoutEmail = JSON.parse(JSON.stringify(newAccount)); delete newAccountWithoutEmail.email; - beforeAll(async() => { - mockLoopBackContext(); - }); + beforeAll(() => + mockLoopBackContext() + ); it(`should not find deadpool as he's not created yet`, async() => { const tx = await models.Client.beginTransaction({}); diff --git a/modules/client/back/methods/client/specs/updateAddress.spec.js b/modules/client/back/methods/client/specs/updateAddress.spec.js index dd5142af0..d0c5e4d88 100644 --- a/modules/client/back/methods/client/specs/updateAddress.spec.js +++ b/modules/client/back/methods/client/specs/updateAddress.spec.js @@ -14,9 +14,9 @@ describe('Address updateAddress', () => { } }; - beforeAll(async() => { - mockLoopBackContext(); - }); + beforeAll(() => + mockLoopBackContext() + ); it('should throw the non uee member error if no incoterms is defined', async() => { const tx = await models.Client.beginTransaction({}); diff --git a/modules/client/back/models/specs/address.spec.js b/modules/client/back/models/specs/address.spec.js index 4baa1bdca..d390d045c 100644 --- a/modules/client/back/models/specs/address.spec.js +++ b/modules/client/back/models/specs/address.spec.js @@ -5,9 +5,9 @@ describe('loopback model address', () => { let createdAddressId; const clientId = 1101; - beforeAll(() => { - mockLoopBackContext(); - }); + beforeAll(() => + mockLoopBackContext() + ); afterAll(async() => { const client = await models.Client.findById(clientId); diff --git a/modules/entry/back/methods/entry/specs/addFromPackaging.spec.js b/modules/entry/back/methods/entry/specs/addFromPackaging.spec.js index 21940d57e..865e59bca 100644 --- a/modules/entry/back/methods/entry/specs/addFromPackaging.spec.js +++ b/modules/entry/back/methods/entry/specs/addFromPackaging.spec.js @@ -7,9 +7,9 @@ describe('entry addFromPackaging()', () => { const yesterday = new Date(today); yesterday.setDate(today.getDate() - 1); - beforeAll(async() => { - mockLoopBackContext(); - }); + beforeAll(() => + mockLoopBackContext() + ); it('should create an incoming travel', async() => { const ctx = {accessToken: {userId: 49}, args: {isTravelReception: true, supplier}}; diff --git a/modules/entry/back/methods/entry/specs/editLatestBuys.spec.js b/modules/entry/back/methods/entry/specs/editLatestBuys.spec.js index bff758eea..04c38078b 100644 --- a/modules/entry/back/methods/entry/specs/editLatestBuys.spec.js +++ b/modules/entry/back/methods/entry/specs/editLatestBuys.spec.js @@ -2,9 +2,9 @@ const models = require('vn-loopback/server/server').models; const {mockLoopBackContext} = require('vn-loopback/../../back/vn-jasmine'); describe('Buy editLatestsBuys()', () => { - beforeAll(async() => { - mockLoopBackContext(); - }); + beforeAll(() => + mockLoopBackContext() + ); it('should change the value of a given column for the selected buys', async() => { const tx = await models.Buy.beginTransaction({}); diff --git a/modules/entry/back/methods/entry/specs/importBuysPreview.spec.js b/modules/entry/back/methods/entry/specs/importBuysPreview.spec.js index bab46ad59..57adaf2dd 100644 --- a/modules/entry/back/methods/entry/specs/importBuysPreview.spec.js +++ b/modules/entry/back/methods/entry/specs/importBuysPreview.spec.js @@ -3,9 +3,9 @@ const {mockLoopBackContext} = require('vn-loopback/../../back/vn-jasmine'); describe('entry importBuysPreview()', () => { const entryId = 1; - beforeAll(async() => { - mockLoopBackContext(); - }); + beforeAll(() => + mockLoopBackContext() + ); it('should return the buys with the calculated packagingFk', async() => { const tx = await models.Entry.beginTransaction({}); diff --git a/modules/invoiceIn/back/methods/invoice-in-due-day/specs/new.spec.js b/modules/invoiceIn/back/methods/invoice-in-due-day/specs/new.spec.js index 02a43d4af..9a996d103 100644 --- a/modules/invoiceIn/back/methods/invoice-in-due-day/specs/new.spec.js +++ b/modules/invoiceIn/back/methods/invoice-in-due-day/specs/new.spec.js @@ -2,9 +2,9 @@ const models = require('vn-loopback/server/server').models; const {mockLoopBackContext} = require('vn-loopback/../../back/vn-jasmine'); describe('invoiceInDueDay new()', () => { - beforeAll(async() => { - mockLoopBackContext(); - }); + beforeAll(() => + mockLoopBackContext() + ); it('should correctly create a new due day', async() => { const userId = 9; diff --git a/modules/item/back/methods/item-shelving/specs/getAlternative.spec.js b/modules/item/back/methods/item-shelving/specs/getAlternative.spec.js index 3082cabd1..006842eca 100644 --- a/modules/item/back/methods/item-shelving/specs/getAlternative.spec.js +++ b/modules/item/back/methods/item-shelving/specs/getAlternative.spec.js @@ -2,9 +2,9 @@ const {models} = require('vn-loopback/server/server'); const {mockLoopBackContext} = require('vn-loopback/../../back/vn-jasmine'); describe('itemShelving getAlternative()', () => { - beforeAll(async() => { - mockLoopBackContext(); - }); + beforeAll(() => + mockLoopBackContext() + ); it('should return a list of items without alternatives', async() => { const shelvingFk = 'HEJ'; diff --git a/modules/item/back/methods/item/specs/clone.spec.js b/modules/item/back/methods/item/specs/clone.spec.js index 1a479cd84..e252c910c 100644 --- a/modules/item/back/methods/item/specs/clone.spec.js +++ b/modules/item/back/methods/item/specs/clone.spec.js @@ -3,9 +3,9 @@ const {mockLoopBackContext} = require('vn-loopback/../../back/vn-jasmine'); describe('item clone()', () => { let nextItemId; - beforeAll(async() => { - mockLoopBackContext(); - }); + beforeAll(() => + mockLoopBackContext() + ); beforeEach(async() => { let query = `SELECT i1.id + 1 as id FROM vn.item i1 diff --git a/modules/item/back/methods/item/specs/regularize.spec.js b/modules/item/back/methods/item/specs/regularize.spec.js index b61dec995..097d61d5c 100644 --- a/modules/item/back/methods/item/specs/regularize.spec.js +++ b/modules/item/back/methods/item/specs/regularize.spec.js @@ -2,9 +2,9 @@ const models = require('vn-loopback/server/server').models; const {mockLoopBackContext} = require('vn-loopback/../../back/vn-jasmine'); describe('regularize()', () => { - beforeAll(async() => { - mockLoopBackContext(); - }); + beforeAll(() => + mockLoopBackContext() + ); it('should create a new ticket and add a line', async() => { const tx = await models.Item.beginTransaction({}); diff --git a/modules/item/back/methods/item/specs/updateTaxes.spec.js b/modules/item/back/methods/item/specs/updateTaxes.spec.js index 49f95c1ed..3d0f1ce33 100644 --- a/modules/item/back/methods/item/specs/updateTaxes.spec.js +++ b/modules/item/back/methods/item/specs/updateTaxes.spec.js @@ -2,9 +2,9 @@ const models = require('vn-loopback/server/server').models; const {mockLoopBackContext} = require('vn-loopback/../../back/vn-jasmine'); describe('item updateTaxes()', () => { - beforeAll(async() => { - mockLoopBackContext(); - }); + beforeAll(() => + mockLoopBackContext() + ); it('should throw an error if the taxClassFk is blank', 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 1830aafcf..be77b0248 100644 --- a/modules/item/back/methods/tag/specs/onSubmit.spec.js +++ b/modules/item/back/methods/tag/specs/onSubmit.spec.js @@ -2,9 +2,9 @@ const models = require('vn-loopback/server/server').models; const {mockLoopBackContext} = require('vn-loopback/../../back/vn-jasmine'); describe('tag onSubmit()', () => { - beforeAll(async() => { - mockLoopBackContext(); - }); + beforeAll(() => + mockLoopBackContext() + ); it('should delete a tag', async() => { const tx = await models.Item.beginTransaction({}); diff --git a/modules/order/back/methods/order/specs/filter.spec.js b/modules/order/back/methods/order/specs/filter.spec.js index 68de7fe04..a2ec88577 100644 --- a/modules/order/back/methods/order/specs/filter.spec.js +++ b/modules/order/back/methods/order/specs/filter.spec.js @@ -1,11 +1,10 @@ +const {mockLoopBackContext} = require('../../../../../../back/vn-jasmine'); + const models = require('vn-loopback/server/server').models; describe('order filter()', () => { - const ctx = { - req: {accessToken: {userId: 9}}, - args: {}, - params: {} - }; + let ctx; + beforeAll(() => ctx = mockLoopBackContext()); it('should call the filter method with a basic search', async() => { const myCtx = Object.assign({}, ctx); 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 a625605d2..dbe9d0e1e 100644 --- a/modules/route/back/methods/agency-term/specs/createInvoiceIn.spec.js +++ b/modules/route/back/methods/agency-term/specs/createInvoiceIn.spec.js @@ -1,5 +1,4 @@ const models = require('vn-loopback/server/server').models; -// const LoopBackContext = require('loopback-context'); describe('AgencyTerm createInvoiceIn()', () => { const {ctx} = beforeAll; diff --git a/modules/route/back/methods/route/specs/clone.spec.js b/modules/route/back/methods/route/specs/clone.spec.js index 98240488c..b9ad7751c 100644 --- a/modules/route/back/methods/route/specs/clone.spec.js +++ b/modules/route/back/methods/route/specs/clone.spec.js @@ -2,9 +2,9 @@ const app = require('vn-loopback/server/server'); const {mockLoopBackContext} = require('vn-loopback/../../back/vn-jasmine'); describe('route clone()', () => { - beforeAll(async() => { - mockLoopBackContext(); - }); + beforeAll(() => + mockLoopBackContext() + ); const createdDate = Date.vnNew(); it('should throw an error if the amount of ids pased to the clone function do no match the database', async() => { diff --git a/modules/route/back/methods/route/specs/guessPriority.spec.js b/modules/route/back/methods/route/specs/guessPriority.spec.js index d73db6379..34fa510e1 100644 --- a/modules/route/back/methods/route/specs/guessPriority.spec.js +++ b/modules/route/back/methods/route/specs/guessPriority.spec.js @@ -1,18 +1,10 @@ const app = require('vn-loopback/server/server'); -// const LoopBackContext = require('loopback-context'); describe('route guessPriority()', () => { const targetRouteId = 7; let routeTicketsToRestore; - const {ctx} = beforeAll; - // beforeAll(() => { - // spyOn(LoopBackContext, 'getCurrentContext').and.returnValue({ - // active: activeCtx - // }); - // }); - afterAll(async() => { let restoreFixtures = []; routeTicketsToRestore.forEach(ticket => { @@ -22,9 +14,6 @@ describe('route guessPriority()', () => { }); it('should call guessPriority() then check all tickets in that route have their priorities defined', async() => { - // 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 315460d4a..4d5fbcbdc 100644 --- a/modules/route/back/methods/route/specs/updateWorkCenter.spec.js +++ b/modules/route/back/methods/route/specs/updateWorkCenter.spec.js @@ -2,9 +2,9 @@ const models = require('vn-loopback/server/server').models; const {mockLoopBackContext} = require('vn-loopback/../../back/vn-jasmine'); describe('route updateWorkCenter()', () => { - beforeAll(async() => { - mockLoopBackContext(); - }); + beforeAll(() => + mockLoopBackContext() + ); const routeId = 1; it('should set the commission work center if the worker has workCenter', async() => { diff --git a/modules/ticket/back/methods/expedition/specs/deleteExpeditions.spec.js b/modules/ticket/back/methods/expedition/specs/deleteExpeditions.spec.js index b72334142..4134b28b8 100644 --- a/modules/ticket/back/methods/expedition/specs/deleteExpeditions.spec.js +++ b/modules/ticket/back/methods/expedition/specs/deleteExpeditions.spec.js @@ -1,5 +1,4 @@ const models = require('vn-loopback/server/server').models; -// const {mockLoopBackContext} = require('vn-loopback/../../back/vn-jasmine'); describe('ticket deleteExpeditions()', () => { const {ctx} = beforeAll; diff --git a/modules/ticket/back/methods/sale/specs/canEdit.spec.js b/modules/ticket/back/methods/sale/specs/canEdit.spec.js index 3185b01e7..668b1c273 100644 --- a/modules/ticket/back/methods/sale/specs/canEdit.spec.js +++ b/modules/ticket/back/methods/sale/specs/canEdit.spec.js @@ -3,9 +3,9 @@ const {mockLoopBackContext} = require('vn-loopback/../../back/vn-jasmine'); describe('sale canEdit()', () => { const employeeId = 1; - beforeAll(async() => { - mockLoopBackContext(); - }); + beforeAll(() => + mockLoopBackContext() + ); describe('sale not exists', () => { it('should return error if sale not exists', async() => { diff --git a/modules/ticket/back/methods/sale/specs/clone.spec.js b/modules/ticket/back/methods/sale/specs/clone.spec.js index e2220c028..8767c2857 100644 --- a/modules/ticket/back/methods/sale/specs/clone.spec.js +++ b/modules/ticket/back/methods/sale/specs/clone.spec.js @@ -14,7 +14,6 @@ describe('Ticket cloning - clone function', () => { }, args: {} }; - spyOn(LoopBackContext, 'getCurrentContext').and.returnValue({ active: ctx.req }); diff --git a/modules/ticket/back/methods/sale/specs/deleteSales.spec.js b/modules/ticket/back/methods/sale/specs/deleteSales.spec.js index 8d0e4bd4e..8dc261b13 100644 --- a/modules/ticket/back/methods/sale/specs/deleteSales.spec.js +++ b/modules/ticket/back/methods/sale/specs/deleteSales.spec.js @@ -2,9 +2,9 @@ const models = require('vn-loopback/server/server').models; const {mockLoopBackContext} = require('vn-loopback/../../back/vn-jasmine'); describe('sale deleteSales()', () => { - beforeAll(async() => { - mockLoopBackContext(); - }); + beforeAll(() => + mockLoopBackContext() + ); it('should throw an error if the ticket of the given sales is not editable', async() => { const tx = await models.Sale.beginTransaction({}); diff --git a/modules/ticket/back/methods/sale/specs/reserve.spec.js b/modules/ticket/back/methods/sale/specs/reserve.spec.js index 37ebf10ab..009d7b711 100644 --- a/modules/ticket/back/methods/sale/specs/reserve.spec.js +++ b/modules/ticket/back/methods/sale/specs/reserve.spec.js @@ -10,9 +10,9 @@ describe('sale reserve()', () => { } }; - beforeAll(async() => { - mockLoopBackContext(); - }); + beforeAll(() => + mockLoopBackContext() + ); it('should throw an error if the ticket can not be modified', async() => { const tx = await models.Sale.beginTransaction({}); 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 8a1130e7d..396834df2 100644 --- a/modules/ticket/back/methods/ticket-request/specs/confirm.spec.js +++ b/modules/ticket/back/methods/ticket-request/specs/confirm.spec.js @@ -2,9 +2,9 @@ const models = require('vn-loopback/server/server').models; const {mockLoopBackContext} = require('vn-loopback/../../back/vn-jasmine'); describe('ticket-request confirm()', () => { - beforeAll(async() => { - mockLoopBackContext(); - }); + beforeAll(() => + mockLoopBackContext() + ); 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-request/specs/deny.spec.js b/modules/ticket/back/methods/ticket-request/specs/deny.spec.js index 1259f1284..aef07bd1b 100644 --- a/modules/ticket/back/methods/ticket-request/specs/deny.spec.js +++ b/modules/ticket/back/methods/ticket-request/specs/deny.spec.js @@ -2,9 +2,9 @@ const models = require('vn-loopback/server/server').models; const {mockLoopBackContext} = require('vn-loopback/../../back/vn-jasmine'); describe('ticket-request deny()', () => { - beforeAll(async() => { - mockLoopBackContext(); - }); + beforeAll(() => + mockLoopBackContext() + ); it('should return the denied ticket request', async() => { const tx = await models.TicketRequest.beginTransaction({}); diff --git a/modules/ticket/back/methods/ticket/specs/updateDiscount.spec.js b/modules/ticket/back/methods/ticket/specs/updateDiscount.spec.js index c0c5333ba..01e6e64bb 100644 --- a/modules/ticket/back/methods/ticket/specs/updateDiscount.spec.js +++ b/modules/ticket/back/methods/ticket/specs/updateDiscount.spec.js @@ -2,9 +2,9 @@ const models = require('vn-loopback/server/server').models; const {mockLoopBackContext} = require('vn-loopback/../../back/vn-jasmine'); describe('sale updateDiscount()', () => { - beforeAll(async() => { - mockLoopBackContext(); - }); + beforeAll(() => + mockLoopBackContext() + ); const originalSaleId = 8; it('should throw an error if no sales were selected', async() => { diff --git a/modules/ticket/back/models/specs/ticket-packaging.spec.js b/modules/ticket/back/models/specs/ticket-packaging.spec.js index 97a936018..7ff863cff 100644 --- a/modules/ticket/back/models/specs/ticket-packaging.spec.js +++ b/modules/ticket/back/models/specs/ticket-packaging.spec.js @@ -2,9 +2,9 @@ const app = require('vn-loopback/server/server'); const {mockLoopBackContext} = require('vn-loopback/../../back/vn-jasmine'); describe('ticket model TicketTracking', () => { - beforeAll(async() => { - mockLoopBackContext(); - }); + beforeAll(() => + mockLoopBackContext() + ); let ticketTrackingId; afterAll(async() => { diff --git a/modules/travel/back/methods/travel/specs/createThermograph.spec.js b/modules/travel/back/methods/travel/specs/createThermograph.spec.js index 9c93d6d52..2b0ae48f4 100644 --- a/modules/travel/back/methods/travel/specs/createThermograph.spec.js +++ b/modules/travel/back/methods/travel/specs/createThermograph.spec.js @@ -2,9 +2,9 @@ const models = require('vn-loopback/server/server').models; const {mockLoopBackContext} = require('vn-loopback/../../back/vn-jasmine'); describe('Travel createThermograph()', () => { - beforeAll(async() => { - mockLoopBackContext(); - }); + beforeAll(() => + mockLoopBackContext() + ); const travelId = 3; const currentUserId = 1102; const thermographId = '138350-0'; diff --git a/modules/worker/back/methods/worker/specs/new.spec.js b/modules/worker/back/methods/worker/specs/new.spec.js index b16efb16a..04540b9b7 100644 --- a/modules/worker/back/methods/worker/specs/new.spec.js +++ b/modules/worker/back/methods/worker/specs/new.spec.js @@ -10,9 +10,9 @@ describe('Worker new', () => { let tx; let opts; - beforeAll(async() => { - mockLoopBackContext(); - }); + beforeAll(() => + mockLoopBackContext() + ); describe('should return error', () => { beforeEach(async() => { diff --git a/modules/zone/back/methods/zone/specs/clone.spec.js b/modules/zone/back/methods/zone/specs/clone.spec.js index 465abdc9c..292aeb2ac 100644 --- a/modules/zone/back/methods/zone/specs/clone.spec.js +++ b/modules/zone/back/methods/zone/specs/clone.spec.js @@ -2,9 +2,9 @@ const models = require('vn-loopback/server/server').models; const {mockLoopBackContext} = require('vn-loopback/../../back/vn-jasmine'); describe('agency clone()', () => { - beforeAll(async() => { - mockLoopBackContext(); - }); + beforeAll(() => + mockLoopBackContext() + ); it('should clone a zone', async() => { const tx = await models.Zone.beginTransaction({}); diff --git a/modules/zone/back/methods/zone/specs/exclusionGeo.spec.js b/modules/zone/back/methods/zone/specs/exclusionGeo.spec.js index 746be502f..dc2eeb8a8 100644 --- a/modules/zone/back/methods/zone/specs/exclusionGeo.spec.js +++ b/modules/zone/back/methods/zone/specs/exclusionGeo.spec.js @@ -2,9 +2,9 @@ const models = require('vn-loopback/server/server').models; const {mockLoopBackContext} = require('vn-loopback/../../back/vn-jasmine'); describe('zone exclusionGeo()', () => { - beforeAll(async() => { - mockLoopBackContext(); - }); + beforeAll(() => + mockLoopBackContext() + ); const zoneId = 1; const today = Date.vnNew(); diff --git a/modules/zone/back/methods/zone/specs/toggleIsIncluded.spec.js b/modules/zone/back/methods/zone/specs/toggleIsIncluded.spec.js index 39986498e..480c8b7ef 100644 --- a/modules/zone/back/methods/zone/specs/toggleIsIncluded.spec.js +++ b/modules/zone/back/methods/zone/specs/toggleIsIncluded.spec.js @@ -2,9 +2,9 @@ const models = require('vn-loopback/server/server').models; const {mockLoopBackContext} = require('vn-loopback/../../back/vn-jasmine'); describe('zone toggleIsIncluded()', () => { - beforeAll(async() => { - mockLoopBackContext(); - }); + beforeAll(() => + mockLoopBackContext() + ); it('should return the created location with isIncluded true', async() => { const tx = await models.Zone.beginTransaction({}); From 324d7ef7aecc40664e8808436c0224edde59bf94 Mon Sep 17 00:00:00 2001 From: Jon Date: Wed, 12 Jun 2024 14:54:43 +0200 Subject: [PATCH 23/61] refactor: refs #6436 changed test config --- back/tests.js | 8 -------- back/vn-jasmine.js | 2 -- 2 files changed, 10 deletions(-) diff --git a/back/tests.js b/back/tests.js index bfbe9e681..2527367c2 100644 --- a/back/tests.js +++ b/back/tests.js @@ -85,9 +85,6 @@ async function test() { 'modules/*/back/**/*.[sS]pec.js' ], helpers: [`back/vn-jasmine.js`], - asyncHelpers: {miHelperAsync - - } }; if (PARALLEL) { @@ -123,8 +120,3 @@ async function test() { } test(); -function miHelperAsync() { - return new Promise((resolve, reject) => { - resolve('Resultado del helper'); - }); -} diff --git a/back/vn-jasmine.js b/back/vn-jasmine.js index 1c022637e..88dc55dc0 100644 --- a/back/vn-jasmine.js +++ b/back/vn-jasmine.js @@ -45,6 +45,4 @@ module.exports = { (function init() { vnBeforeAll(); - describe.$inject = () => { - }; })(); From 61a588b57c35264508078ca61d5cc4bd04675678 Mon Sep 17 00:00:00 2001 From: Jon Date: Fri, 14 Jun 2024 08:39:57 +0200 Subject: [PATCH 24/61] refactor: refs #6436 fixed test --- back/methods/collection/spec/getSales.spec.js | 2 +- .../collection/spec/getTickets.spec.js | 2 +- .../collection/spec/setSaleQuantity.spec.js | 5 +- .../specs/getStarredModules.spec.js | 2 +- .../starred-module/specs/setPosition.spec.js | 2 +- .../specs/toggleStarredModule.spec.js | 2 +- .../user-config/specs/getUserConfig.spec.js | 2 +- back/models/specs/mailAliasAccount.spec.js | 5 +- back/vn-jasmine.js | 50 ++++++++------- .../methods/application/spec/execute.spec.js | 2 +- .../methods/vn-model/specs/crud.spec.js | 5 +- .../vn-model/specs/rewriteDbError.spec.js | 5 +- .../back/methods/claim/specs/filter.spec.js | 2 +- .../claim/specs/regularizeClaim.spec.js | 13 +--- .../methods/claim/specs/updateClaim.spec.js | 3 +- .../claim/specs/updateClaimAction.spec.js | 5 +- .../client/specs/addressesPropagateRe.spec.js | 5 +- .../client/specs/createAddress.spec.js | 5 +- .../client/specs/createWithUser.spec.js | 6 +- .../back/methods/client/specs/getCard.spec.js | 2 +- .../back/methods/client/specs/getDebt.spec.js | 2 +- .../back/methods/client/specs/sendSms.spec.js | 2 +- .../back/methods/client/specs/summary.spec.js | 2 +- .../client/specs/updateAddress.spec.js | 6 +- .../client/back/models/specs/address.spec.js | 5 +- .../entry/specs/addFromPackaging.spec.js | 5 +- .../entry/specs/editLatestBuys.spec.js | 5 +- .../entry/specs/importBuysPreview.spec.js | 5 +- .../invoice-in-due-day/specs/new.spec.js | 5 +- .../methods/invoice-in/specs/clone.spec.js | 2 +- .../invoice-in/specs/corrective.spec.js | 2 +- .../methods/invoiceOut/specs/book.spec.js | 2 +- .../specs/upsertFixedPrice.spec.js | 3 +- .../specs/getAlternative.spec.js | 5 +- .../item-shelving/specs/upsertItem.spec.js | 2 +- .../back/methods/item/specs/clone.spec.js | 5 +- .../methods/item/specs/getBalance.spec.js | 2 +- .../item/back/methods/item/specs/new.spec.js | 2 +- .../methods/item/specs/regularize.spec.js | 6 +- .../methods/item/specs/updateTaxes.spec.js | 5 +- .../back/methods/tag/specs/onSubmit.spec.js | 5 +- .../order-row/specs/addToOrder.spec.js | 2 +- .../back/methods/order/specs/filter.spec.js | 5 +- .../back/methods/order/specs/new.spec.js | 2 +- .../methods/order/specs/newFromTicket.spec.js | 2 +- .../agency-term/specs/createInvoiceIn.spec.js | 2 +- .../back/methods/route/specs/clone.spec.js | 5 +- .../methods/route/specs/guessPriority.spec.js | 2 +- .../route/specs/updateWorkCenter.spec.js | 5 +- .../supplier/specs/consumption.spec.js | 2 +- .../back/models/specs/supplier.spec.js | 3 +- .../specs/addExpeditionState.spec.js | 2 +- .../specs/deleteExpeditions.spec.js | 2 +- .../expedition/specs/moveExpeditions.spec.js | 2 +- .../back/methods/sale/specs/canEdit.spec.js | 5 +- .../back/methods/sale/specs/clone.spec.js | 16 +---- .../methods/sale/specs/deleteSales.spec.js | 21 +------ .../sale/specs/recalculatePrice.spec.js | 2 +- .../back/methods/sale/specs/reserve.spec.js | 5 +- .../methods/sale/specs/updateConcept.spec.js | 2 +- .../ticket-request/specs/confirm.spec.js | 6 +- .../methods/ticket-request/specs/deny.spec.js | 20 +----- .../back/methods/ticket/specs/clone.spec.js | 2 +- .../ticket/specs/componentUpdate.spec.js | 63 +++---------------- .../back/methods/ticket/specs/filter.spec.js | 51 ++++++++++----- .../ticket/specs/getTicketsAdvance.spec.js | 11 ++-- .../ticket/specs/getTicketsFuture.spec.js | 25 ++++---- .../ticket/specs/isEditableOrThrow.spec.js | 2 +- .../back/methods/ticket/specs/merge.spec.js | 6 +- .../specs/recalculateComponents.spec.js | 2 +- .../back/methods/ticket/specs/sendSms.spec.js | 2 +- .../methods/ticket/specs/setDeleted.spec.js | 42 +------------ .../back/methods/ticket/specs/state.spec.js | 22 +++---- .../ticket/specs/transferClient.spec.js | 2 +- .../ticket/specs/updateDiscount.spec.js | 50 ++------------- .../models/specs/ticket-packaging.spec.js | 5 +- modules/ticket/back/models/ticket-request.js | 2 +- .../specs/createThermograph.spec.js | 2 +- .../travel/specs/createThermograph.spec.js | 5 +- .../methods/calendar/specs/absences.spec.js | 2 +- .../department/specs/getLeaves.spec.js | 2 +- .../worker/specs/createAbsence.spec.js | 3 +- .../worker/specs/mySubordinates.spec.js | 2 +- .../back/methods/worker/specs/new.spec.js | 5 +- .../specs/getAgenciesWithWarehouse.spec.js | 2 +- .../methods/agency/specs/landsThatDay.spec.js | 2 +- .../back/methods/zone/specs/clone.spec.js | 5 +- .../methods/zone/specs/exclusionGeo.spec.js | 5 +- .../back/methods/zone/specs/getEvents.spec.js | 2 +- .../back/methods/zone/specs/getLeaves.spec.js | 2 +- .../zone/specs/getUpcomingDeliveries.spec.js | 2 +- .../zone/specs/toggleIsIncluded.spec.js | 5 +- 92 files changed, 197 insertions(+), 452 deletions(-) diff --git a/back/methods/collection/spec/getSales.spec.js b/back/methods/collection/spec/getSales.spec.js index f276d07d0..520657ec1 100644 --- a/back/methods/collection/spec/getSales.spec.js +++ b/back/methods/collection/spec/getSales.spec.js @@ -4,7 +4,7 @@ describe('collection getSales()', () => { const collectionOrTicketFk = 999999; const print = true; const source = 'CHECKER'; - const {ctx} = beforeAll; + const ctx = beforeAll.getCtx(); it('should return a collection with tickets, placements and barcodes settled correctly', async() => { const tx = await models.Collection.beginTransaction({}); diff --git a/back/methods/collection/spec/getTickets.spec.js b/back/methods/collection/spec/getTickets.spec.js index c066ead8c..646f44223 100644 --- a/back/methods/collection/spec/getTickets.spec.js +++ b/back/methods/collection/spec/getTickets.spec.js @@ -1,7 +1,7 @@ const models = require('vn-loopback/server/server').models; describe('collection getTickets()', () => { - const {ctx} = beforeAll; + const ctx = beforeAll.getCtx(); it('should get tickets, sales and barcodes from collection', async() => { const tx = await models.Collection.beginTransaction({}); diff --git a/back/methods/collection/spec/setSaleQuantity.spec.js b/back/methods/collection/spec/setSaleQuantity.spec.js index e26e25115..00ddae0fe 100644 --- a/back/methods/collection/spec/setSaleQuantity.spec.js +++ b/back/methods/collection/spec/setSaleQuantity.spec.js @@ -1,10 +1,7 @@ const models = require('vn-loopback/server/server').models; -const {mockLoopBackContext} = require('vn-loopback/../../back/vn-jasmine'); describe('setSaleQuantity()', () => { - beforeAll(() => - mockLoopBackContext() - ); + beforeAll.mockLoopBackContext(); it('should change quantity sale', async() => { const tx = await models.Ticket.beginTransaction({}); diff --git a/back/methods/starred-module/specs/getStarredModules.spec.js b/back/methods/starred-module/specs/getStarredModules.spec.js index cce353f93..afe1dd9c2 100644 --- a/back/methods/starred-module/specs/getStarredModules.spec.js +++ b/back/methods/starred-module/specs/getStarredModules.spec.js @@ -1,7 +1,7 @@ const {models} = require('vn-loopback/server/server'); describe('getStarredModules()', () => { - const {ctx} = beforeAll; + const ctx = beforeAll.getCtx(); it(`should return the starred modules for a given user`, async() => { const newStarred = await models.StarredModule.create({workerFk: 9, moduleFk: 'customer', position: 1}); diff --git a/back/methods/starred-module/specs/setPosition.spec.js b/back/methods/starred-module/specs/setPosition.spec.js index 495bc8384..c99206e56 100644 --- a/back/methods/starred-module/specs/setPosition.spec.js +++ b/back/methods/starred-module/specs/setPosition.spec.js @@ -1,7 +1,7 @@ const {models} = require('vn-loopback/server/server'); describe('setPosition()', () => { - const {ctx} = beforeAll; + const ctx = beforeAll.getCtx(); 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 d5a5c8ab3..d506abc33 100644 --- a/back/methods/starred-module/specs/toggleStarredModule.spec.js +++ b/back/methods/starred-module/specs/toggleStarredModule.spec.js @@ -1,7 +1,7 @@ const {models} = require('vn-loopback/server/server'); describe('toggleStarredModule()', () => { - const {ctx} = beforeAll; + const ctx = beforeAll.getCtx(); 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'); diff --git a/back/methods/user-config/specs/getUserConfig.spec.js b/back/methods/user-config/specs/getUserConfig.spec.js index c27018b07..bbfb98ef7 100644 --- a/back/methods/user-config/specs/getUserConfig.spec.js +++ b/back/methods/user-config/specs/getUserConfig.spec.js @@ -1,7 +1,7 @@ const models = require('vn-loopback/server/server').models; describe('userConfig getUserConfig()', () => { - const {ctx} = beforeAll; + const ctx = beforeAll.getCtx(); it(`should return the configuration data of a given user`, async() => { const tx = await models.Item.beginTransaction({}); const options = {transaction: tx}; diff --git a/back/models/specs/mailAliasAccount.spec.js b/back/models/specs/mailAliasAccount.spec.js index 8f0278a50..0f4cbdbb1 100644 --- a/back/models/specs/mailAliasAccount.spec.js +++ b/back/models/specs/mailAliasAccount.spec.js @@ -1,12 +1,13 @@ const models = require('vn-loopback/server/server').models; describe('loopback model MailAliasAccount', () => { + const ctx = beforeAll.getCtx(); it('should add a mail Alias', async() => { const tx = await models.MailAliasAccount.beginTransaction({}); let error; try { - const options = {transaction: tx, accessToken: {userId: 9}}; + const options = {transaction: tx, ctx}; await models.MailAliasAccount.create({mailAlias: 2, account: 5}, options); await tx.rollback(); @@ -23,7 +24,7 @@ describe('loopback model MailAliasAccount', () => { let error; try { - const options = {transaction: tx, accessToken: {userId: 9}}; + const options = {transaction: tx, ctx}; await models.MailAliasAccount.create({mailAlias: 3, account: 5}, options); await tx.rollback(); diff --git a/back/vn-jasmine.js b/back/vn-jasmine.js index 88dc55dc0..c2d8a497c 100644 --- a/back/vn-jasmine.js +++ b/back/vn-jasmine.js @@ -1,41 +1,47 @@ const LoopBackContext = require('loopback-context'); -const DEFAULT_ACCESS_TOKEN = {accessToken: {userId: 9}}; +const getAccessToken = (userId = 9) => { + return {accessToken: {userId}}; +}; const DEFAULT_HEADERS = {headers: {origin: 'http://localhost'}}; -const DEFAULT_BEFORE_ALL = { - ctx: { +const default_before_all = userId => { + return { req: { - ...DEFAULT_ACCESS_TOKEN, - ...DEFAULT_HEADERS + ...getAccessToken(userId), + ...DEFAULT_HEADERS, + ...{__: value => value} }, args: {} - } + }; }; -const DEFAULT_LOOPBACK_CTX = { - ...DEFAULT_ACCESS_TOKEN, - http: { - req: { - ...DEFAULT_HEADERS - } - }, - args: {} +const default_loopback_ctx = userId => { + return { + ...getAccessToken(userId), + ...default_before_all(userId), + http: { + ...default_before_all(userId) + }, + args: {} + }; }; -function vnBeforeAll(value = DEFAULT_BEFORE_ALL) { - Object.assign(beforeAll, value); +function vnBeforeAll() { + Object.assign(beforeAll, {getCtx: default_before_all}); + Object.assign(beforeAll, {mockLoopBackContext}); } -function mockBeforeAll(value = DEFAULT_BEFORE_ALL) { +function mockBeforeAll(value = default_before_all) { const origin = beforeAll.ctx; Object.assign(origin, value); return origin; } -const mockLoopBackContext = (value = DEFAULT_LOOPBACK_CTX) => { - const activeCtx = value; - - spyOn(LoopBackContext, 'getCurrentContext').and.returnValue({ - active: activeCtx +const mockLoopBackContext = userId => { + const activeCtx = default_loopback_ctx(userId); + beforeAll(() => { + spyOn(LoopBackContext, 'getCurrentContext').and.returnValue({ + active: activeCtx + }); }); return activeCtx; }; diff --git a/loopback/common/methods/application/spec/execute.spec.js b/loopback/common/methods/application/spec/execute.spec.js index b697dbef9..ca4efd9cc 100644 --- a/loopback/common/methods/application/spec/execute.spec.js +++ b/loopback/common/methods/application/spec/execute.spec.js @@ -4,7 +4,7 @@ describe('Application execute()/executeProc()/executeFunc()', () => { const userWithoutPrivileges = 1; const userWithInheritedPrivileges = 120; let tx; - const {ctx} = beforeAll; + const ctx = beforeAll.getCtx(); beforeEach(async() => { tx = await models.Application.beginTransaction({}); diff --git a/loopback/common/methods/vn-model/specs/crud.spec.js b/loopback/common/methods/vn-model/specs/crud.spec.js index a8923aed8..28b256ad8 100644 --- a/loopback/common/methods/vn-model/specs/crud.spec.js +++ b/loopback/common/methods/vn-model/specs/crud.spec.js @@ -1,10 +1,7 @@ const app = require('vn-loopback/server/server'); -const {mockLoopBackContext} = require('vn-loopback/../../back/vn-jasmine'); describe('Model crud()', () => { - beforeAll(() => - mockLoopBackContext() - ); + beforeAll.mockLoopBackContext(); let insertId; const barcodeModel = app.models.ItemBarcode; diff --git a/loopback/common/methods/vn-model/specs/rewriteDbError.spec.js b/loopback/common/methods/vn-model/specs/rewriteDbError.spec.js index d89508383..84c0784c9 100644 --- a/loopback/common/methods/vn-model/specs/rewriteDbError.spec.js +++ b/loopback/common/methods/vn-model/specs/rewriteDbError.spec.js @@ -1,10 +1,7 @@ const models = require('vn-loopback/server/server').models; -const {mockLoopBackContext} = require('vn-loopback/../../back/vn-jasmine'); describe('Model rewriteDbError()', () => { - beforeAll(() => - mockLoopBackContext() - ); + beforeAll.mockLoopBackContext(); it('should extend rewriteDbError properties to any model passed', () => { const exampleModel = models.ItemTag; diff --git a/modules/claim/back/methods/claim/specs/filter.spec.js b/modules/claim/back/methods/claim/specs/filter.spec.js index b55e554b9..1ef808e9d 100644 --- a/modules/claim/back/methods/claim/specs/filter.spec.js +++ b/modules/claim/back/methods/claim/specs/filter.spec.js @@ -2,7 +2,7 @@ const app = require('vn-loopback/server/server'); const models = require('vn-loopback/server/server').models; describe('claim filter()', () => { - const {ctx} = beforeAll; + const ctx = beforeAll.getCtx(); 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 879979829..55d76ed7a 100644 --- a/modules/claim/back/methods/claim/specs/regularizeClaim.spec.js +++ b/modules/claim/back/methods/claim/specs/regularizeClaim.spec.js @@ -1,18 +1,11 @@ const models = require('vn-loopback/server/server').models; -const {mockLoopBackContext} = require('vn-loopback/../../back/vn-jasmine'); describe('claim regularizeClaim()', () => { const userId = 18; - const ctx = { - req: { - accessToken: {userId: userId}, - headers: {origin: 'http://localhost'} - } - }; + const ctx = beforeAll.mockLoopBackContext(userId); ctx.req.__ = (value, params) => { return params.nickname; }; - const chatModel = models.Chat; const claimId = 1; const ticketId = 1; @@ -40,10 +33,6 @@ describe('claim regularizeClaim()', () => { return await models.ClaimEnd.create(claimEnds, options); } - beforeAll(() => - mockLoopBackContext() - ); - it('should send a chat message with value "Trash" and then change claim state to resolved', async() => { const tx = await models.Claim.beginTransaction({}); diff --git a/modules/claim/back/methods/claim/specs/updateClaim.spec.js b/modules/claim/back/methods/claim/specs/updateClaim.spec.js index 5c8f08132..e1eec59d1 100644 --- a/modules/claim/back/methods/claim/specs/updateClaim.spec.js +++ b/modules/claim/back/methods/claim/specs/updateClaim.spec.js @@ -1,11 +1,10 @@ const app = require('vn-loopback/server/server'); -const {mockLoopBackContext} = require('vn-loopback/../../back/vn-jasmine'); const i18n = require('i18n'); describe('Update Claim', () => { let url; let claimStatesMap = {}; + beforeAll.mockLoopBackContext(); beforeAll(async() => { - 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 506c80abb..bc081ed08 100644 --- a/modules/claim/back/methods/claim/specs/updateClaimAction.spec.js +++ b/modules/claim/back/methods/claim/specs/updateClaimAction.spec.js @@ -1,10 +1,7 @@ const app = require('vn-loopback/server/server'); -const {mockLoopBackContext} = require('vn-loopback/../../back/vn-jasmine'); describe('Update Claim', () => { - beforeAll(() => - mockLoopBackContext() - ); + beforeAll.mockLoopBackContext(); const newDate = Date.vnNew(); const original = { ticketFk: 3, diff --git a/modules/client/back/methods/client/specs/addressesPropagateRe.spec.js b/modules/client/back/methods/client/specs/addressesPropagateRe.spec.js index be2732bdb..1a186f93c 100644 --- a/modules/client/back/methods/client/specs/addressesPropagateRe.spec.js +++ b/modules/client/back/methods/client/specs/addressesPropagateRe.spec.js @@ -1,10 +1,7 @@ const models = require('vn-loopback/server/server').models; -const {mockLoopBackContext} = require('vn-loopback/../../back/vn-jasmine'); describe('Client addressesPropagateRe', () => { - beforeAll(() => - mockLoopBackContext() - ); + beforeAll.mockLoopBackContext(); it('should propagate the isEqualizated on both addresses of Mr Wayne' + ' and set hasToInvoiceByAddress to false', async() => { diff --git a/modules/client/back/methods/client/specs/createAddress.spec.js b/modules/client/back/methods/client/specs/createAddress.spec.js index 9c827a40e..f4901ff93 100644 --- a/modules/client/back/methods/client/specs/createAddress.spec.js +++ b/modules/client/back/methods/client/specs/createAddress.spec.js @@ -1,5 +1,4 @@ const models = require('vn-loopback/server/server').models; -const {mockLoopBackContext} = require('vn-loopback/../../back/vn-jasmine'); describe('Address createAddress', () => { const clientFk = 1101; @@ -7,9 +6,7 @@ describe('Address createAddress', () => { const incotermsFk = 'FAS'; const customAgentOneId = 1; - beforeAll(() => - mockLoopBackContext() - ); + beforeAll.mockLoopBackContext(); it('should throw a non uee member error if no incoterms is defined', async() => { const tx = await models.Client.beginTransaction({}); diff --git a/modules/client/back/methods/client/specs/createWithUser.spec.js b/modules/client/back/methods/client/specs/createWithUser.spec.js index 47f2d34ce..5b1ff5da9 100644 --- a/modules/client/back/methods/client/specs/createWithUser.spec.js +++ b/modules/client/back/methods/client/specs/createWithUser.spec.js @@ -1,6 +1,4 @@ const models = require('vn-loopback/server/server').models; -const {mockLoopBackContext} = require('vn-loopback/../../back/vn-jasmine'); - describe('Client Create', () => { const newAccount = { userName: 'deadpool', @@ -16,9 +14,7 @@ describe('Client Create', () => { const newAccountWithoutEmail = JSON.parse(JSON.stringify(newAccount)); delete newAccountWithoutEmail.email; - beforeAll(() => - mockLoopBackContext() - ); + beforeAll.mockLoopBackContext(); it(`should not find deadpool as he's not created yet`, async() => { const tx = await models.Client.beginTransaction({}); diff --git a/modules/client/back/methods/client/specs/getCard.spec.js b/modules/client/back/methods/client/specs/getCard.spec.js index 1082b4009..49e5ed5a4 100644 --- a/modules/client/back/methods/client/specs/getCard.spec.js +++ b/modules/client/back/methods/client/specs/getCard.spec.js @@ -1,7 +1,7 @@ const models = require('vn-loopback/server/server').models; describe('Client getCard()', () => { - const {ctx} = beforeAll; + const ctx = beforeAll.getCtx(); it('should receive a formated card of Bruce Wayne', async() => { const tx = await models.Client.beginTransaction({}); diff --git a/modules/client/back/methods/client/specs/getDebt.spec.js b/modules/client/back/methods/client/specs/getDebt.spec.js index 7fc76ee94..d89d671a3 100644 --- a/modules/client/back/methods/client/specs/getDebt.spec.js +++ b/modules/client/back/methods/client/specs/getDebt.spec.js @@ -1,7 +1,7 @@ const models = require('vn-loopback/server/server').models; describe('client getDebt()', () => { - const {ctx} = beforeAll; + const ctx = beforeAll.getCtx(); it('should return the client debt', async() => { const tx = await models.Client.beginTransaction({}); diff --git a/modules/client/back/methods/client/specs/sendSms.spec.js b/modules/client/back/methods/client/specs/sendSms.spec.js index b6cb55062..bba9f83ce 100644 --- a/modules/client/back/methods/client/specs/sendSms.spec.js +++ b/modules/client/back/methods/client/specs/sendSms.spec.js @@ -1,7 +1,7 @@ const models = require('vn-loopback/server/server').models; describe('client sendSms()', () => { - const {ctx} = beforeAll; + const ctx = beforeAll.getCtx(); it('should now send a message and log it', async() => { const tx = await models.Client.beginTransaction({}); diff --git a/modules/client/back/methods/client/specs/summary.spec.js b/modules/client/back/methods/client/specs/summary.spec.js index d15d183c6..fe2af8028 100644 --- a/modules/client/back/methods/client/specs/summary.spec.js +++ b/modules/client/back/methods/client/specs/summary.spec.js @@ -1,7 +1,7 @@ const models = require('vn-loopback/server/server').models; describe('client summary()', () => { - const {ctx} = beforeAll; + const ctx = beforeAll.getCtx(); it('should return a summary object containing data', async() => { const clientId = 1101; const tx = await models.Client.beginTransaction({}); diff --git a/modules/client/back/methods/client/specs/updateAddress.spec.js b/modules/client/back/methods/client/specs/updateAddress.spec.js index d0c5e4d88..68981f8b7 100644 --- a/modules/client/back/methods/client/specs/updateAddress.spec.js +++ b/modules/client/back/methods/client/specs/updateAddress.spec.js @@ -1,6 +1,4 @@ const models = require('vn-loopback/server/server').models; -const {mockLoopBackContext} = require('vn-loopback/../../back/vn-jasmine'); - describe('Address updateAddress', () => { const clientId = 1101; const addressId = 1; @@ -14,9 +12,7 @@ describe('Address updateAddress', () => { } }; - beforeAll(() => - mockLoopBackContext() - ); + beforeAll.mockLoopBackContext(); it('should throw the non uee member error if no incoterms is defined', async() => { const tx = await models.Client.beginTransaction({}); diff --git a/modules/client/back/models/specs/address.spec.js b/modules/client/back/models/specs/address.spec.js index d390d045c..3eae1b1bf 100644 --- a/modules/client/back/models/specs/address.spec.js +++ b/modules/client/back/models/specs/address.spec.js @@ -1,13 +1,10 @@ const models = require('vn-loopback/server/server').models; -const {mockLoopBackContext} = require('vn-loopback/../../back/vn-jasmine'); describe('loopback model address', () => { let createdAddressId; const clientId = 1101; - beforeAll(() => - mockLoopBackContext() - ); + beforeAll.mockLoopBackContext(); afterAll(async() => { const client = await models.Client.findById(clientId); diff --git a/modules/entry/back/methods/entry/specs/addFromPackaging.spec.js b/modules/entry/back/methods/entry/specs/addFromPackaging.spec.js index 865e59bca..0c8d2729b 100644 --- a/modules/entry/back/methods/entry/specs/addFromPackaging.spec.js +++ b/modules/entry/back/methods/entry/specs/addFromPackaging.spec.js @@ -1,5 +1,4 @@ const models = require('vn-loopback/server/server').models; -const {mockLoopBackContext} = require('vn-loopback/../../back/vn-jasmine'); describe('entry addFromPackaging()', () => { const supplier = 442; @@ -7,9 +6,7 @@ describe('entry addFromPackaging()', () => { const yesterday = new Date(today); yesterday.setDate(today.getDate() - 1); - beforeAll(() => - mockLoopBackContext() - ); + beforeAll.mockLoopBackContext(); it('should create an incoming travel', async() => { const ctx = {accessToken: {userId: 49}, args: {isTravelReception: true, supplier}}; diff --git a/modules/entry/back/methods/entry/specs/editLatestBuys.spec.js b/modules/entry/back/methods/entry/specs/editLatestBuys.spec.js index 04c38078b..f319c112a 100644 --- a/modules/entry/back/methods/entry/specs/editLatestBuys.spec.js +++ b/modules/entry/back/methods/entry/specs/editLatestBuys.spec.js @@ -1,10 +1,7 @@ const models = require('vn-loopback/server/server').models; -const {mockLoopBackContext} = require('vn-loopback/../../back/vn-jasmine'); describe('Buy editLatestsBuys()', () => { - beforeAll(() => - mockLoopBackContext() - ); + beforeAll.mockLoopBackContext(); it('should change the value of a given column for the selected buys', async() => { const tx = await models.Buy.beginTransaction({}); diff --git a/modules/entry/back/methods/entry/specs/importBuysPreview.spec.js b/modules/entry/back/methods/entry/specs/importBuysPreview.spec.js index 57adaf2dd..fb3268901 100644 --- a/modules/entry/back/methods/entry/specs/importBuysPreview.spec.js +++ b/modules/entry/back/methods/entry/specs/importBuysPreview.spec.js @@ -1,11 +1,8 @@ const models = require('vn-loopback/server/server').models; -const {mockLoopBackContext} = require('vn-loopback/../../back/vn-jasmine'); describe('entry importBuysPreview()', () => { const entryId = 1; - beforeAll(() => - mockLoopBackContext() - ); + beforeAll.mockLoopBackContext(); it('should return the buys with the calculated packagingFk', async() => { const tx = await models.Entry.beginTransaction({}); diff --git a/modules/invoiceIn/back/methods/invoice-in-due-day/specs/new.spec.js b/modules/invoiceIn/back/methods/invoice-in-due-day/specs/new.spec.js index 9a996d103..2105cd9c0 100644 --- a/modules/invoiceIn/back/methods/invoice-in-due-day/specs/new.spec.js +++ b/modules/invoiceIn/back/methods/invoice-in-due-day/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('invoiceInDueDay new()', () => { - beforeAll(() => - mockLoopBackContext() - ); + beforeAll.mockLoopBackContext(); it('should correctly create a new due day', async() => { const userId = 9; diff --git a/modules/invoiceIn/back/methods/invoice-in/specs/clone.spec.js b/modules/invoiceIn/back/methods/invoice-in/specs/clone.spec.js index 9fef506d4..cf1e0ac2d 100644 --- a/modules/invoiceIn/back/methods/invoice-in/specs/clone.spec.js +++ b/modules/invoiceIn/back/methods/invoice-in/specs/clone.spec.js @@ -1,7 +1,7 @@ const models = require('vn-loopback/server/server').models; describe('invoiceIn clone()', () => { - const {ctx} = beforeAll; + const ctx = beforeAll.getCtx(); let options; let tx; diff --git a/modules/invoiceIn/back/methods/invoice-in/specs/corrective.spec.js b/modules/invoiceIn/back/methods/invoice-in/specs/corrective.spec.js index ff547f1c8..c63f02439 100644 --- a/modules/invoiceIn/back/methods/invoice-in/specs/corrective.spec.js +++ b/modules/invoiceIn/back/methods/invoice-in/specs/corrective.spec.js @@ -1,7 +1,7 @@ const models = require('vn-loopback/server/server').models; describe('invoiceIn corrective()', () => { - const {ctx} = beforeAll; + const ctx = beforeAll.getCtx(); let options; let tx; diff --git a/modules/invoiceOut/back/methods/invoiceOut/specs/book.spec.js b/modules/invoiceOut/back/methods/invoiceOut/specs/book.spec.js index 29e21a27c..bebc9a8e4 100644 --- a/modules/invoiceOut/back/methods/invoiceOut/specs/book.spec.js +++ b/modules/invoiceOut/back/methods/invoiceOut/specs/book.spec.js @@ -1,7 +1,7 @@ const models = require('vn-loopback/server/server').models; describe('invoiceOut book()', () => { - const {ctx} = beforeAll; + const ctx = beforeAll.getCtx(); const invoiceOutId = 5; it('should update the booked property', async() => { diff --git a/modules/item/back/methods/fixed-price/specs/upsertFixedPrice.spec.js b/modules/item/back/methods/fixed-price/specs/upsertFixedPrice.spec.js index 36a15849c..335159de5 100644 --- a/modules/item/back/methods/fixed-price/specs/upsertFixedPrice.spec.js +++ b/modules/item/back/methods/fixed-price/specs/upsertFixedPrice.spec.js @@ -1,14 +1,13 @@ const models = require('vn-loopback/server/server').models; -const {mockLoopBackContext} = require('vn-loopback/../../back/vn-jasmine'); describe('upsertFixedPrice()', () => { const now = Date.vnNew(); const fixedPriceId = 1; let originalFixedPrice; + beforeAll.mockLoopBackContext(); beforeAll(async() => { originalFixedPrice = await models.FixedPrice.findById(fixedPriceId); - mockLoopBackContext(); }); it(`should toggle the hasMinPrice boolean if there's a minPrice and update the rest of the data`, async() => { diff --git a/modules/item/back/methods/item-shelving/specs/getAlternative.spec.js b/modules/item/back/methods/item-shelving/specs/getAlternative.spec.js index 006842eca..3b0a65e61 100644 --- a/modules/item/back/methods/item-shelving/specs/getAlternative.spec.js +++ b/modules/item/back/methods/item-shelving/specs/getAlternative.spec.js @@ -1,10 +1,7 @@ const {models} = require('vn-loopback/server/server'); -const {mockLoopBackContext} = require('vn-loopback/../../back/vn-jasmine'); describe('itemShelving getAlternative()', () => { - beforeAll(() => - mockLoopBackContext() - ); + beforeAll.mockLoopBackContext(); it('should return a list of items without alternatives', async() => { const shelvingFk = 'HEJ'; diff --git a/modules/item/back/methods/item-shelving/specs/upsertItem.spec.js b/modules/item/back/methods/item-shelving/specs/upsertItem.spec.js index 18a8a6e0e..f01cb985d 100644 --- a/modules/item/back/methods/item-shelving/specs/upsertItem.spec.js +++ b/modules/item/back/methods/item-shelving/specs/upsertItem.spec.js @@ -3,7 +3,7 @@ const {models} = require('vn-loopback/server/server'); describe('ItemShelving upsertItem()', () => { const warehouseFk = 1; - const {ctx} = beforeAll; + const ctx = beforeAll.getCtx(); let options; let tx; diff --git a/modules/item/back/methods/item/specs/clone.spec.js b/modules/item/back/methods/item/specs/clone.spec.js index e252c910c..5bb5fe560 100644 --- a/modules/item/back/methods/item/specs/clone.spec.js +++ b/modules/item/back/methods/item/specs/clone.spec.js @@ -1,11 +1,8 @@ const models = require('vn-loopback/server/server').models; -const {mockLoopBackContext} = require('vn-loopback/../../back/vn-jasmine'); describe('item clone()', () => { let nextItemId; - beforeAll(() => - mockLoopBackContext() - ); + beforeAll.mockLoopBackContext(); beforeEach(async() => { let query = `SELECT i1.id + 1 as id FROM vn.item i1 diff --git a/modules/item/back/methods/item/specs/getBalance.spec.js b/modules/item/back/methods/item/specs/getBalance.spec.js index d1bb65b75..bae0997bb 100644 --- a/modules/item/back/methods/item/specs/getBalance.spec.js +++ b/modules/item/back/methods/item/specs/getBalance.spec.js @@ -2,7 +2,7 @@ const models = require('vn-loopback/server/server').models; const LoopBackContext = require('loopback-context'); describe('item getBalance()', () => { - const {ctx} = beforeAll; + const ctx = beforeAll.getCtx(); it('should return the balance lines of a client type loses in which one has highlighted true', async() => { const tx = await models.Item.beginTransaction({}); const options = {transaction: tx}; diff --git a/modules/item/back/methods/item/specs/new.spec.js b/modules/item/back/methods/item/specs/new.spec.js index 5611b28ab..11570ffb9 100644 --- a/modules/item/back/methods/item/specs/new.spec.js +++ b/modules/item/back/methods/item/specs/new.spec.js @@ -1,7 +1,7 @@ const models = require('vn-loopback/server/server').models; describe('item new()', () => { - const {ctx} = beforeAll; + const ctx = beforeAll.getCtx(); 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/item/specs/regularize.spec.js b/modules/item/back/methods/item/specs/regularize.spec.js index 097d61d5c..4e94d5d6d 100644 --- a/modules/item/back/methods/item/specs/regularize.spec.js +++ b/modules/item/back/methods/item/specs/regularize.spec.js @@ -1,17 +1,13 @@ const models = require('vn-loopback/server/server').models; -const {mockLoopBackContext} = require('vn-loopback/../../back/vn-jasmine'); describe('regularize()', () => { - beforeAll(() => - mockLoopBackContext() - ); + const ctx = beforeAll.mockLoopBackContext(18); it('should create a new ticket and add a line', async() => { const tx = await models.Item.beginTransaction({}); const options = {transaction: tx}; try { - const ctx = {req: {accessToken: {userId: 18}}}; const itemId = 1; const warehouseId = 1; const quantity = 11; diff --git a/modules/item/back/methods/item/specs/updateTaxes.spec.js b/modules/item/back/methods/item/specs/updateTaxes.spec.js index 3d0f1ce33..828a5fec9 100644 --- a/modules/item/back/methods/item/specs/updateTaxes.spec.js +++ b/modules/item/back/methods/item/specs/updateTaxes.spec.js @@ -1,10 +1,7 @@ const models = require('vn-loopback/server/server').models; -const {mockLoopBackContext} = require('vn-loopback/../../back/vn-jasmine'); describe('item updateTaxes()', () => { - beforeAll(() => - mockLoopBackContext() - ); + beforeAll.mockLoopBackContext(); it('should throw an error if the taxClassFk is blank', 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 be77b0248..e92a5fcdf 100644 --- a/modules/item/back/methods/tag/specs/onSubmit.spec.js +++ b/modules/item/back/methods/tag/specs/onSubmit.spec.js @@ -1,10 +1,7 @@ const models = require('vn-loopback/server/server').models; -const {mockLoopBackContext} = require('vn-loopback/../../back/vn-jasmine'); describe('tag onSubmit()', () => { - beforeAll(() => - mockLoopBackContext() - ); + beforeAll.mockLoopBackContext(); it('should delete a tag', async() => { const tx = await models.Item.beginTransaction({}); diff --git a/modules/order/back/methods/order-row/specs/addToOrder.spec.js b/modules/order/back/methods/order-row/specs/addToOrder.spec.js index 327c86db0..2bc78ffef 100644 --- a/modules/order/back/methods/order-row/specs/addToOrder.spec.js +++ b/modules/order/back/methods/order-row/specs/addToOrder.spec.js @@ -1,7 +1,7 @@ const models = require('vn-loopback/server/server').models; describe('order addToOrder()', () => { - const {ctx} = beforeAll; + const ctx = beforeAll.getCtx(); const orderId = 8; it('should add a row to a given order', async() => { const tx = await models.Order.beginTransaction({}); diff --git a/modules/order/back/methods/order/specs/filter.spec.js b/modules/order/back/methods/order/specs/filter.spec.js index a2ec88577..9e644bb2d 100644 --- a/modules/order/back/methods/order/specs/filter.spec.js +++ b/modules/order/back/methods/order/specs/filter.spec.js @@ -1,10 +1,7 @@ -const {mockLoopBackContext} = require('../../../../../../back/vn-jasmine'); - const models = require('vn-loopback/server/server').models; describe('order filter()', () => { - let ctx; - beforeAll(() => ctx = mockLoopBackContext()); + const ctx = beforeAll.getCtx(); it('should call the filter method with a basic search', async() => { const myCtx = Object.assign({}, ctx); diff --git a/modules/order/back/methods/order/specs/new.spec.js b/modules/order/back/methods/order/specs/new.spec.js index 6ed1fa4ae..779de6ada 100644 --- a/modules/order/back/methods/order/specs/new.spec.js +++ b/modules/order/back/methods/order/specs/new.spec.js @@ -2,7 +2,7 @@ const models = require('vn-loopback/server/server').models; const UserError = require('vn-loopback/util/user-error'); describe('order new()', () => { - const {ctx} = beforeAll; + const ctx = beforeAll.getCtx(); it('should throw an error if the client isnt active', async() => { const tx = await models.Order.beginTransaction({}); diff --git a/modules/order/back/methods/order/specs/newFromTicket.spec.js b/modules/order/back/methods/order/specs/newFromTicket.spec.js index a592877cf..d927a0338 100644 --- a/modules/order/back/methods/order/specs/newFromTicket.spec.js +++ b/modules/order/back/methods/order/specs/newFromTicket.spec.js @@ -1,7 +1,7 @@ const models = require('vn-loopback/server/server').models; describe('order newFromTicket()', () => { - const {ctx} = beforeAll; + const ctx = beforeAll.getCtx(); it('should create a new order from an existing ticket', async() => { const tx = await models.Order.beginTransaction({}); 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 dbe9d0e1e..24ffa9cd7 100644 --- a/modules/route/back/methods/agency-term/specs/createInvoiceIn.spec.js +++ b/modules/route/back/methods/agency-term/specs/createInvoiceIn.spec.js @@ -1,7 +1,7 @@ const models = require('vn-loopback/server/server').models; describe('AgencyTerm createInvoiceIn()', () => { - const {ctx} = beforeAll; + const ctx = beforeAll.getCtx(); 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 b9ad7751c..a064e35ba 100644 --- a/modules/route/back/methods/route/specs/clone.spec.js +++ b/modules/route/back/methods/route/specs/clone.spec.js @@ -1,10 +1,7 @@ const app = require('vn-loopback/server/server'); -const {mockLoopBackContext} = require('vn-loopback/../../back/vn-jasmine'); describe('route clone()', () => { - beforeAll(() => - mockLoopBackContext() - ); + beforeAll.mockLoopBackContext(); const createdDate = Date.vnNew(); it('should throw an error if the amount of ids pased to the clone function do no match the database', async() => { diff --git a/modules/route/back/methods/route/specs/guessPriority.spec.js b/modules/route/back/methods/route/specs/guessPriority.spec.js index 34fa510e1..522801f43 100644 --- a/modules/route/back/methods/route/specs/guessPriority.spec.js +++ b/modules/route/back/methods/route/specs/guessPriority.spec.js @@ -3,7 +3,7 @@ const app = require('vn-loopback/server/server'); describe('route guessPriority()', () => { const targetRouteId = 7; let routeTicketsToRestore; - const {ctx} = beforeAll; + const ctx = beforeAll.getCtx(); afterAll(async() => { let restoreFixtures = []; diff --git a/modules/route/back/methods/route/specs/updateWorkCenter.spec.js b/modules/route/back/methods/route/specs/updateWorkCenter.spec.js index 4d5fbcbdc..b4b9253f8 100644 --- a/modules/route/back/methods/route/specs/updateWorkCenter.spec.js +++ b/modules/route/back/methods/route/specs/updateWorkCenter.spec.js @@ -1,10 +1,7 @@ const models = require('vn-loopback/server/server').models; -const {mockLoopBackContext} = require('vn-loopback/../../back/vn-jasmine'); describe('route updateWorkCenter()', () => { - beforeAll(() => - mockLoopBackContext() - ); + beforeAll.mockLoopBackContext(); const routeId = 1; it('should set the commission work center if the worker has workCenter', async() => { diff --git a/modules/supplier/back/methods/supplier/specs/consumption.spec.js b/modules/supplier/back/methods/supplier/specs/consumption.spec.js index 0b4d6f82c..4c729f64a 100644 --- a/modules/supplier/back/methods/supplier/specs/consumption.spec.js +++ b/modules/supplier/back/methods/supplier/specs/consumption.spec.js @@ -1,8 +1,8 @@ const app = require('vn-loopback/server/server'); describe('supplier consumption() filter', () => { + const ctx = beforeAll.getCtx(); it('should return a list of entries from the supplier 2', async() => { - const ctx = {req: {accessToken: {userId: 9}}, args: {}}; const filter = { where: { supplierFk: 2 diff --git a/modules/supplier/back/models/specs/supplier.spec.js b/modules/supplier/back/models/specs/supplier.spec.js index 2c0d1910f..4e9bd3253 100644 --- a/modules/supplier/back/models/specs/supplier.spec.js +++ b/modules/supplier/back/models/specs/supplier.spec.js @@ -1,14 +1,13 @@ const models = require('vn-loopback/server/server').models; -const {mockLoopBackContext} = require('vn-loopback/../../back/vn-jasmine'); describe('loopback model Supplier', () => { let supplierOne; let supplierTwo; + beforeAll.mockLoopBackContext(); beforeAll(async() => { supplierOne = await models.Supplier.findById(1); supplierTwo = await models.Supplier.findById(442); - mockLoopBackContext(); }); describe('payMethodFk', () => { diff --git a/modules/ticket/back/methods/expedition-state/specs/addExpeditionState.spec.js b/modules/ticket/back/methods/expedition-state/specs/addExpeditionState.spec.js index ce9049a95..747352286 100644 --- a/modules/ticket/back/methods/expedition-state/specs/addExpeditionState.spec.js +++ b/modules/ticket/back/methods/expedition-state/specs/addExpeditionState.spec.js @@ -1,7 +1,7 @@ const models = require('vn-loopback/server/server').models; describe('expeditionState addExpeditionState()', () => { - const {ctx} = beforeAll; + const ctx = beforeAll.getCtx(); it('should update the expedition states', async() => { const tx = await models.ExpeditionState.beginTransaction({}); try { diff --git a/modules/ticket/back/methods/expedition/specs/deleteExpeditions.spec.js b/modules/ticket/back/methods/expedition/specs/deleteExpeditions.spec.js index 4134b28b8..4b17f98b7 100644 --- a/modules/ticket/back/methods/expedition/specs/deleteExpeditions.spec.js +++ b/modules/ticket/back/methods/expedition/specs/deleteExpeditions.spec.js @@ -1,7 +1,7 @@ const models = require('vn-loopback/server/server').models; describe('ticket deleteExpeditions()', () => { - const {ctx} = beforeAll; + const ctx = beforeAll.getCtx(); it('should delete the selected expeditions', async() => { const tx = await models.Expedition.beginTransaction({}); diff --git a/modules/ticket/back/methods/expedition/specs/moveExpeditions.spec.js b/modules/ticket/back/methods/expedition/specs/moveExpeditions.spec.js index 621992c5d..c1c7c2c12 100644 --- a/modules/ticket/back/methods/expedition/specs/moveExpeditions.spec.js +++ b/modules/ticket/back/methods/expedition/specs/moveExpeditions.spec.js @@ -1,7 +1,7 @@ const models = require('vn-loopback/server/server').models; describe('ticket moveExpeditions()', () => { - const {ctx} = beforeAll; + const ctx = beforeAll.getCtx(); it('should move the selected expeditions to new ticket', async() => { const tx = await models.Expedition.beginTransaction({}); diff --git a/modules/ticket/back/methods/sale/specs/canEdit.spec.js b/modules/ticket/back/methods/sale/specs/canEdit.spec.js index 668b1c273..168bd28fb 100644 --- a/modules/ticket/back/methods/sale/specs/canEdit.spec.js +++ b/modules/ticket/back/methods/sale/specs/canEdit.spec.js @@ -1,11 +1,8 @@ const models = require('vn-loopback/server/server').models; -const {mockLoopBackContext} = require('vn-loopback/../../back/vn-jasmine'); describe('sale canEdit()', () => { const employeeId = 1; - beforeAll(() => - mockLoopBackContext() - ); + beforeAll.mockLoopBackContext(); describe('sale not exists', () => { it('should return error if sale not exists', async() => { diff --git a/modules/ticket/back/methods/sale/specs/clone.spec.js b/modules/ticket/back/methods/sale/specs/clone.spec.js index 8767c2857..5b0dc84a7 100644 --- a/modules/ticket/back/methods/sale/specs/clone.spec.js +++ b/modules/ticket/back/methods/sale/specs/clone.spec.js @@ -1,23 +1,11 @@ const models = require('vn-loopback/server/server').models; -const LoopBackContext = require('loopback-context'); - describe('Ticket cloning - clone function', () => { - let ctx; + const ctx = beforeAll.getCtx(); + beforeAll.mockLoopBackContext(); let options; let tx; beforeEach(async() => { - ctx = { - req: { - accessToken: {userId: 9}, - headers: {origin: 'http://localhost'} - }, - args: {} - }; - spyOn(LoopBackContext, 'getCurrentContext').and.returnValue({ - active: ctx.req - }); - options = {transaction: tx}; tx = await models.Sale.beginTransaction({}); options.transaction = tx; diff --git a/modules/ticket/back/methods/sale/specs/deleteSales.spec.js b/modules/ticket/back/methods/sale/specs/deleteSales.spec.js index 8dc261b13..ba14310a1 100644 --- a/modules/ticket/back/methods/sale/specs/deleteSales.spec.js +++ b/modules/ticket/back/methods/sale/specs/deleteSales.spec.js @@ -1,10 +1,8 @@ const models = require('vn-loopback/server/server').models; -const {mockLoopBackContext} = require('vn-loopback/../../back/vn-jasmine'); describe('sale deleteSales()', () => { - beforeAll(() => - mockLoopBackContext() - ); + const ctx = beforeAll.getCtx(); + beforeAll.mockLoopBackContext(); it('should throw an error if the ticket of the given sales is not editable', async() => { const tx = await models.Sale.beginTransaction({}); @@ -13,14 +11,6 @@ describe('sale deleteSales()', () => { try { const options = {transaction: tx}; - const ctx = { - req: { - accessToken: {userId: 9}, - headers: {origin: 'localhost:5000'}, - __: () => {} - } - }; - const sales = [{id: 1, instance: 0}, {id: 2, instance: 1}]; const ticketId = 2; @@ -41,13 +31,6 @@ describe('sale deleteSales()', () => { try { const options = {transaction: tx}; - const ctx = { - req: { - accessToken: {userId: 9}, - headers: {origin: 'localhost:5000'}, - __: () => {} - } - }; const sale = await models.Sale.findOne({where: {id: 9}}, options); sale.id = null; const newSale = await models.Sale.create(sale, options); diff --git a/modules/ticket/back/methods/sale/specs/recalculatePrice.spec.js b/modules/ticket/back/methods/sale/specs/recalculatePrice.spec.js index 3c871dd6c..b97060a3d 100644 --- a/modules/ticket/back/methods/sale/specs/recalculatePrice.spec.js +++ b/modules/ticket/back/methods/sale/specs/recalculatePrice.spec.js @@ -1,7 +1,7 @@ const models = require('vn-loopback/server/server').models; describe('sale recalculatePrice()', () => { - const {ctx} = beforeAll; + const ctx = beforeAll.getCtx(); it('should update the sale price', async() => { const tx = await models.Sale.beginTransaction({}); const sales = [ diff --git a/modules/ticket/back/methods/sale/specs/reserve.spec.js b/modules/ticket/back/methods/sale/specs/reserve.spec.js index 009d7b711..e39f636cc 100644 --- a/modules/ticket/back/methods/sale/specs/reserve.spec.js +++ b/modules/ticket/back/methods/sale/specs/reserve.spec.js @@ -1,5 +1,4 @@ const models = require('vn-loopback/server/server').models; -const {mockLoopBackContext} = require('vn-loopback/../../back/vn-jasmine'); describe('sale reserve()', () => { const ctx = { @@ -10,9 +9,7 @@ describe('sale reserve()', () => { } }; - beforeAll(() => - mockLoopBackContext() - ); + beforeAll.mockLoopBackContext(); it('should throw an error if the ticket can not be modified', async() => { const tx = await models.Sale.beginTransaction({}); diff --git a/modules/ticket/back/methods/sale/specs/updateConcept.spec.js b/modules/ticket/back/methods/sale/specs/updateConcept.spec.js index be6ad77a3..8e3538fc3 100644 --- a/modules/ticket/back/methods/sale/specs/updateConcept.spec.js +++ b/modules/ticket/back/methods/sale/specs/updateConcept.spec.js @@ -1,7 +1,7 @@ const models = require('vn-loopback/server/server').models; describe('sale updateConcept()', () => { - const {ctx} = beforeAll; + const ctx = beforeAll.getCtx(); const saleId = 25; it('should throw if ID was undefined', async() => { 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 396834df2..3fe174e46 100644 --- a/modules/ticket/back/methods/ticket-request/specs/confirm.spec.js +++ b/modules/ticket/back/methods/ticket-request/specs/confirm.spec.js @@ -1,10 +1,8 @@ const models = require('vn-loopback/server/server').models; -const {mockLoopBackContext} = require('vn-loopback/../../back/vn-jasmine'); describe('ticket-request confirm()', () => { - beforeAll(() => - mockLoopBackContext() - ); + const ctx = beforeAll.getCtx(); + beforeAll.mockLoopBackContext(); 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-request/specs/deny.spec.js b/modules/ticket/back/methods/ticket-request/specs/deny.spec.js index aef07bd1b..9920bd4d3 100644 --- a/modules/ticket/back/methods/ticket-request/specs/deny.spec.js +++ b/modules/ticket/back/methods/ticket-request/specs/deny.spec.js @@ -1,29 +1,15 @@ const models = require('vn-loopback/server/server').models; -const {mockLoopBackContext} = require('vn-loopback/../../back/vn-jasmine'); describe('ticket-request deny()', () => { - beforeAll(() => - mockLoopBackContext() - ); + const ctx = beforeAll.getCtx(); + beforeAll.mockLoopBackContext(); it('should return the denied ticket request', async() => { const tx = await models.TicketRequest.beginTransaction({}); try { const options = {transaction: tx}; - - const ctx = { - req: { - accessToken: {userId: 9}, - headers: {origin: 'http://localhost'} - }, - args: {id: 4, observation: 'my observation'}, - }; - - ctx.req.__ = value => { - return value; - }; - + ctx.args = {id: 4, observation: 'my observation'}; const result = await models.TicketRequest.deny(ctx, options); expect(result.id).toEqual(4); diff --git a/modules/ticket/back/methods/ticket/specs/clone.spec.js b/modules/ticket/back/methods/ticket/specs/clone.spec.js index cf222ab8d..ccc0dcdf3 100644 --- a/modules/ticket/back/methods/ticket/specs/clone.spec.js +++ b/modules/ticket/back/methods/ticket/specs/clone.spec.js @@ -1,7 +1,7 @@ const models = require('vn-loopback/server/server').models; describe('Ticket cloning - clone function', () => { - const {ctx} = beforeAll; + const ctx = beforeAll.getCtx(); let options; let tx; const ticketId = 1; diff --git a/modules/ticket/back/methods/ticket/specs/componentUpdate.spec.js b/modules/ticket/back/methods/ticket/specs/componentUpdate.spec.js index b138b88ea..15dd5e4ce 100644 --- a/modules/ticket/back/methods/ticket/specs/componentUpdate.spec.js +++ b/modules/ticket/back/methods/ticket/specs/componentUpdate.spec.js @@ -1,8 +1,7 @@ const models = require('vn-loopback/server/server').models; -const {mockLoopBackContext} = require('vn-loopback/../../back/vn-jasmine'); describe('ticket componentUpdate()', () => { - const userID = 1101; + const ctx = beforeAll.getCtx(1101); const ticketID = 11; const today = Date.vnNew(); const tomorrow = Date.vnNew(); @@ -16,8 +15,8 @@ describe('ticket componentUpdate()', () => { let componentOfSaleEight; let componentValue; + beforeAll.mockLoopBackContext(); beforeAll(async() => { - mockLoopBackContext(); const deliveryComponenet = await models.Component.findOne({where: {code: 'delivery'}}); deliveryComponentId = deliveryComponenet.id; componentOfSaleSeven = `SELECT value @@ -54,16 +53,7 @@ describe('ticket componentUpdate()', () => { isWithoutNegatives: false }; - let ctx = { - args: args, - req: { - accessToken: {userId: userID}, - headers: {origin: 'http://localhost'}, - __: value => { - return value; - } - } - }; + ctx.args = args; await models.Ticket.componentUpdate(ctx, options); [componentValue] = await models.SaleComponent.rawSql(componentOfSaleSeven, null, options); @@ -103,16 +93,7 @@ describe('ticket componentUpdate()', () => { isWithoutNegatives: false }; - const ctx = { - args: args, - req: { - accessToken: {userId: userID}, - headers: {origin: 'http://localhost'}, - __: value => { - return value; - } - } - }; + ctx.args = args; const observationTypeDelivery = await models.ObservationType.findOne({ where: {code: 'delivery'} }, options); @@ -142,6 +123,7 @@ describe('ticket componentUpdate()', () => { }); it('should change warehouse and without negatives', async() => { + const ctx = beforeAll.getCtx(9); const tx = await models.SaleComponent.beginTransaction({}); try { @@ -168,17 +150,7 @@ describe('ticket componentUpdate()', () => { option: 'renewPrices', isWithoutNegatives: true }; - - const ctx = { - args: args, - req: { - accessToken: {userId: 9}, - headers: {origin: 'http://localhost'}, - __: value => { - return value; - } - } - }; + ctx.args = args; const oldTicket = await models.Ticket.findById(ticketID, null, options); @@ -200,6 +172,7 @@ describe('ticket componentUpdate()', () => { }); describe('componentUpdate() keepPrice', () => { + const ctx = beforeAll.getCtx(); it('should change shipped and keep price', async() => { const tx = await models.Ticket.beginTransaction({}); @@ -229,16 +202,7 @@ describe('ticket componentUpdate()', () => { keepPrice: true }; - const ctx = { - args: args, - req: { - accessToken: {userId: 9}, - headers: {origin: 'http://localhost'}, - __: value => { - return value; - } - } - }; + ctx.args = args; const beforeSale = await models.Sale.findById(saleId, null, options); await models.Ticket.componentUpdate(ctx, options); @@ -282,16 +246,7 @@ describe('ticket componentUpdate()', () => { keepPrice: false }; - const ctx = { - args: args, - req: { - accessToken: {userId: 9}, - headers: {origin: 'http://localhost'}, - __: value => { - return value; - } - } - }; + ctx.args = args; const beforeSale = await models.Sale.findById(saleId, null, options); await models.Ticket.componentUpdate(ctx, options); diff --git a/modules/ticket/back/methods/ticket/specs/filter.spec.js b/modules/ticket/back/methods/ticket/specs/filter.spec.js index 8008acfaf..b162ce81f 100644 --- a/modules/ticket/back/methods/ticket/specs/filter.spec.js +++ b/modules/ticket/back/methods/ticket/specs/filter.spec.js @@ -1,13 +1,13 @@ const models = require('vn-loopback/server/server').models; describe('ticket filter()', () => { + const ctx = beforeAll.getCtx(); it('should return the tickets matching the filter', async() => { const tx = await models.Ticket.beginTransaction({}); try { const options = {transaction: tx}; - const ctx = {req: {accessToken: {userId: 9}}, args: {}}; const filter = {order: 'id DESC'}; const result = await models.Ticket.filter(ctx, filter, options); @@ -31,11 +31,12 @@ describe('ticket filter()', () => { const today = Date.vnNew(); today.setHours(23, 59, 59, 59); - const ctx = {req: {accessToken: {userId: 9}}, args: { + const args = { problems: true, from: yesterday, to: today - }}; + }; + ctx.args = args; const filter = {}; const result = await models.Ticket.filter(ctx, filter, options); @@ -60,11 +61,12 @@ describe('ticket filter()', () => { const today = Date.vnNew(); today.setHours(23, 59, 59, 59); - const ctx = {req: {accessToken: {userId: 9}}, args: { + const args = { problems: false, from: yesterday, to: today - }}; + }; + ctx.args = args; const filter = {}; const result = await models.Ticket.filter(ctx, filter, options); @@ -83,7 +85,8 @@ describe('ticket filter()', () => { try { const options = {transaction: tx}; - const ctx = {req: {accessToken: {userId: 9}}, args: {problems: null}}; + const args = {problems: null}; + ctx.args = args; const filter = {}; const result = await models.Ticket.filter(ctx, filter, options); @@ -102,7 +105,8 @@ describe('ticket filter()', () => { try { const options = {transaction: tx}; - const ctx = {req: {accessToken: {userId: 9}}, args: {orderFk: 11}}; + const args = {orderFk: 11}; + ctx.args = args; const filter = {}; const result = await models.Ticket.filter(ctx, filter, options); const firstRow = result[0]; @@ -123,7 +127,8 @@ describe('ticket filter()', () => { try { const options = {transaction: tx}; - const ctx = {req: {accessToken: {userId: 9}}, args: {pending: true}}; + const args = {pending: true}; + ctx.args = args; const filter = {}; const result = await models.Ticket.filter(ctx, filter, options); @@ -146,7 +151,8 @@ describe('ticket filter()', () => { try { const options = {transaction: tx}; - const ctx = {req: {accessToken: {userId: 9}}, args: {pending: false}}; + const args = {pending: false}; + ctx.args = args; const filter = {}; const result = await models.Ticket.filter(ctx, filter, options); const firstRow = result[0]; @@ -167,11 +173,13 @@ describe('ticket filter()', () => { it('should return the tickets from the worker team', async() => { const tx = await models.Ticket.beginTransaction({}); + const ctx = beforeAll.getCtx(18); try { const options = {transaction: tx}; - const ctx = {req: {accessToken: {userId: 18}}, args: {myTeam: true}}; + const args = {myTeam: true}; + ctx.args = args; const filter = {}; const result = await models.Ticket.filter(ctx, filter, options); @@ -185,12 +193,14 @@ describe('ticket filter()', () => { }); it('should return the tickets that are not from the worker team', async() => { + const ctx = beforeAll.getCtx(18); const tx = await models.Ticket.beginTransaction({}); try { const options = {transaction: tx}; - const ctx = {req: {accessToken: {userId: 18}}, args: {myTeam: false}}; + const args = {myTeam: false}; + ctx.args = args; const filter = {}; const result = await models.Ticket.filter(ctx, filter, options); @@ -204,12 +214,14 @@ describe('ticket filter()', () => { }); it('should return the tickets belonging to the collection id 1', async() => { + const ctx = beforeAll.getCtx(18); const tx = await models.Ticket.beginTransaction({}); try { const options = {transaction: tx}; - const ctx = {req: {accessToken: {userId: 18}}, args: {collectionFk: 1}}; + const args = {collectionFk: 1}; + ctx.args = args; const filter = {}; const result = await models.Ticket.filter(ctx, filter, options); @@ -228,7 +240,8 @@ describe('ticket filter()', () => { try { const options = {transaction: tx}; - const ctx = {req: {accessToken: {userId: 9}}, args: {hasRoute: true}}; + const args = {hasRoute: true}; + ctx.args = args; const filter = {}; const result = await models.Ticket.filter(ctx, filter, options); @@ -247,7 +260,8 @@ describe('ticket filter()', () => { try { const options = {transaction: tx}; - const ctx = {req: {accessToken: {userId: 9}}, args: {hasRoute: false}}; + const args = {hasRoute: false}; + ctx.args = args; const filter = {}; const result = await models.Ticket.filter(ctx, filter, options); @@ -266,7 +280,8 @@ describe('ticket filter()', () => { try { const options = {transaction: tx}; - const ctx = {req: {accessToken: {userId: 9}}, args: {hasRoute: null}}; + const args = {hasRoute: null}; + ctx.args = args; const filter = {}; const result = await models.Ticket.filter(ctx, filter, options); @@ -285,7 +300,8 @@ describe('ticket filter()', () => { try { const options = {transaction: tx}; - const ctx = {req: {accessToken: {userId: 9}}, args: {hasInvoice: true}}; + const args = {hasInvoice: true}; + ctx.args = args; const filter = {}; const result = await models.Ticket.filter(ctx, filter, options); @@ -304,7 +320,8 @@ describe('ticket filter()', () => { try { const options = {transaction: tx}; - const ctx = {req: {accessToken: {userId: 9}}, args: {hasInvoice: null}}; + const args = {hasInvoice: null}; + ctx.args = args; const filter = {}; const result = await models.Ticket.filter(ctx, filter, options); diff --git a/modules/ticket/back/methods/ticket/specs/getTicketsAdvance.spec.js b/modules/ticket/back/methods/ticket/specs/getTicketsAdvance.spec.js index 5a3209a6d..488cd1fc2 100644 --- a/modules/ticket/back/methods/ticket/specs/getTicketsAdvance.spec.js +++ b/modules/ticket/back/methods/ticket/specs/getTicketsAdvance.spec.js @@ -1,6 +1,7 @@ const models = require('vn-loopback/server/server').models; describe('TicketFuture getTicketsAdvance()', () => { + const ctx = beforeAll.getCtx(); const today = Date.vnNew(); today.setHours(0, 0, 0, 0); let tomorrow = Date.vnNew(); @@ -18,7 +19,7 @@ describe('TicketFuture getTicketsAdvance()', () => { warehouseFk: 1, }; - const ctx = {req: {accessToken: {userId: 9}}, args}; + ctx.args = args; const result = await models.Ticket.getTicketsAdvance(ctx, options); expect(result.length).toBeGreaterThan(0); @@ -42,7 +43,7 @@ describe('TicketFuture getTicketsAdvance()', () => { isFullMovable: true }; - const ctx = {req: {accessToken: {userId: 9}}, args}; + ctx.args = args; const result = await models.Ticket.getTicketsAdvance(ctx, options); expect(result.length).toBeGreaterThan(0); @@ -67,7 +68,7 @@ describe('TicketFuture getTicketsAdvance()', () => { isFullMovable: false }; - const ctx = {req: {accessToken: {userId: 9}}, args}; + ctx.args = args; const result = await models.Ticket.getTicketsAdvance(ctx, options); expect(result.length).toEqual(0); @@ -92,7 +93,7 @@ describe('TicketFuture getTicketsAdvance()', () => { ipt: 'V' }; - const ctx = {req: {accessToken: {userId: 9}}, args}; + ctx.args = args; const result = await models.Ticket.getTicketsAdvance(ctx, options); expect(result.length).toBeGreaterThan(5); @@ -117,7 +118,7 @@ describe('TicketFuture getTicketsAdvance()', () => { tfIpt: 'V' }; - const ctx = {req: {accessToken: {userId: 9}}, args}; + ctx.args = args; const result = await models.Ticket.getTicketsAdvance(ctx, options); expect(result.length).toBeGreaterThan(5); diff --git a/modules/ticket/back/methods/ticket/specs/getTicketsFuture.spec.js b/modules/ticket/back/methods/ticket/specs/getTicketsFuture.spec.js index 44896493f..4b28f34ea 100644 --- a/modules/ticket/back/methods/ticket/specs/getTicketsFuture.spec.js +++ b/modules/ticket/back/methods/ticket/specs/getTicketsFuture.spec.js @@ -1,6 +1,7 @@ const models = require('vn-loopback/server/server').models; describe('ticket getTicketsFuture()', () => { + const ctx = beforeAll.getCtx(); const today = Date.vnNew(); today.setHours(0, 0, 0, 0); @@ -16,7 +17,7 @@ describe('ticket getTicketsFuture()', () => { warehouseFk: 1, }; - const ctx = {req: {accessToken: {userId: 9}}, args}; + ctx.args = args; const result = await models.Ticket.getTicketsFuture(ctx, options); expect(result.length).toBeGreaterThan(0); @@ -40,7 +41,7 @@ describe('ticket getTicketsFuture()', () => { problems: true }; - const ctx = {req: {accessToken: {userId: 9}}, args}; + ctx.args = args; const result = await models.Ticket.getTicketsFuture(ctx, options); expect(result.length).toBeGreaterThan(0); @@ -65,7 +66,7 @@ describe('ticket getTicketsFuture()', () => { problems: false }; - const ctx = {req: {accessToken: {userId: 9}}, args}; + ctx.args = args; const result = await models.Ticket.getTicketsFuture(ctx, options); expect(result.length).toEqual(0); @@ -90,7 +91,7 @@ describe('ticket getTicketsFuture()', () => { problems: null }; - const ctx = {req: {accessToken: {userId: 9}}, args}; + ctx.args = args; const result = await models.Ticket.getTicketsFuture(ctx, options); expect(result.length).toBeGreaterThan(0); @@ -115,7 +116,7 @@ describe('ticket getTicketsFuture()', () => { state: 'OK' }; - const ctx = {req: {accessToken: {userId: 9}}, args}; + ctx.args = args; const result = await models.Ticket.getTicketsFuture(ctx, options); expect(result.length).toBeGreaterThan(0); @@ -140,7 +141,7 @@ describe('ticket getTicketsFuture()', () => { futureState: 'OK' }; - const ctx = {req: {accessToken: {userId: 9}}, args}; + ctx.args = args; const result = await models.Ticket.getTicketsFuture(ctx, options); expect(result.length).toBeGreaterThan(0); @@ -165,7 +166,7 @@ describe('ticket getTicketsFuture()', () => { ipt: null }; - const ctx = {req: {accessToken: {userId: 9}}, args}; + ctx.args = args; const result = await models.Ticket.getTicketsFuture(ctx, options); expect(result.length).toBeGreaterThan(0); @@ -190,7 +191,7 @@ describe('ticket getTicketsFuture()', () => { ipt: 'H' }; - const ctx = {req: {accessToken: {userId: 9}}, args}; + ctx.args = args; const result = await models.Ticket.getTicketsFuture(ctx, options); expect(result.length).toBeGreaterThan(0); @@ -215,7 +216,7 @@ describe('ticket getTicketsFuture()', () => { futureIpt: null }; - const ctx = {req: {accessToken: {userId: 9}}, args}; + ctx.args = args; const result = await models.Ticket.getTicketsFuture(ctx, options); expect(result.length).toBeGreaterThan(0); @@ -240,7 +241,7 @@ describe('ticket getTicketsFuture()', () => { futureIpt: 'H' }; - const ctx = {req: {accessToken: {userId: 9}}, args}; + ctx.args = args; const result = await models.Ticket.getTicketsFuture(ctx, options); expect(result.length).toBeGreaterThan(0); @@ -265,7 +266,7 @@ describe('ticket getTicketsFuture()', () => { id: 13 }; - const ctx = {req: {accessToken: {userId: 9}}, args}; + ctx.args = args; const result = await models.Ticket.getTicketsFuture(ctx, options); expect(result.length).toBeGreaterThan(0); @@ -290,7 +291,7 @@ describe('ticket getTicketsFuture()', () => { futureId: 12 }; - const ctx = {req: {accessToken: {userId: 9}}, args}; + ctx.args = args; const result = await models.Ticket.getTicketsFuture(ctx, options); expect(result.length).toBeGreaterThan(0); diff --git a/modules/ticket/back/methods/ticket/specs/isEditableOrThrow.spec.js b/modules/ticket/back/methods/ticket/specs/isEditableOrThrow.spec.js index e78812bfe..883b0de2e 100644 --- a/modules/ticket/back/methods/ticket/specs/isEditableOrThrow.spec.js +++ b/modules/ticket/back/methods/ticket/specs/isEditableOrThrow.spec.js @@ -1,7 +1,7 @@ const models = require('vn-loopback/server/server').models; describe('ticket isEditableOrThrow()', () => { - const {ctx} = beforeAll; + const ctx = beforeAll.getCtx(); it('should throw an error as the ticket does not exist', async() => { const tx = await models.Ticket.beginTransaction({}); let error; diff --git a/modules/ticket/back/methods/ticket/specs/merge.spec.js b/modules/ticket/back/methods/ticket/specs/merge.spec.js index 21d4e5c75..68f9d3393 100644 --- a/modules/ticket/back/methods/ticket/specs/merge.spec.js +++ b/modules/ticket/back/methods/ticket/specs/merge.spec.js @@ -1,7 +1,7 @@ const models = require('vn-loopback/server/server').models; describe('ticket merge()', () => { - const {ctx} = beforeAll; + const ctx = beforeAll.getCtx(); const tickets = { originId: 13, destinationId: 12, @@ -10,10 +10,6 @@ describe('ticket merge()', () => { workerFk: 1 }; - ctx.req.__ = value => { - return value; - }; - it('should merge two tickets', async() => { const tx = await models.Ticket.beginTransaction({}); diff --git a/modules/ticket/back/methods/ticket/specs/recalculateComponents.spec.js b/modules/ticket/back/methods/ticket/specs/recalculateComponents.spec.js index 5c3811583..f9c7284f5 100644 --- a/modules/ticket/back/methods/ticket/specs/recalculateComponents.spec.js +++ b/modules/ticket/back/methods/ticket/specs/recalculateComponents.spec.js @@ -3,7 +3,7 @@ const ForbiddenError = require('vn-loopback/util/forbiddenError'); describe('ticket recalculateComponents()', () => { const ticketId = 11; - const {ctx} = beforeAll; + const ctx = beforeAll.getCtx(); it('should update the ticket components', async() => { const tx = await models.Ticket.beginTransaction({}); diff --git a/modules/ticket/back/methods/ticket/specs/sendSms.spec.js b/modules/ticket/back/methods/ticket/specs/sendSms.spec.js index b79e41d37..2a7b82ea0 100644 --- a/modules/ticket/back/methods/ticket/specs/sendSms.spec.js +++ b/modules/ticket/back/methods/ticket/specs/sendSms.spec.js @@ -1,7 +1,7 @@ const models = require('vn-loopback/server/server').models; describe('ticket sendSms()', () => { - const {ctx} = beforeAll; + const ctx = beforeAll.getCtx(); it('should send a message and log it', async() => { const tx = await models.Ticket.beginTransaction({}); diff --git a/modules/ticket/back/methods/ticket/specs/setDeleted.spec.js b/modules/ticket/back/methods/ticket/specs/setDeleted.spec.js index cb2a21d91..ed9347714 100644 --- a/modules/ticket/back/methods/ticket/specs/setDeleted.spec.js +++ b/modules/ticket/back/methods/ticket/specs/setDeleted.spec.js @@ -1,17 +1,8 @@ const models = require('vn-loopback/server/server').models; -const LoopBackContext = require('loopback-context'); describe('ticket setDeleted()', () => { - const userId = 1106; - const activeCtx = { - accessToken: {userId: userId}, - }; - - beforeEach(() => { - spyOn(LoopBackContext, 'getCurrentContext').and.returnValue({ - active: activeCtx - }); - }); + const ctx = beforeAll.getCtx(); + beforeAll.mockLoopBackContext(); it('should throw an error if the given ticket has a claim', async() => { const tx = await models.Ticket.beginTransaction({}); @@ -20,7 +11,6 @@ describe('ticket setDeleted()', () => { try { const options = {transaction: tx}; - const ctx = {req: activeCtx}; const ticketId = 16; await models.Ticket.setDeleted(ctx, ticketId, options); @@ -40,15 +30,6 @@ describe('ticket setDeleted()', () => { try { const options = {transaction: tx}; - const ctx = { - req: { - accessToken: {userId: 9}, - headers: {origin: 'http://localhost:5000'}, - } - }; - ctx.req.__ = value => { - return value; - }; const ticketId = 24; const [sectorCollectionBefore] = await models.Ticket.rawSql( `SELECT COUNT(*) numberRows @@ -75,15 +56,6 @@ describe('ticket setDeleted()', () => { try { const options = {transaction: tx}; - const ctx = { - req: { - accessToken: {userId: 9}, - headers: {origin: 'http://localhost:5000'}, - } - }; - ctx.req.__ = value => { - return value; - }; const [ticketCollectionOld] = await models.Ticket.rawSql( `SELECT COUNT(*) numberRows FROM vn.ticketCollection`, [], options); @@ -110,16 +82,6 @@ describe('ticket setDeleted()', () => { try { const options = {transaction: tx}; - const ctx = { - req: { - accessToken: {userId: 9}, - headers: {origin: 'http://localhost:5000'}, - } - }; - ctx.req.__ = value => { - return value; - }; - const ticketId = 8; await models.Ticket.setDeleted(ctx, ticketId, options); diff --git a/modules/ticket/back/methods/ticket/specs/state.spec.js b/modules/ticket/back/methods/ticket/specs/state.spec.js index d908aa2ef..3042633c6 100644 --- a/modules/ticket/back/methods/ticket/specs/state.spec.js +++ b/modules/ticket/back/methods/ticket/specs/state.spec.js @@ -2,14 +2,10 @@ const models = require('vn-loopback/server/server').models; const LoopBackContext = require('loopback-context'); describe('ticket state()', () => { + const ctx = beforeAll.getCtx(); const salesPersonId = 18; const employeeId = 1; const productionId = 49; - const activeCtx = { - accessToken: {userId: 9}, - __: value => value - }; - const ctx = {req: activeCtx}; const now = Date.vnNew(); const sampleTicket = { shipped: now, @@ -33,7 +29,7 @@ describe('ticket state()', () => { beforeAll(async() => { spyOn(LoopBackContext, 'getCurrentContext').and.returnValue({ - active: activeCtx + active: ctx }); }); @@ -45,7 +41,7 @@ describe('ticket state()', () => { try { const options = {transaction: tx}; - activeCtx.accessToken.userId = salesPersonId; + ctx.req.accessToken.userId = salesPersonId; await models.Ticket.state(ctx, {ticketFk: 2, stateFk: 3}, options); @@ -66,7 +62,7 @@ describe('ticket state()', () => { try { const options = {transaction: tx}; - activeCtx.accessToken.userId = employeeId; + ctx.req.accessToken.userId = employeeId; await models.Ticket.state(ctx, {ticketFk: 11, stateFk: 13}, options); @@ -88,7 +84,7 @@ describe('ticket state()', () => { const ticket = await models.Ticket.create(sampleTicket, options); - activeCtx.accessToken.userId = productionId; + ctx.req.accessToken.userId = productionId; const stateOk = await models.State.findOne({where: {code: 'OK'}}, options); const params = {ticketFk: ticket.id, stateFk: stateOk.id}; @@ -114,7 +110,7 @@ describe('ticket state()', () => { const options = {transaction: tx}; const ticket = await models.Ticket.create(sampleTicket, options); - activeCtx.accessToken.userId = salesPersonId; + ctx.req.accessToken.userId = salesPersonId; const assignedState = await models.State.findOne({where: {code: 'PICKER_DESIGNED'}}, options); const paramsAssigned = {ticketFk: ticket.id, stateFk: assignedState.id, userFk: 1}; const resAssigned = await models.Ticket.state(ctx, paramsAssigned, options); @@ -125,7 +121,7 @@ describe('ticket state()', () => { expect(resAssigned.userFk).toBe(1); expect(resAssigned.id).toBeDefined(); - activeCtx.accessToken.userId = productionId; + ctx.req.accessToken.userId = productionId; const packedState = await models.State.findOne({where: {code: 'PACKED'}}, options); const paramsPacked = {ticketFk: ticket.id, stateFk: packedState.id, userFk: salesPersonId}; const resPacked = await models.Ticket.state(ctx, paramsPacked, options); @@ -147,7 +143,7 @@ describe('ticket state()', () => { const options = {transaction: tx}; const ticket = await models.Ticket.create(sampleTicket, options); - activeCtx.accessToken.userId = salesPersonId; + ctx.req.accessToken.userId = salesPersonId; const sampleSale = { ticketFk: ticket.id, @@ -167,7 +163,7 @@ describe('ticket state()', () => { expect(resAssigned.userFk).toBe(1); expect(resAssigned.id).toBeDefined(); - activeCtx.accessToken.userId = productionId; + ctx.req.accessToken.userId = productionId; const packedState = await models.State.findOne({where: {code: 'PACKED'}}, options); const paramsPacked = {ticketFk: ticket.id, stateFk: packedState.id, userFk: salesPersonId}; const resPacked = await models.Ticket.state(ctx, paramsPacked, options); diff --git a/modules/ticket/back/methods/ticket/specs/transferClient.spec.js b/modules/ticket/back/methods/ticket/specs/transferClient.spec.js index 4aac0833a..01fd8fcbe 100644 --- a/modules/ticket/back/methods/ticket/specs/transferClient.spec.js +++ b/modules/ticket/back/methods/ticket/specs/transferClient.spec.js @@ -5,7 +5,7 @@ describe('Ticket transferClient()', () => { const refundTicketId = 24; const clientId = 1; - const {ctx} = beforeAll; + const ctx = beforeAll.getCtx(); let options; let tx; beforeEach(async() => { diff --git a/modules/ticket/back/methods/ticket/specs/updateDiscount.spec.js b/modules/ticket/back/methods/ticket/specs/updateDiscount.spec.js index 01e6e64bb..272387a30 100644 --- a/modules/ticket/back/methods/ticket/specs/updateDiscount.spec.js +++ b/modules/ticket/back/methods/ticket/specs/updateDiscount.spec.js @@ -1,10 +1,8 @@ const models = require('vn-loopback/server/server').models; -const {mockLoopBackContext} = require('vn-loopback/../../back/vn-jasmine'); describe('sale updateDiscount()', () => { - beforeAll(() => - mockLoopBackContext() - ); + const ctx = beforeAll.getCtx(); + beforeAll.mockLoopBackContext(); const originalSaleId = 8; it('should throw an error if no sales were selected', async() => { @@ -14,13 +12,6 @@ describe('sale updateDiscount()', () => { try { const options = {transaction: tx}; - const ctx = { - req: { - accessToken: {userId: 9}, - headers: {origin: 'localhost:5000'}, - __: () => {} - } - }; const ticketId = 11; const sales = []; const newDiscount = 10; @@ -43,13 +34,6 @@ describe('sale updateDiscount()', () => { try { const options = {transaction: tx}; - const ctx = { - req: { - accessToken: {userId: 9}, - headers: {origin: 'localhost:5000'}, - __: () => {} - } - }; const ticketId = 11; const sales = [1, 14]; const newDiscount = 10; @@ -72,13 +56,6 @@ describe('sale updateDiscount()', () => { try { const options = {transaction: tx}; - const ctx = { - req: { - accessToken: {userId: 9}, - headers: {origin: 'localhost:5000'}, - __: () => {} - } - }; const ticketId = 1; const sales = [1]; const newDiscount = 100; @@ -96,17 +73,11 @@ describe('sale updateDiscount()', () => { it('should update the discount if the salesPerson has mana and manaCode = "mana"', async() => { const tx = await models.Ticket.beginTransaction({}); + const ctx = beforeAll.getCtx(18); try { const options = {transaction: tx}; - const ctx = { - req: { - accessToken: {userId: 18}, - headers: {origin: 'localhost:5000'}, - __: () => {} - } - }; const ticketId = 11; const sales = [originalSaleId]; const newDiscount = 100; @@ -141,17 +112,11 @@ describe('sale updateDiscount()', () => { it('should update the discount if the salesPerson has mana and manaCode = "manaClaim"', async() => { const tx = await models.Ticket.beginTransaction({}); + const ctx = beforeAll.getCtx(18); try { const options = {transaction: tx}; - const ctx = { - req: { - accessToken: {userId: 18}, - headers: {origin: 'localhost:5000'}, - __: () => {} - } - }; const ticketId = 11; const sales = [originalSaleId]; const newDiscount = 100; @@ -190,13 +155,6 @@ describe('sale updateDiscount()', () => { try { const options = {transaction: tx}; - const ctx = { - req: { - accessToken: {userId: 9}, - headers: {origin: 'localhost:5000'}, - __: () => {} - } - }; const ticketId = 11; const sales = [originalSaleId]; const newDiscount = 100; diff --git a/modules/ticket/back/models/specs/ticket-packaging.spec.js b/modules/ticket/back/models/specs/ticket-packaging.spec.js index 7ff863cff..5e0ca82db 100644 --- a/modules/ticket/back/models/specs/ticket-packaging.spec.js +++ b/modules/ticket/back/models/specs/ticket-packaging.spec.js @@ -1,10 +1,7 @@ const app = require('vn-loopback/server/server'); -const {mockLoopBackContext} = require('vn-loopback/../../back/vn-jasmine'); describe('ticket model TicketTracking', () => { - beforeAll(() => - mockLoopBackContext() - ); + beforeAll.mockLoopBackContext(); let ticketTrackingId; afterAll(async() => { diff --git a/modules/ticket/back/models/ticket-request.js b/modules/ticket/back/models/ticket-request.js index 622cd7696..30d6a5454 100644 --- a/modules/ticket/back/models/ticket-request.js +++ b/modules/ticket/back/models/ticket-request.js @@ -19,7 +19,7 @@ module.exports = function(Self) { instance.requesterFk = worker.id; const httpCtx = {req: loopBackContext.active}; - const httpRequest = httpCtx.req.http .req; + const httpRequest = httpCtx.req.http.req; const $t = httpRequest.__; if (attenderFk) { diff --git a/modules/travel/back/methods/thermograph/specs/createThermograph.spec.js b/modules/travel/back/methods/thermograph/specs/createThermograph.spec.js index 49eeb86c2..71b9fcccb 100644 --- a/modules/travel/back/methods/thermograph/specs/createThermograph.spec.js +++ b/modules/travel/back/methods/thermograph/specs/createThermograph.spec.js @@ -5,7 +5,7 @@ describe('Termograph createThermograph()', () => { const model = 'DISPOSABLE'; const temperatureFk = 'COOL'; const warehouseId = 1; - const {ctx} = beforeAll; + const ctx = beforeAll.getCtx(); it(`should create a thermograph which is saved in both thermograph and travelThermograph`, async() => { const tx = await models.Thermograph.beginTransaction({}); diff --git a/modules/travel/back/methods/travel/specs/createThermograph.spec.js b/modules/travel/back/methods/travel/specs/createThermograph.spec.js index 2b0ae48f4..f70e27368 100644 --- a/modules/travel/back/methods/travel/specs/createThermograph.spec.js +++ b/modules/travel/back/methods/travel/specs/createThermograph.spec.js @@ -1,10 +1,7 @@ const models = require('vn-loopback/server/server').models; -const {mockLoopBackContext} = require('vn-loopback/../../back/vn-jasmine'); describe('Travel createThermograph()', () => { - beforeAll(() => - mockLoopBackContext() - ); + beforeAll.mockLoopBackContext(); const travelId = 3; const currentUserId = 1102; const thermographId = '138350-0'; diff --git a/modules/worker/back/methods/calendar/specs/absences.spec.js b/modules/worker/back/methods/calendar/specs/absences.spec.js index 0e6f21a5f..f369d1dca 100644 --- a/modules/worker/back/methods/calendar/specs/absences.spec.js +++ b/modules/worker/back/methods/calendar/specs/absences.spec.js @@ -1,7 +1,7 @@ const app = require('vn-loopback/server/server'); describe('Worker absences()', () => { - const {ctx} = beforeAll; + const ctx = beforeAll.getCtx(); it('should get the absence calendar for a full year contract', async() => { const ctx = {req: {accessToken: {userId: 1106}}}; const workerId = 1106; diff --git a/modules/worker/back/methods/department/specs/getLeaves.spec.js b/modules/worker/back/methods/department/specs/getLeaves.spec.js index d7e934d20..2feb6b461 100644 --- a/modules/worker/back/methods/department/specs/getLeaves.spec.js +++ b/modules/worker/back/methods/department/specs/getLeaves.spec.js @@ -1,7 +1,7 @@ const models = require('vn-loopback/server/server').models; describe('department getLeaves()', () => { - const {ctx} = beforeAll; + const ctx = beforeAll.getCtx(); it('should return the department and the childs containing the search value', async() => { let result = await models.Department.getLeaves(ctx, null, 'INFORMATICA'); diff --git a/modules/worker/back/methods/worker/specs/createAbsence.spec.js b/modules/worker/back/methods/worker/specs/createAbsence.spec.js index aadaca99b..fcb1c1633 100644 --- a/modules/worker/back/methods/worker/specs/createAbsence.spec.js +++ b/modules/worker/back/methods/worker/specs/createAbsence.spec.js @@ -133,7 +133,8 @@ describe('Worker createAbsence()', () => { expect(error.message).toEqual(`Cannot add holidays on this day`); }); - it(`should throw an error when adding a absence if the worker has hours recorded that day and not is a half absence`, async() => { + it(`should throw an error when adding a absence if the worker ` + + `has hours recorded that day and not is a half absence`, async() => { const ctx = { req: {accessToken: {userId: 19}}, args: { diff --git a/modules/worker/back/methods/worker/specs/mySubordinates.spec.js b/modules/worker/back/methods/worker/specs/mySubordinates.spec.js index ecd668603..7443827ce 100644 --- a/modules/worker/back/methods/worker/specs/mySubordinates.spec.js +++ b/modules/worker/back/methods/worker/specs/mySubordinates.spec.js @@ -1,7 +1,7 @@ const app = require('vn-loopback/server/server'); describe('worker mySubordinates()', () => { - const {ctx} = beforeAll; + const ctx = beforeAll.getCtx(); it('should return an array of subordinates greather than 1', async() => { let result = await app.models.Worker.mySubordinates(ctx); diff --git a/modules/worker/back/methods/worker/specs/new.spec.js b/modules/worker/back/methods/worker/specs/new.spec.js index 04540b9b7..d9e843064 100644 --- a/modules/worker/back/methods/worker/specs/new.spec.js +++ b/modules/worker/back/methods/worker/specs/new.spec.js @@ -1,5 +1,4 @@ const {models} = require('vn-loopback/server/server'); -const {mockLoopBackContext} = require('vn-loopback/../../back/vn-jasmine'); describe('Worker new', () => { const developerId = 9; @@ -10,9 +9,7 @@ describe('Worker new', () => { let tx; let opts; - beforeAll(() => - mockLoopBackContext() - ); + beforeAll.mockLoopBackContext(); describe('should return error', () => { beforeEach(async() => { diff --git a/modules/zone/back/methods/agency/specs/getAgenciesWithWarehouse.spec.js b/modules/zone/back/methods/agency/specs/getAgenciesWithWarehouse.spec.js index 27a48a848..931a5c707 100644 --- a/modules/zone/back/methods/agency/specs/getAgenciesWithWarehouse.spec.js +++ b/modules/zone/back/methods/agency/specs/getAgenciesWithWarehouse.spec.js @@ -1,7 +1,7 @@ const app = require('vn-loopback/server/server'); describe('Agency getAgenciesWithWarehouse()', () => { - const {ctx} = beforeAll; + const ctx = beforeAll.getCtx(); const today = Date.vnNew(); it('should return the agencies that can handle the given delivery request', async() => { const tx = await app.models.Zone.beginTransaction({}); diff --git a/modules/zone/back/methods/agency/specs/landsThatDay.spec.js b/modules/zone/back/methods/agency/specs/landsThatDay.spec.js index 27e71bc6f..cd587a329 100644 --- a/modules/zone/back/methods/agency/specs/landsThatDay.spec.js +++ b/modules/zone/back/methods/agency/specs/landsThatDay.spec.js @@ -1,7 +1,7 @@ const {models} = require('vn-loopback/server/server'); describe('Agency landsThatDay()', () => { - const {ctx} = beforeAll; + const ctx = beforeAll.getCtx(); const today = Date.vnNew(); it('should return a list of agencies that can land a shipment on a day for an address', async() => { const tx = await models.Agency.beginTransaction({}); diff --git a/modules/zone/back/methods/zone/specs/clone.spec.js b/modules/zone/back/methods/zone/specs/clone.spec.js index 292aeb2ac..3a8783f21 100644 --- a/modules/zone/back/methods/zone/specs/clone.spec.js +++ b/modules/zone/back/methods/zone/specs/clone.spec.js @@ -1,10 +1,7 @@ const models = require('vn-loopback/server/server').models; -const {mockLoopBackContext} = require('vn-loopback/../../back/vn-jasmine'); describe('agency clone()', () => { - beforeAll(() => - mockLoopBackContext() - ); + beforeAll.mockLoopBackContext(); it('should clone a zone', async() => { const tx = await models.Zone.beginTransaction({}); diff --git a/modules/zone/back/methods/zone/specs/exclusionGeo.spec.js b/modules/zone/back/methods/zone/specs/exclusionGeo.spec.js index dc2eeb8a8..bd4438204 100644 --- a/modules/zone/back/methods/zone/specs/exclusionGeo.spec.js +++ b/modules/zone/back/methods/zone/specs/exclusionGeo.spec.js @@ -1,10 +1,7 @@ const models = require('vn-loopback/server/server').models; -const {mockLoopBackContext} = require('vn-loopback/../../back/vn-jasmine'); describe('zone exclusionGeo()', () => { - beforeAll(() => - mockLoopBackContext() - ); + beforeAll.mockLoopBackContext(); const zoneId = 1; const today = Date.vnNew(); diff --git a/modules/zone/back/methods/zone/specs/getEvents.spec.js b/modules/zone/back/methods/zone/specs/getEvents.spec.js index 3c9dd76f2..80388d009 100644 --- a/modules/zone/back/methods/zone/specs/getEvents.spec.js +++ b/modules/zone/back/methods/zone/specs/getEvents.spec.js @@ -1,7 +1,7 @@ const models = require('vn-loopback/server/server').models; describe('zone getEvents()', () => { - const {ctx} = beforeAll; + const ctx = beforeAll.getCtx(); it('should return all events for the specified geo and agency mode', async() => { const tx = await models.Zone.beginTransaction({}); diff --git a/modules/zone/back/methods/zone/specs/getLeaves.spec.js b/modules/zone/back/methods/zone/specs/getLeaves.spec.js index 4b8ab926c..fde56be35 100644 --- a/modules/zone/back/methods/zone/specs/getLeaves.spec.js +++ b/modules/zone/back/methods/zone/specs/getLeaves.spec.js @@ -1,7 +1,7 @@ const models = require('vn-loopback/server/server').models; describe('zone getLeaves()', () => { - const {ctx} = beforeAll; + const ctx = beforeAll.getCtx(); it('should return the country and the childs containing the search value', async() => { const tx = await models.Zone.beginTransaction({}); diff --git a/modules/zone/back/methods/zone/specs/getUpcomingDeliveries.spec.js b/modules/zone/back/methods/zone/specs/getUpcomingDeliveries.spec.js index cf2a070f3..08d8601bc 100644 --- a/modules/zone/back/methods/zone/specs/getUpcomingDeliveries.spec.js +++ b/modules/zone/back/methods/zone/specs/getUpcomingDeliveries.spec.js @@ -1,7 +1,7 @@ const models = require('vn-loopback/server/server').models; describe('zone getUpcomingDeliveries()', () => { - const {ctx} = beforeAll; + const ctx = beforeAll.getCtx(); it('should check returns data', async() => { const tx = await models.Zone.beginTransaction({}); diff --git a/modules/zone/back/methods/zone/specs/toggleIsIncluded.spec.js b/modules/zone/back/methods/zone/specs/toggleIsIncluded.spec.js index 480c8b7ef..81d02193e 100644 --- a/modules/zone/back/methods/zone/specs/toggleIsIncluded.spec.js +++ b/modules/zone/back/methods/zone/specs/toggleIsIncluded.spec.js @@ -1,10 +1,7 @@ const models = require('vn-loopback/server/server').models; -const {mockLoopBackContext} = require('vn-loopback/../../back/vn-jasmine'); describe('zone toggleIsIncluded()', () => { - beforeAll(() => - mockLoopBackContext() - ); + beforeAll.mockLoopBackContext(); it('should return the created location with isIncluded true', async() => { const tx = await models.Zone.beginTransaction({}); From ee75068e9c0eaadc3b2c09f61600d522f8658992 Mon Sep 17 00:00:00 2001 From: Jon Date: Fri, 14 Jun 2024 08:57:11 +0200 Subject: [PATCH 25/61] refactor: refs #6436 fixed test --- back/methods/starred-module/specs/setPosition.spec.js | 1 + 1 file changed, 1 insertion(+) diff --git a/back/methods/starred-module/specs/setPosition.spec.js b/back/methods/starred-module/specs/setPosition.spec.js index c99206e56..63addeffc 100644 --- a/back/methods/starred-module/specs/setPosition.spec.js +++ b/back/methods/starred-module/specs/setPosition.spec.js @@ -2,6 +2,7 @@ const {models} = require('vn-loopback/server/server'); describe('setPosition()', () => { const ctx = beforeAll.getCtx(); + beforeAll.mockLoopBackContext(); it('should increase the orders module position by replacing it with clients and vice versa', async() => { const tx = await models.StarredModule.beginTransaction({}); From d3f23a6d7a97d4288863200550733484f28e3c87 Mon Sep 17 00:00:00 2001 From: Jon Date: Fri, 14 Jun 2024 09:04:18 +0200 Subject: [PATCH 26/61] fix: refs #6436 fix filter test --- modules/ticket/back/methods/ticket/specs/filter.spec.js | 1 + 1 file changed, 1 insertion(+) diff --git a/modules/ticket/back/methods/ticket/specs/filter.spec.js b/modules/ticket/back/methods/ticket/specs/filter.spec.js index b162ce81f..1d050931b 100644 --- a/modules/ticket/back/methods/ticket/specs/filter.spec.js +++ b/modules/ticket/back/methods/ticket/specs/filter.spec.js @@ -8,6 +8,7 @@ describe('ticket filter()', () => { try { const options = {transaction: tx}; + const ctx = {req: {accessToken: {userId: 9}}, args: {}}; const filter = {order: 'id DESC'}; const result = await models.Ticket.filter(ctx, filter, options); From a42562b0ca1d572d8c9dca5d4864ec8eaee47b48 Mon Sep 17 00:00:00 2001 From: robert Date: Wed, 19 Jun 2024 10:01:32 +0200 Subject: [PATCH 27/61] fear: refs #5855 claim_ratio_routine --- db/routines/bi/procedures/claim_ratio_routine.sql | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/db/routines/bi/procedures/claim_ratio_routine.sql b/db/routines/bi/procedures/claim_ratio_routine.sql index e22162fff..bd273a2c9 100644 --- a/db/routines/bi/procedures/claim_ratio_routine.sql +++ b/db/routines/bi/procedures/claim_ratio_routine.sql @@ -55,8 +55,8 @@ BEGIN -- Recobros - DROP TEMPORARY TABLE IF EXISTS tmp.ticket_list; - CREATE TEMPORARY TABLE tmp.ticket_list + DROP TEMPORARY TABLE IF EXISTS tTicket_list; + CREATE TEMPORARY TABLE tTicket_list (PRIMARY KEY (Id_Ticket)) SELECT DISTINCT t.id Id_Ticket FROM vn.saleComponent sc @@ -74,7 +74,7 @@ BEGIN DELETE g.* FROM vn.greuge g - JOIN tmp.ticket_list t ON g.ticketFk = t.Id_Ticket + JOIN tTicket_list t ON g.ticketFk = t.Id_Ticket WHERE g.greugeTypeFk = 2; INSERT INTO vn.greuge(clientFk, description, amount,shipped, @@ -87,7 +87,7 @@ BEGIN ,tt.Id_Ticket FROM vn.sale s JOIN vn.ticket t ON t.id = s.ticketFk - JOIN tmp.ticket_list tt ON tt.Id_Ticket = t.id + JOIN tTicket_list tt ON tt.Id_Ticket = t.id JOIN vn.saleComponent sc ON sc.saleFk = s.id AND sc.componentFk = 17 GROUP BY t.id @@ -95,7 +95,7 @@ BEGIN UPDATE vn.saleComponent sc JOIN vn.sale s ON s.id = sc.saleFk - JOIN tmp.ticket_list tt ON tt.Id_Ticket = s.ticketFk + JOIN tTicket_list tt ON tt.Id_Ticket = s.ticketFk SET sc.isGreuge = 1 WHERE sc.componentFk = 17; @@ -164,6 +164,6 @@ BEGIN SET cr.recobro = sub.recobro WHERE Id_Cliente IN ( 5189,8942); - DROP TEMPORARY TABLE tmp.ticket_list; + DROP TEMPORARY TABLE tTicket_list; END$$ DELIMITER ; From 0128dfd967d6cebf6a0206c4ce4a064fa1638592 Mon Sep 17 00:00:00 2001 From: robert Date: Wed, 19 Jun 2024 11:30:50 +0200 Subject: [PATCH 28/61] feat: refs #5855 changes required --- db/routines/edi/procedures/floramondo_offerRefresh.sql | 3 +-- db/routines/vn/procedures/copyComponentsFromSaleList.sql | 8 ++++---- db/routines/vn/procedures/ticket_DelayTruck.sql | 8 ++++---- 3 files changed, 9 insertions(+), 10 deletions(-) diff --git a/db/routines/edi/procedures/floramondo_offerRefresh.sql b/db/routines/edi/procedures/floramondo_offerRefresh.sql index 312de7ffb..18d3f8b7e 100644 --- a/db/routines/edi/procedures/floramondo_offerRefresh.sql +++ b/db/routines/edi/procedures/floramondo_offerRefresh.sql @@ -484,8 +484,7 @@ proc: BEGIN DROP TEMPORARY TABLE edi.offer, - itemToInsert, - tmp.buyRecalc; + itemToInsert; SET @isTriggerDisabled = FALSE; diff --git a/db/routines/vn/procedures/copyComponentsFromSaleList.sql b/db/routines/vn/procedures/copyComponentsFromSaleList.sql index 13487af17..ab75486d1 100644 --- a/db/routines/vn/procedures/copyComponentsFromSaleList.sql +++ b/db/routines/vn/procedures/copyComponentsFromSaleList.sql @@ -16,9 +16,9 @@ BEGIN SET @order = 0; - DROP TEMPORARY TABLE IF EXISTS tmp.newSaleList; + DROP TEMPORARY TABLE IF EXISTS tNewSaleList; - CREATE TEMPORARY TABLE tmp.newSaleList + CREATE TEMPORARY TABLE tNewSaleList SELECT id as saleFk, @order := @order + 1 as orden FROM vn.sale WHERE ticketFk = vTargetTicketFk @@ -28,8 +28,8 @@ BEGIN SELECT ns.saleFk, sc.componentFk, sc.value FROM vn.saleComponent sc JOIN tmp.saleList s ON s.saleFk = sc.saleFk - JOIN tmp.newSaleList ns ON ns.orden = s.orden; + JOIN tNewSaleList ns ON ns.orden = s.orden; - DROP TEMPORARY TABLE IF EXISTS tmp.newSaleList; + DROP TEMPORARY TABLE IF EXISTS tNewSaleList; END$$ DELIMITER ; diff --git a/db/routines/vn/procedures/ticket_DelayTruck.sql b/db/routines/vn/procedures/ticket_DelayTruck.sql index 2fb98d07d..81896dd8e 100644 --- a/db/routines/vn/procedures/ticket_DelayTruck.sql +++ b/db/routines/vn/procedures/ticket_DelayTruck.sql @@ -3,14 +3,14 @@ CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`ticket_DelayTruck`( BEGIN DECLARE done INT DEFAULT FALSE; DECLARE vTicketFk INT; - DECLARE cur1 CURSOR FOR SELECT ticketFk FROM tmp.ticket; + DECLARE cur1 CURSOR FOR SELECT ticketFk FROM tTicket; DECLARE CONTINUE HANDLER FOR NOT FOUND SET done = TRUE; CALL vn.productionControl(vWarehouserFk,0) ; - DROP TEMPORARY TABLE IF EXISTS tmp.ticket; - CREATE TEMPORARY TABLE tmp.ticket + DROP TEMPORARY TABLE IF EXISTS tTicket; + CREATE TEMPORARY TABLE tTicket SELECT ticketFk FROM tmp.productionBuffer JOIN alertLevel al ON al.code = 'FREE' @@ -31,6 +31,6 @@ BEGIN END LOOP; CLOSE cur1; - DROP TEMPORARY TABLE tmp.ticket, tmp.productionBuffer; + DROP TEMPORARY TABLE tTicket, tmp.productionBuffer; END$$ DELIMITER ; From 9022f6211639d163a4049962077d0d0d7acff180 Mon Sep 17 00:00:00 2001 From: robert Date: Mon, 24 Jun 2024 08:03:43 +0200 Subject: [PATCH 29/61] feat: refs #5855 changes required --- db/routines/vn/procedures/copyComponentsFromSaleList.sql | 2 +- db/routines/vn/procedures/itemShelving_inventory.sql | 2 +- db/routines/vn/procedures/ticket_add.sql | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/db/routines/vn/procedures/copyComponentsFromSaleList.sql b/db/routines/vn/procedures/copyComponentsFromSaleList.sql index ab75486d1..8db8409f1 100644 --- a/db/routines/vn/procedures/copyComponentsFromSaleList.sql +++ b/db/routines/vn/procedures/copyComponentsFromSaleList.sql @@ -30,6 +30,6 @@ BEGIN JOIN tmp.saleList s ON s.saleFk = sc.saleFk JOIN tNewSaleList ns ON ns.orden = s.orden; - DROP TEMPORARY TABLE IF EXISTS tNewSaleList; + DROP TEMPORARY TABLE tNewSaleList; END$$ DELIMITER ; diff --git a/db/routines/vn/procedures/itemShelving_inventory.sql b/db/routines/vn/procedures/itemShelving_inventory.sql index 6d780c342..f4b8ae165 100644 --- a/db/routines/vn/procedures/itemShelving_inventory.sql +++ b/db/routines/vn/procedures/itemShelving_inventory.sql @@ -60,6 +60,6 @@ BEGIN AND p.sectorFk = vSectorFk ORDER BY p.pickingOrder; - DROP TEMPORARY TABLE IF EXISTS tmp.stockMisfit; + DROP TEMPORARY TABLE tmp.stockMisfit; END$$ DELIMITER ; diff --git a/db/routines/vn/procedures/ticket_add.sql b/db/routines/vn/procedures/ticket_add.sql index c85000218..d9b68997c 100644 --- a/db/routines/vn/procedures/ticket_add.sql +++ b/db/routines/vn/procedures/ticket_add.sql @@ -66,7 +66,7 @@ BEGIN CALL util.throw ('NOT_ZONE_WITH_THIS_PARAMETERS'); END IF; - DROP TEMPORARY TABLE IF EXISTS tmp.zoneGetShipped; + DROP TEMPORARY TABLE tmp.zoneGetShipped; END IF; INSERT INTO ticket ( From 2797a731c548b83185af42abebf9044c39ce0b07 Mon Sep 17 00:00:00 2001 From: carlossa Date: Tue, 25 Jun 2024 12:00:49 +0200 Subject: [PATCH 30/61] refs #6952 subName --- .../reports/delivery-note/delivery-note.html | 3 ++- .../reports/delivery-note/locale/en.yml | 5 +++-- .../reports/delivery-note/locale/es.yml | 5 +++-- .../reports/delivery-note/locale/fr.yml | 7 ++++--- .../reports/delivery-note/locale/pt.yml | 5 +++-- .../reports/delivery-note/sql/sales.sql | 19 ++++++++++--------- 6 files changed, 25 insertions(+), 19 deletions(-) diff --git a/print/templates/reports/delivery-note/delivery-note.html b/print/templates/reports/delivery-note/delivery-note.html index 92dd1b126..540a80a3a 100644 --- a/print/templates/reports/delivery-note/delivery-note.html +++ b/print/templates/reports/delivery-note/delivery-note.html @@ -81,6 +81,7 @@ {{sale.tag5}} {{sale.value5}} {{sale.tag6}} {{sale.value6}} {{sale.tag7}} {{sale.value7}} + {{$t('producer')}} {{ sale.subName }} @@ -249,4 +250,4 @@ v-bind:center-text="client.socialName" v-bind="$props"> - \ No newline at end of file + diff --git a/print/templates/reports/delivery-note/locale/en.yml b/print/templates/reports/delivery-note/locale/en.yml index 5902da8b3..84b31e494 100644 --- a/print/templates/reports/delivery-note/locale/en.yml +++ b/print/templates/reports/delivery-note/locale/en.yml @@ -20,6 +20,7 @@ vatType: VAT Type digitalSignature: Digital signature plantPassport: Plant passport packages: Packages +producer: Producer services: title: Services theader: @@ -44,7 +45,7 @@ taxes: taxBase: Tax base tax: Tax fee: Fee - tfoot: + tfoot: subtotal: Subtotal total: Total -observations: Observations \ No newline at end of file +observations: Observations diff --git a/print/templates/reports/delivery-note/locale/es.yml b/print/templates/reports/delivery-note/locale/es.yml index d87198f45..891e59d77 100644 --- a/print/templates/reports/delivery-note/locale/es.yml +++ b/print/templates/reports/delivery-note/locale/es.yml @@ -15,6 +15,7 @@ discount: Dto. vat: IVA amount: Importe total: Total +producer: Productor subtotal: Subtotal vatType: Tipo de IVA digitalSignature: Firma digital @@ -45,7 +46,7 @@ taxes: taxBase: Base imp. tax: Tasa fee: Cuota - tfoot: + tfoot: subtotal: Subtotal total: Total -observations: Observaciones \ No newline at end of file +observations: Observaciones diff --git a/print/templates/reports/delivery-note/locale/fr.yml b/print/templates/reports/delivery-note/locale/fr.yml index 603623a47..87cd2bcde 100644 --- a/print/templates/reports/delivery-note/locale/fr.yml +++ b/print/templates/reports/delivery-note/locale/fr.yml @@ -14,7 +14,8 @@ price: PRIX/u discount: Remise vat: TVA amount: Montant -total: Total +producer: producteur +total: Total subtotal: Total partiel vatType: Type de TVA digitalSignature: Signature numérique @@ -45,7 +46,7 @@ taxes: taxBase: Base imposable tax: Taxe fee: Quote - tfoot: + tfoot: subtotal: Total partiel total: Total -observations: Observations \ No newline at end of file +observations: Observations diff --git a/print/templates/reports/delivery-note/locale/pt.yml b/print/templates/reports/delivery-note/locale/pt.yml index fb49d230b..be39eb3f0 100644 --- a/print/templates/reports/delivery-note/locale/pt.yml +++ b/print/templates/reports/delivery-note/locale/pt.yml @@ -14,6 +14,7 @@ price: PVP/u discount: Dto. vat: IVA amount: Importe +producer: Produtor total: Total subtotal: Sub-total vatType: Tipo de IVA @@ -45,7 +46,7 @@ taxes: taxBase: Tributável tax: Taxa fee: Compartilhado - tfoot: + tfoot: subtotal: Subtotal total: Total -observations: Observações \ No newline at end of file +observations: Observações diff --git a/print/templates/reports/delivery-note/sql/sales.sql b/print/templates/reports/delivery-note/sql/sales.sql index c449030cf..4cbffa12f 100644 --- a/print/templates/reports/delivery-note/sql/sales.sql +++ b/print/templates/reports/delivery-note/sql/sales.sql @@ -1,4 +1,4 @@ -SELECT +SELECT s.id, s.itemFk, s.concept, @@ -15,12 +15,13 @@ SELECT s.ticketFk, tcl.code vatType, ib.ediBotanic botanical, - i.tag5, + i.tag5, i.value5, - i.tag6, - i.value6, - i.tag7, - i.value7 + i.tag6, + i.value6, + i.tag7, + i.value7, + i.subName FROM vn.sale s LEFT JOIN saleComponent sc ON sc.saleFk = s.id LEFT JOIN component cr ON cr.id = sc.componentFk @@ -32,12 +33,12 @@ FROM vn.sale s LEFT JOIN supplier sp ON sp.id = t.companyFk LEFT JOIN itemType it ON it.id = i.typeFk LEFT JOIN itemCategory ic ON ic.id = it.categoryFk - LEFT JOIN itemTaxCountry itc ON itc.itemFk = i.id - AND itc.countryFk = sp.countryFk + LEFT JOIN itemTaxCountry itc ON itc.itemFk = i.id + AND itc.countryFk = sp.countryFk LEFT JOIN taxClass tcl ON tcl.id = itc.taxClassFk LEFT JOIN itemBotanicalWithGenus ib ON ib.itemFk = i.id AND ic.code = 'plant' AND ib.ediBotanic IS NOT NULL WHERE s.ticketFk = ? GROUP BY s.id -ORDER BY (it.isPackaging), s.concept, s.itemFk \ No newline at end of file +ORDER BY (it.isPackaging), s.concept, s.itemFk From b4afb883fc71e335ef41572d2dbc77c1126f0536 Mon Sep 17 00:00:00 2001 From: Javier Segarra Date: Wed, 26 Jun 2024 09:35:18 +0200 Subject: [PATCH 31/61] feat(salix): refs #6436 #6436 remove unnecessary object.assign --- back/vn-jasmine.js | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/back/vn-jasmine.js b/back/vn-jasmine.js index c2d8a497c..2b981c6d9 100644 --- a/back/vn-jasmine.js +++ b/back/vn-jasmine.js @@ -27,13 +27,7 @@ const default_loopback_ctx = userId => { }; function vnBeforeAll() { - Object.assign(beforeAll, {getCtx: default_before_all}); - Object.assign(beforeAll, {mockLoopBackContext}); -} -function mockBeforeAll(value = default_before_all) { - const origin = beforeAll.ctx; - Object.assign(origin, value); - return origin; + Object.assign(beforeAll, {getCtx: default_before_all, mockLoopBackContext}); } const mockLoopBackContext = userId => { @@ -46,7 +40,7 @@ const mockLoopBackContext = userId => { return activeCtx; }; module.exports = { - mockBeforeAll, mockLoopBackContext + mockLoopBackContext }; (function init() { From a23f485296c594c23779a8879ba9cc3e1b4a781e Mon Sep 17 00:00:00 2001 From: guillermo Date: Mon, 1 Jul 2024 11:11:16 +0200 Subject: [PATCH 32/61] refactor: refs #7424 Component type refactor --- db/routines/bi/procedures/rutasAnalyze.sql | 2 +- .../bi/views/tarifa_componentes_series.sql | 2 +- db/routines/vn/procedures/sale_PriceFix.sql | 2 +- .../procedures/ticket_checkNoComponents.sql | 3 +- .../procedures/ticket_getFromFloramondo.sql | 4 +- db/routines/vn/views/saleCost.sql | 2 +- .../vn/views/sale_freightComponent.sql | 2 +- .../11119-tealGerbera/00-firstScript.sql | 9 ++ .../ticket/back/models/component-type.json | 2 +- modules/ticket/front/component/index.html | 2 +- modules/ticket/front/component/index.js | 2 +- .../reports/delivery-note/sql/sales.sql | 85 +++++++++---------- 12 files changed, 63 insertions(+), 54 deletions(-) create mode 100644 db/versions/11119-tealGerbera/00-firstScript.sql diff --git a/db/routines/bi/procedures/rutasAnalyze.sql b/db/routines/bi/procedures/rutasAnalyze.sql index 5f0d55c7a..e277968bf 100644 --- a/db/routines/bi/procedures/rutasAnalyze.sql +++ b/db/routines/bi/procedures/rutasAnalyze.sql @@ -59,7 +59,7 @@ BEGIN JOIN vn.saleComponent sc ON sc.saleFk = s.id JOIN vn.component c ON c.id = sc.componentFk JOIN vn.componentType ct ON ct.id = c.typeFk - WHERE ct.code = 'FREIGHT' + WHERE ct.code = 'freight' AND r.created BETWEEN vDatedFrom AND vDatedTo GROUP BY r.id ) sub ON sub.routeFk = r.Id_Ruta diff --git a/db/routines/bi/views/tarifa_componentes_series.sql b/db/routines/bi/views/tarifa_componentes_series.sql index f231ae420..ed2f8e29a 100644 --- a/db/routines/bi/views/tarifa_componentes_series.sql +++ b/db/routines/bi/views/tarifa_componentes_series.sql @@ -2,7 +2,7 @@ CREATE OR REPLACE DEFINER=`root`@`localhost` SQL SECURITY DEFINER VIEW `bi`.`tarifa_componentes_series` AS SELECT `ct`.`id` AS `tarifa_componentes_series_id`, - `ct`.`type` AS `Serie`, + `ct`.`name` AS `Serie`, `ct`.`isBase` AS `base`, `ct`.`isMargin` AS `margen` FROM `vn`.`componentType` `ct` diff --git a/db/routines/vn/procedures/sale_PriceFix.sql b/db/routines/vn/procedures/sale_PriceFix.sql index 8ffa77070..5f956cba8 100644 --- a/db/routines/vn/procedures/sale_PriceFix.sql +++ b/db/routines/vn/procedures/sale_PriceFix.sql @@ -8,7 +8,7 @@ BEGIN JOIN vn.component c ON c.id = sc.componentFk JOIN vn.componentType ct ON ct.id = c.typeFk WHERE s.ticketFk = vTicketFk - AND ct.`type` = 'otros'; + AND ct.code = 'other'; UPDATE vn.sale s JOIN ( diff --git a/db/routines/vn/procedures/ticket_checkNoComponents.sql b/db/routines/vn/procedures/ticket_checkNoComponents.sql index 28fe333f0..b03427192 100644 --- a/db/routines/vn/procedures/ticket_checkNoComponents.sql +++ b/db/routines/vn/procedures/ticket_checkNoComponents.sql @@ -20,7 +20,8 @@ BEGIN JOIN itemCategory ic ON ic.id = tp.categoryFk JOIN saleComponent sc ON sc.saleFk = s.id JOIN component c ON c.id = sc.componentFk - JOIN componentType ct ON ct.id = c.typeFk AND ct.id = 1 + JOIN componentType ct ON ct.id = c.typeFk + AND ct.code = 'cost' WHERE t.shipped BETWEEN vShippedFrom AND vShippedTo AND ic.merchandise; diff --git a/db/routines/vn/procedures/ticket_getFromFloramondo.sql b/db/routines/vn/procedures/ticket_getFromFloramondo.sql index 4d83d6dda..5f2bedbb1 100644 --- a/db/routines/vn/procedures/ticket_getFromFloramondo.sql +++ b/db/routines/vn/procedures/ticket_getFromFloramondo.sql @@ -66,7 +66,7 @@ BEGIN JOIN vn.componentType ct ON ct.id = c.typeFk JOIN vn.sale s ON s.id = sc.saleFk JOIN tmp.ticket t ON t.ticketFk = s.ticketFk - WHERE ct.code = 'FREIGHT' + WHERE ct.code = 'freight' GROUP BY t.ticketFk) sb ON sb.ticketFk = tf.ticketFk SET tf.freight = sb.freight; @@ -88,7 +88,7 @@ BEGIN -- Margin UPDATE tmp.ticketFloramondo tf - JOIN (SELECT SUM(IF(ct.code = 'COST',sc.value, 0)) cost, + JOIN (SELECT SUM(IF(ct.code = 'cost',sc.value, 0)) cost, SUM(IF(ct.isMargin, sc.value, 0)) margin, t.ticketFk FROM vn.saleComponent sc diff --git a/db/routines/vn/views/saleCost.sql b/db/routines/vn/views/saleCost.sql index 27265aa93..304b9e3a3 100644 --- a/db/routines/vn/views/saleCost.sql +++ b/db/routines/vn/views/saleCost.sql @@ -19,4 +19,4 @@ FROM ( ) JOIN `vn`.`componentType` `ct` ON(`ct`.`id` = `c`.`typeFk`) ) -WHERE `ct`.`type` = 'coste' +WHERE `ct`.`code` = 'cost' diff --git a/db/routines/vn/views/sale_freightComponent.sql b/db/routines/vn/views/sale_freightComponent.sql index 7a329e0ee..269a8cca1 100644 --- a/db/routines/vn/views/sale_freightComponent.sql +++ b/db/routines/vn/views/sale_freightComponent.sql @@ -16,6 +16,6 @@ FROM ( ) JOIN `vn`.`componentType` `ct` ON( `ct`.`id` = `c`.`typeFk` - AND `ct`.`type` = 'agencia' + AND `ct`.`code` = 'freight' ) ) diff --git a/db/versions/11119-tealGerbera/00-firstScript.sql b/db/versions/11119-tealGerbera/00-firstScript.sql new file mode 100644 index 000000000..40b3b0424 --- /dev/null +++ b/db/versions/11119-tealGerbera/00-firstScript.sql @@ -0,0 +1,9 @@ +ALTER TABLE vn.componentType + CHANGE code code varchar(20) CHARACTER SET utf8mb3 COLLATE utf8mb3_unicode_ci DEFAULT NULL NULL AFTER id; +ALTER TABLE vn.componentType + CHANGE `type` name varchar(45) CHARACTER SET utf8mb3 COLLATE utf8mb3_unicode_ci NOT NULL; +UPDATE IGNORE vn.componentType + SET code = LOWER(code); +UPDATE IGNORE vn.componentType + SET code = 'other' + WHERE id = 12; \ No newline at end of file diff --git a/modules/ticket/back/models/component-type.json b/modules/ticket/back/models/component-type.json index 26daf5216..735227a35 100644 --- a/modules/ticket/back/models/component-type.json +++ b/modules/ticket/back/models/component-type.json @@ -12,7 +12,7 @@ "type": "number", "description": "Identifier" }, - "type": { + "name": { "type": "string" }, "isBase":{ diff --git a/modules/ticket/front/component/index.html b/modules/ticket/front/component/index.html index 39b54b461..2a3a80f3e 100644 --- a/modules/ticket/front/component/index.html +++ b/modules/ticket/front/component/index.html @@ -51,7 +51,7 @@ ng-repeat="saleComponent in sale.components track by saleComponent.componentFk" class="components"> - {{::saleComponent.component.componentType.type}} + {{::saleComponent.component.componentType.name}} {{::saleComponent.component.name}} diff --git a/modules/ticket/front/component/index.js b/modules/ticket/front/component/index.js index 3f262f457..aa755e808 100644 --- a/modules/ticket/front/component/index.js +++ b/modules/ticket/front/component/index.js @@ -20,7 +20,7 @@ class Controller extends Section { include: { relation: 'componentType', scope: { - fields: ['type', 'isBase'] + fields: ['name', 'isBase'] } } } diff --git a/print/templates/reports/delivery-note/sql/sales.sql b/print/templates/reports/delivery-note/sql/sales.sql index c449030cf..636bbc228 100644 --- a/print/templates/reports/delivery-note/sql/sales.sql +++ b/print/templates/reports/delivery-note/sql/sales.sql @@ -1,43 +1,42 @@ -SELECT - s.id, - s.itemFk, - s.concept, - s.quantity, - s.price, - s.price - SUM(IF(ctr.id = 6, sc.value, 0)) netPrice, - s.discount, - i.size, - i.stems, - i.category, - it.id itemTypeId, - o.code AS origin, - i.inkFk, - s.ticketFk, - tcl.code vatType, - ib.ediBotanic botanical, - i.tag5, - i.value5, - i.tag6, - i.value6, - i.tag7, - i.value7 -FROM vn.sale s - LEFT JOIN saleComponent sc ON sc.saleFk = s.id - LEFT JOIN component cr ON cr.id = sc.componentFk - LEFT JOIN componentType ctr ON ctr.id = cr.typeFk - LEFT JOIN item i ON i.id = s.itemFk - LEFT JOIN ticket t ON t.id = s.ticketFk - LEFT JOIN origin o ON o.id = i.originFk - LEFT JOIN country c ON c.id = o.countryFk - LEFT JOIN supplier sp ON sp.id = t.companyFk - LEFT JOIN itemType it ON it.id = i.typeFk - LEFT JOIN itemCategory ic ON ic.id = it.categoryFk - LEFT JOIN itemTaxCountry itc ON itc.itemFk = i.id - AND itc.countryFk = sp.countryFk - LEFT JOIN taxClass tcl ON tcl.id = itc.taxClassFk - LEFT JOIN itemBotanicalWithGenus ib ON ib.itemFk = i.id - AND ic.code = 'plant' - AND ib.ediBotanic IS NOT NULL -WHERE s.ticketFk = ? -GROUP BY s.id -ORDER BY (it.isPackaging), s.concept, s.itemFk \ No newline at end of file +SELECT s.id, + s.itemFk, + s.concept, + s.quantity, + s.price, + s.price - SUM(IF(ctr.code = 'freight', sc.value, 0)) netPrice, + s.discount, + i.size, + i.stems, + i.category, + it.id itemTypeId, + o.code origin, + i.inkFk, + s.ticketFk, + tcl.code vatType, + ib.ediBotanic botanical, + i.tag5, + i.value5, + i.tag6, + i.value6, + i.tag7, + i.value7 + FROM vn.sale s + LEFT JOIN saleComponent sc ON sc.saleFk = s.id + LEFT JOIN component cr ON cr.id = sc.componentFk + LEFT JOIN componentType ctr ON ctr.id = cr.typeFk + LEFT JOIN item i ON i.id = s.itemFk + LEFT JOIN ticket t ON t.id = s.ticketFk + LEFT JOIN origin o ON o.id = i.originFk + LEFT JOIN country c ON c.id = o.countryFk + LEFT JOIN supplier sp ON sp.id = t.companyFk + LEFT JOIN itemType it ON it.id = i.typeFk + LEFT JOIN itemCategory ic ON ic.id = it.categoryFk + LEFT JOIN itemTaxCountry itc ON itc.itemFk = i.id + AND itc.countryFk = sp.countryFk + LEFT JOIN taxClass tcl ON tcl.id = itc.taxClassFk + LEFT JOIN itemBotanicalWithGenus ib ON ib.itemFk = i.id + AND ic.code = 'plant' + AND ib.ediBotanic IS NOT NULL + WHERE s.ticketFk = ? + GROUP BY s.id + ORDER BY (it.isPackaging), s.concept, s.itemFk \ No newline at end of file From 0240734a4b99c4003ce909e7aeba121e2c062b8f Mon Sep 17 00:00:00 2001 From: carlossa Date: Mon, 1 Jul 2024 11:50:37 +0200 Subject: [PATCH 33/61] refs #6897 fix filter --- modules/entry/back/methods/entry/filter.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/modules/entry/back/methods/entry/filter.js b/modules/entry/back/methods/entry/filter.js index 1cd12b737..f3f14e7c1 100644 --- a/modules/entry/back/methods/entry/filter.js +++ b/modules/entry/back/methods/entry/filter.js @@ -173,7 +173,8 @@ module.exports = Self => { s.name AS supplierName, s.nickname AS supplierAlias, co.code AS companyCode, - cu.code AS currencyCode + cu.code AS currencyCode, + t.ref AS travelRef FROM vn.entry e JOIN vn.supplier s ON s.id = e.supplierFk JOIN vn.travel t ON t.id = e.travelFk From 9e5f416d55bc2b159c99c33498da8ed0d33b0967 Mon Sep 17 00:00:00 2001 From: guillermo Date: Mon, 1 Jul 2024 12:06:30 +0200 Subject: [PATCH 34/61] refactor: refs #7418 Item type refactor --- db/dump/fixtures.before.sql | 1 - db/routines/vn2008/views/Tipos.sql | 7 +------ db/versions/11120-brownTulip/00-firstScript.sql | 6 ++++++ 3 files changed, 7 insertions(+), 7 deletions(-) create mode 100644 db/versions/11120-brownTulip/00-firstScript.sql diff --git a/db/dump/fixtures.before.sql b/db/dump/fixtures.before.sql index 27f84bdfb..61d46d133 100644 --- a/db/dump/fixtures.before.sql +++ b/db/dump/fixtures.before.sql @@ -3232,7 +3232,6 @@ INSERT IGNORE INTO vn.itemType workerFk = 103, isInventory = TRUE, life = 10, - density = 250, itemPackingTypeFk = NULL, temperatureFk = 'warm'; diff --git a/db/routines/vn2008/views/Tipos.sql b/db/routines/vn2008/views/Tipos.sql index 4cde954f1..5b96c1766 100644 --- a/db/routines/vn2008/views/Tipos.sql +++ b/db/routines/vn2008/views/Tipos.sql @@ -9,14 +9,9 @@ AS SELECT `it`.`id` AS `tipo_id`, `it`.`workerFk` AS `Id_Trabajador`, `it`.`life` AS `life`, `it`.`isPackaging` AS `isPackaging`, - `it`.`density` AS `density`, `it`.`isInventory` AS `inventory`, `it`.`created` AS `odbc_date`, `it`.`making` AS `confeccion`, `it`.`temperatureFk` AS `Temperatura`, - `it`.`promo` AS `promo`, - `it`.`maneuver` AS `maneuver`, - `it`.`target` AS `target`, - `it`.`topMargin` AS `top_margin`, - `it`.`profit` AS `profit` + `it`.`promo` AS `promo` FROM `vn`.`itemType` `it` diff --git a/db/versions/11120-brownTulip/00-firstScript.sql b/db/versions/11120-brownTulip/00-firstScript.sql new file mode 100644 index 000000000..c4ded80bb --- /dev/null +++ b/db/versions/11120-brownTulip/00-firstScript.sql @@ -0,0 +1,6 @@ +ALTER TABLE vn.itemType + CHANGE maneuver maneuver__ double DEFAULT 0.21 NOT NULL COMMENT '@deprecated 2024-07-01 refs #7418', + CHANGE target target__ double DEFAULT 0.15 NOT NULL COMMENT '@deprecated 2024-07-01 refs #7418', + CHANGE topMargin topMargin__ double DEFAULT 0.3 NOT NULL COMMENT '@deprecated 2024-07-01 refs #7418', + CHANGE profit profit__ double DEFAULT 0.02 NOT NULL COMMENT '@deprecated 2024-07-01 refs #7418', + CHANGE density density__ double DEFAULT 167 NOT NULL COMMENT '@deprecated 2024-07-01 refs #7418 Almacena el valor por defecto de la densidad en kg/m3 para el calculo de los portes aereos, en articulos se guarda la correcta'; \ No newline at end of file From 2ed31ee1d3702df9a7e3f31571b91f50f13e2b9e Mon Sep 17 00:00:00 2001 From: ivanm Date: Mon, 1 Jul 2024 13:26:59 +0200 Subject: [PATCH 35/61] refs #7651 Add editorFk and triggers --- .../account/triggers/mailAliasAccount_beforeInsert.sql | 8 ++++++++ .../account/triggers/mailAliasAccount_beforeUpdate.sql | 8 ++++++++ db/versions/11121-silverAralia/00-firstScript.sql | 4 ++++ 3 files changed, 20 insertions(+) create mode 100644 db/routines/account/triggers/mailAliasAccount_beforeInsert.sql create mode 100644 db/routines/account/triggers/mailAliasAccount_beforeUpdate.sql create mode 100644 db/versions/11121-silverAralia/00-firstScript.sql diff --git a/db/routines/account/triggers/mailAliasAccount_beforeInsert.sql b/db/routines/account/triggers/mailAliasAccount_beforeInsert.sql new file mode 100644 index 000000000..a435832f2 --- /dev/null +++ b/db/routines/account/triggers/mailAliasAccount_beforeInsert.sql @@ -0,0 +1,8 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `account`.`mailAliasAccount_beforeInsert` + BEFORE INSERT ON `mailAliasAccount` + FOR EACH ROW +BEGIN + SET NEW.editorFk = account.myUser_getId(); +END$$ +DELIMITER ; \ No newline at end of file diff --git a/db/routines/account/triggers/mailAliasAccount_beforeUpdate.sql b/db/routines/account/triggers/mailAliasAccount_beforeUpdate.sql new file mode 100644 index 000000000..471a34900 --- /dev/null +++ b/db/routines/account/triggers/mailAliasAccount_beforeUpdate.sql @@ -0,0 +1,8 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `account`.`mailAliasAccount_beforeUpdate` + BEFORE UPDATE ON `mailAliasAccount` + FOR EACH ROW +BEGIN + SET NEW.editorFk = account.myUser_getId(); +END$$ +DELIMITER ; \ No newline at end of file diff --git a/db/versions/11121-silverAralia/00-firstScript.sql b/db/versions/11121-silverAralia/00-firstScript.sql new file mode 100644 index 000000000..e74ca2e95 --- /dev/null +++ b/db/versions/11121-silverAralia/00-firstScript.sql @@ -0,0 +1,4 @@ +ALTER TABLE account.mailAliasAccount + ADD editorFk INT UNSIGNED NULL, + ADD CONSTRAINT mailAliasAccount_editorFk FOREIGN KEY (editorFk) + REFERENCES account.`user`(id); \ No newline at end of file From f47197cd8085bb9a762fb98998bd3f8c6b2f3ca6 Mon Sep 17 00:00:00 2001 From: Javier Segarra Date: Mon, 1 Jul 2024 14:06:28 +0200 Subject: [PATCH 36/61] Merge branch '7648_customerEntries' into 7648_dev_customerEntries --- .../11118-limeCymbidium/00-firstScript.sql | 10 ++++++ modules/entry/back/methods/entry/buyLabel.js | 3 +- modules/entry/back/methods/entry/filter.js | 8 +++-- modules/entry/back/methods/entry/getBuys.js | 34 +++++++++++++++---- .../back/methods/entry/specs/filter.spec.js | 18 ++++++---- .../back/methods/entry/specs/getBuys.spec.js | 9 ++++- .../back/methods/supplier/isSupplier.js | 28 +++++++++++++++ modules/supplier/back/models/supplier.js | 1 + 8 files changed, 95 insertions(+), 16 deletions(-) create mode 100644 db/versions/11118-limeCymbidium/00-firstScript.sql create mode 100644 modules/supplier/back/methods/supplier/isSupplier.js diff --git a/db/versions/11118-limeCymbidium/00-firstScript.sql b/db/versions/11118-limeCymbidium/00-firstScript.sql new file mode 100644 index 000000000..52ab2acbd --- /dev/null +++ b/db/versions/11118-limeCymbidium/00-firstScript.sql @@ -0,0 +1,10 @@ +-- Place your SQL code here +-- Auto-generated SQL script #202406281423 +INSERT INTO salix.ACL (model,property,accessType,permission,principalType,principalId) + VALUES ('Entry','filter','READ','ALLOW','ROLE','$authenticated'); + +-- Auto-generated SQL script #202406281452 +INSERT INTO salix.ACL (model,property,accessType,permission,principalType,principalId) + VALUES ('Entry','getBuys','READ','ALLOW','ROLE','$authenticated'); +INSERT INTO salix.ACL (model,property,accessType,permission,principalType,principalId) + VALUES ('Entry','buyLabel','READ','ALLOW','ROLE','$authenticated'); diff --git a/modules/entry/back/methods/entry/buyLabel.js b/modules/entry/back/methods/entry/buyLabel.js index 650b05c97..d9b0ebf1d 100644 --- a/modules/entry/back/methods/entry/buyLabel.js +++ b/modules/entry/back/methods/entry/buyLabel.js @@ -29,7 +29,8 @@ module.exports = Self => { http: { path: '/:id/buy-label', verb: 'GET' - } + }, + accessScopes: ['DEFAULT', 'read:multimedia'] }); Self.buyLabel = (ctx, id) => Self.printReport(ctx, id, 'buy-label'); diff --git a/modules/entry/back/methods/entry/filter.js b/modules/entry/back/methods/entry/filter.js index 1cd12b737..7d287b842 100644 --- a/modules/entry/back/methods/entry/filter.js +++ b/modules/entry/back/methods/entry/filter.js @@ -112,7 +112,7 @@ module.exports = Self => { if (typeof options == 'object') Object.assign(myOptions, options); - + const isSupplier = await Self.app.models.Supplier.isSupplier(ctx, options); const conn = Self.dataSource.connector; const where = buildFilter(ctx.args, (param, value) => { switch (param) { @@ -146,7 +146,11 @@ module.exports = Self => { } }); filter = mergeFilters(ctx.args.filter, {where}); - + delete filter.order; + if (isSupplier) { + if (!filter.where) filter.where = {}; + filter.where.supplierFk = ctx.req.accessToken.userId; + } const stmts = []; let stmt; stmt = new ParameterizedSQL( diff --git a/modules/entry/back/methods/entry/getBuys.js b/modules/entry/back/methods/entry/getBuys.js index 0ed77e8d1..cfb065b83 100644 --- a/modules/entry/back/methods/entry/getBuys.js +++ b/modules/entry/back/methods/entry/getBuys.js @@ -1,7 +1,10 @@ +const ForbiddenError = require('vn-loopback/util/forbiddenError'); +const UserError = require('vn-loopback/util/user-error'); + const mergeFilters = require('vn-loopback/util/filter').mergeFilters; module.exports = Self => { - Self.remoteMethod('getBuys', { + Self.remoteMethodCtx('getBuys', { description: 'Returns buys for one entry', accessType: 'READ', accepts: [{ @@ -27,13 +30,18 @@ module.exports = Self => { } }); - Self.getBuys = async(id, filter, options) => { + Self.getBuys = async(ctx, id, filter, options) => { const models = Self.app.models; const myOptions = {}; if (typeof options == 'object') Object.assign(myOptions, options); + const isSupplier = await Self.app.models.Supplier.isSupplier(ctx, options); + if (isSupplier) { + const isEntryOwner = (await Self.findById(id)).supplierFk === ctx.req.accessToken.userId; + if (! isEntryOwner) throw new UserError('Access Denied'); + } let defaultFilter = { where: {entryFk: id}, fields: [ @@ -49,9 +57,23 @@ module.exports = Self => { 'buyingValue', 'price2', 'price3', - 'printedStickers' + 'printedStickers', + 'entryFk' ], - include: { + include: [{ + relation: 'entry', + scope: { + fields: [ + 'id', 'supplierFk' + ], + include: { + relation: 'supplier', scope: { + fields: ['id'] + } + } + } + }, + { relation: 'item', scope: { fields: [ @@ -82,9 +104,9 @@ module.exports = Self => { } } } - } + }] }; - + delete filter.order; defaultFilter = mergeFilters(defaultFilter, filter); return models.Buy.find(defaultFilter, myOptions); diff --git a/modules/entry/back/methods/entry/specs/filter.spec.js b/modules/entry/back/methods/entry/specs/filter.spec.js index 28763bc81..e116d1c5f 100644 --- a/modules/entry/back/methods/entry/specs/filter.spec.js +++ b/modules/entry/back/methods/entry/specs/filter.spec.js @@ -9,7 +9,8 @@ describe('Entry filter()', () => { const ctx = { args: { search: 1 - } + }, + req: {accessToken: {userId: 9}} }; const result = await models.Entry.filter(ctx, options); @@ -32,7 +33,8 @@ describe('Entry filter()', () => { const ctx = { args: { currencyFk: 1 - } + }, + req: {accessToken: {userId: 9}} }; const result = await models.Entry.filter(ctx, options); @@ -54,7 +56,8 @@ describe('Entry filter()', () => { const ctx = { args: { supplierFk: 2 - } + }, + req: {accessToken: {userId: 9}} }; const result = await models.Entry.filter(ctx, options); @@ -76,7 +79,8 @@ describe('Entry filter()', () => { const ctx = { args: { companyFk: 442 - } + }, + req: {accessToken: {userId: 9}} }; const result = await models.Entry.filter(ctx, options); @@ -98,7 +102,8 @@ describe('Entry filter()', () => { const ctx = { args: { isBooked: true, - } + }, + req: {accessToken: {userId: 9}} }; const result = await models.Entry.filter(ctx, options); @@ -121,7 +126,8 @@ describe('Entry filter()', () => { args: { reference: 'movement', travelFk: '2' - } + }, + req: {accessToken: {userId: 9}} }; const result = await models.Entry.filter(ctx, options); diff --git a/modules/entry/back/methods/entry/specs/getBuys.spec.js b/modules/entry/back/methods/entry/specs/getBuys.spec.js index cf4462e48..44b2ff5bc 100644 --- a/modules/entry/back/methods/entry/specs/getBuys.spec.js +++ b/modules/entry/back/methods/entry/specs/getBuys.spec.js @@ -7,7 +7,14 @@ describe('entry getBuys()', () => { const options = {transaction: tx}; try { - const result = await models.Entry.getBuys(entryId, options); + const ctx = { + args: { + search: 1 + }, + req: {accessToken: {userId: 2}} + }; + + const result = await models.Entry.getBuys(ctx, entryId, options); const length = result.length; const anyResult = result[Math.floor(Math.random() * Math.floor(length))]; diff --git a/modules/supplier/back/methods/supplier/isSupplier.js b/modules/supplier/back/methods/supplier/isSupplier.js new file mode 100644 index 000000000..d13f304a8 --- /dev/null +++ b/modules/supplier/back/methods/supplier/isSupplier.js @@ -0,0 +1,28 @@ +const UserError = require('vn-loopback/util/user-error'); + +module.exports = Self => { + Self.remoteMethodCtx('isSupplier', { + description: 'Check is supplierFk exists as supplier', + accessType: 'READ', + returns: { + type: 'boolean', + root: true + }, + http: { + path: `/isSupplier`, + verb: 'GET' + } + }); + + Self.isSupplier = async(ctx, options) => { + const myOptions = {validate: false}; + + if (typeof options == 'object') + Object.assign(myOptions, options); + + const userId = ctx.req.accessToken.userId; + const exists = await Self.findById(userId); + + return !!exists; + }; +}; diff --git a/modules/supplier/back/models/supplier.js b/modules/supplier/back/models/supplier.js index 2d3ffef3e..6094602b6 100644 --- a/modules/supplier/back/models/supplier.js +++ b/modules/supplier/back/models/supplier.js @@ -12,6 +12,7 @@ module.exports = Self => { require('../methods/supplier/campaignMetricsEmail')(Self); require('../methods/supplier/newSupplier')(Self); require('../methods/supplier/getItemsPackaging')(Self); + require('../methods/supplier/isSupplier')(Self); Self.validatesPresenceOf('name', { message: 'The social name cannot be empty' From f0326860baaac84570a1e261cb1738860760bf4a Mon Sep 17 00:00:00 2001 From: Javier Segarra Date: Mon, 1 Jul 2024 14:07:46 +0200 Subject: [PATCH 37/61] feat(salix): refs #7648 #7648 add new fields --- modules/entry/back/methods/entry/filter.js | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/modules/entry/back/methods/entry/filter.js b/modules/entry/back/methods/entry/filter.js index 7d287b842..929df8bd9 100644 --- a/modules/entry/back/methods/entry/filter.js +++ b/modules/entry/back/methods/entry/filter.js @@ -177,10 +177,15 @@ module.exports = Self => { s.name AS supplierName, s.nickname AS supplierAlias, co.code AS companyCode, - cu.code AS currencyCode + cu.code AS currencyCode, + t.shipped AS shipped, + t.landed AS landed, + t.warehouseInFk AS warehouseId, + w.name AS warehouseName FROM vn.entry e JOIN vn.supplier s ON s.id = e.supplierFk JOIN vn.travel t ON t.id = e.travelFk + JOIN vn.warehouse w ON w.id = t.warehouseInFk JOIN vn.company co ON co.id = e.companyFk JOIN vn.currency cu ON cu.id = e.currencyFk` ); From 29aecd62a527c203430e0b84ad3ffe466d4bff9f Mon Sep 17 00:00:00 2001 From: ivanm Date: Mon, 1 Jul 2024 14:51:32 +0200 Subject: [PATCH 38/61] refs #7651 add afterDelete trigger --- .../triggers/mailAliasAccount_afterDelete.sql | 12 ++++++++++++ db/versions/11121-silverAralia/00-firstScript.sql | 2 +- 2 files changed, 13 insertions(+), 1 deletion(-) create mode 100644 db/routines/account/triggers/mailAliasAccount_afterDelete.sql diff --git a/db/routines/account/triggers/mailAliasAccount_afterDelete.sql b/db/routines/account/triggers/mailAliasAccount_afterDelete.sql new file mode 100644 index 000000000..83af7169c --- /dev/null +++ b/db/routines/account/triggers/mailAliasAccount_afterDelete.sql @@ -0,0 +1,12 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `account`.`mailAliasAccount_afterDelete` + AFTER DELETE ON `mailAliasAccount` + FOR EACH ROW +BEGIN + INSERT INTO userLog + SET `action` = 'delete', + `changedModel` = 'MailAliasAccount', + `changedModelId` = OLD.id, + `userFk` = account.myUser_getId(); +END$$ +DELIMITER ; \ No newline at end of file diff --git a/db/versions/11121-silverAralia/00-firstScript.sql b/db/versions/11121-silverAralia/00-firstScript.sql index e74ca2e95..20b0e8195 100644 --- a/db/versions/11121-silverAralia/00-firstScript.sql +++ b/db/versions/11121-silverAralia/00-firstScript.sql @@ -1,4 +1,4 @@ ALTER TABLE account.mailAliasAccount - ADD editorFk INT UNSIGNED NULL, + ADD editorFk INT(10) UNSIGNED DEFAULT NULL, ADD CONSTRAINT mailAliasAccount_editorFk FOREIGN KEY (editorFk) REFERENCES account.`user`(id); \ No newline at end of file From d9742afc9b4fdaaf143fe91c227527e684d3c931 Mon Sep 17 00:00:00 2001 From: sergiodt Date: Mon, 1 Jul 2024 17:45:45 +0200 Subject: [PATCH 39/61] feat roadmap refs #7195 --- modules/route/back/models/roadmapStop.json | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/modules/route/back/models/roadmapStop.json b/modules/route/back/models/roadmapStop.json index 74b02cd7a..93eae0113 100644 --- a/modules/route/back/models/roadmapStop.json +++ b/modules/route/back/models/roadmapStop.json @@ -3,7 +3,7 @@ "base": "VnModel", "options": { "mysql": { - "table": "roadmapStop" + "table": "roadmapStop" } }, "properties": { @@ -28,16 +28,16 @@ "type": "number" } }, - "relations": { - "roadmap": { + "relations": { + "roadmap": { "type": "belongsTo", "model": "Roadmap", "foreignKey": "roadmapFk" }, "address": { "type": "belongsTo", - "model": "Address", + "model": "RoadmapAddress", "foreignKey": "addressFk" } - } -} + } +} \ No newline at end of file From a0185dca0486a339ba41ab8822ff4e767e19be1b Mon Sep 17 00:00:00 2001 From: Javier Segarra Date: Mon, 1 Jul 2024 18:39:21 +0200 Subject: [PATCH 40/61] feat(salix): refs #7648 #7648 new supplier role --- .../11118-limeCymbidium/00-firstScript.sql | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/db/versions/11118-limeCymbidium/00-firstScript.sql b/db/versions/11118-limeCymbidium/00-firstScript.sql index 52ab2acbd..7f9a2432d 100644 --- a/db/versions/11118-limeCymbidium/00-firstScript.sql +++ b/db/versions/11118-limeCymbidium/00-firstScript.sql @@ -1,10 +1,15 @@ --- Place your SQL code here --- Auto-generated SQL script #202406281423 -INSERT INTO salix.ACL (model,property,accessType,permission,principalType,principalId) - VALUES ('Entry','filter','READ','ALLOW','ROLE','$authenticated'); --- Auto-generated SQL script #202406281452 -INSERT INTO salix.ACL (model,property,accessType,permission,principalType,principalId) +INSERT IGNORE INTO salix.ACL (`model`,`property`,`accessType`,`permission`,`principalType`,`principalId`) + VALUES ('Entry','filter','READ','ALLOW','ROLE','supplier'); + +INSERT IGNORE INTO salix.ACL (`model`,`property`,`accessType`,`permission`,`principalType`,`principalId`) VALUES ('Entry','getBuys','READ','ALLOW','ROLE','$authenticated'); -INSERT INTO salix.ACL (model,property,accessType,permission,principalType,principalId) + +INSERT IGNORE INTO salix.ACL (`model`,`property`,`accessType`,`permission`,`principalType`,`principalId`) VALUES ('Entry','buyLabel','READ','ALLOW','ROLE','$authenticated'); + +INSERT IGNORE INTO `account`.`role` (`name`,`description`,`hasLogin`,`created`,`modified`) + VALUES ('supplier','Proveedores',1,'2017-10-10 14:58:58.000','2017-10-10 14:59:20.000'); +SET @supplierFk =LAST_INSERT_ID(); +INSERT IGNORE INTO account.roleInherit (`role`,`inheritsFrom`) + VALUES (@supplierFk,2); From f27bdec75822835be3db77ff496f686d524a826d Mon Sep 17 00:00:00 2001 From: Javier Segarra Date: Mon, 1 Jul 2024 21:14:27 +0200 Subject: [PATCH 41/61] feat(salix): refs #7648 #7648 changes requested --- .../11118-limeCymbidium/00-firstScript.sql | 9 ++++-- loopback/common/methods/schema/model-info.js | 1 + modules/entry/back/methods/entry/filter.js | 4 +-- modules/entry/back/methods/entry/getBuys.js | 8 +++--- .../back/methods/supplier/isSupplier.js | 28 ------------------- modules/supplier/back/models/supplier.js | 1 - 6 files changed, 14 insertions(+), 37 deletions(-) delete mode 100644 modules/supplier/back/methods/supplier/isSupplier.js diff --git a/db/versions/11118-limeCymbidium/00-firstScript.sql b/db/versions/11118-limeCymbidium/00-firstScript.sql index 7f9a2432d..0ed1337a0 100644 --- a/db/versions/11118-limeCymbidium/00-firstScript.sql +++ b/db/versions/11118-limeCymbidium/00-firstScript.sql @@ -3,13 +3,18 @@ INSERT IGNORE INTO salix.ACL (`model`,`property`,`accessType`,`permission`,`prin VALUES ('Entry','filter','READ','ALLOW','ROLE','supplier'); INSERT IGNORE INTO salix.ACL (`model`,`property`,`accessType`,`permission`,`principalType`,`principalId`) - VALUES ('Entry','getBuys','READ','ALLOW','ROLE','$authenticated'); + VALUES ('Entry','getBuys','READ','ALLOW','ROLE','supplier'); INSERT IGNORE INTO salix.ACL (`model`,`property`,`accessType`,`permission`,`principalType`,`principalId`) - VALUES ('Entry','buyLabel','READ','ALLOW','ROLE','$authenticated'); + VALUES ('Entry','buyLabel','READ','ALLOW','ROLE','supplier'); INSERT IGNORE INTO `account`.`role` (`name`,`description`,`hasLogin`,`created`,`modified`) VALUES ('supplier','Proveedores',1,'2017-10-10 14:58:58.000','2017-10-10 14:59:20.000'); SET @supplierFk =LAST_INSERT_ID(); INSERT IGNORE INTO account.roleInherit (`role`,`inheritsFrom`) VALUES (@supplierFk,2); + +UPDATE salix.ACL + SET principalId='$authenticated' + WHERE id=264; + diff --git a/loopback/common/methods/schema/model-info.js b/loopback/common/methods/schema/model-info.js index 0648deb80..74d764475 100644 --- a/loopback/common/methods/schema/model-info.js +++ b/loopback/common/methods/schema/model-info.js @@ -92,6 +92,7 @@ module.exports = Self => { const locale = modelLocale && modelLocale.get(lang); json[modelName] = { + http: model.sharedClass.http.path, properties: model.definition.rawProperties, validations: jsonValidations, locale diff --git a/modules/entry/back/methods/entry/filter.js b/modules/entry/back/methods/entry/filter.js index 929df8bd9..2a127b496 100644 --- a/modules/entry/back/methods/entry/filter.js +++ b/modules/entry/back/methods/entry/filter.js @@ -112,7 +112,6 @@ module.exports = Self => { if (typeof options == 'object') Object.assign(myOptions, options); - const isSupplier = await Self.app.models.Supplier.isSupplier(ctx, options); const conn = Self.dataSource.connector; const where = buildFilter(ctx.args, (param, value) => { switch (param) { @@ -146,7 +145,8 @@ module.exports = Self => { } }); filter = mergeFilters(ctx.args.filter, {where}); - delete filter.order; + const userId = ctx.req.accessToken.userId; + const isSupplier = await Self.app.models.Supplier.findById(userId, options); if (isSupplier) { if (!filter.where) filter.where = {}; filter.where.supplierFk = ctx.req.accessToken.userId; diff --git a/modules/entry/back/methods/entry/getBuys.js b/modules/entry/back/methods/entry/getBuys.js index cfb065b83..e392ba3ce 100644 --- a/modules/entry/back/methods/entry/getBuys.js +++ b/modules/entry/back/methods/entry/getBuys.js @@ -31,16 +31,17 @@ module.exports = Self => { }); Self.getBuys = async(ctx, id, filter, options) => { + const userId = ctx.req.accessToken.userId; const models = Self.app.models; const myOptions = {}; if (typeof options == 'object') Object.assign(myOptions, options); - const isSupplier = await Self.app.models.Supplier.isSupplier(ctx, options); + const isSupplier = await Self.app.models.Supplier.findById(userId, options); if (isSupplier) { - const isEntryOwner = (await Self.findById(id)).supplierFk === ctx.req.accessToken.userId; + const isEntryOwner = (await Self.findById(id)).supplierFk === userId; - if (! isEntryOwner) throw new UserError('Access Denied'); + if (!isEntryOwner) throw new UserError('Access Denied'); } let defaultFilter = { where: {entryFk: id}, @@ -106,7 +107,6 @@ module.exports = Self => { } }] }; - delete filter.order; defaultFilter = mergeFilters(defaultFilter, filter); return models.Buy.find(defaultFilter, myOptions); diff --git a/modules/supplier/back/methods/supplier/isSupplier.js b/modules/supplier/back/methods/supplier/isSupplier.js deleted file mode 100644 index d13f304a8..000000000 --- a/modules/supplier/back/methods/supplier/isSupplier.js +++ /dev/null @@ -1,28 +0,0 @@ -const UserError = require('vn-loopback/util/user-error'); - -module.exports = Self => { - Self.remoteMethodCtx('isSupplier', { - description: 'Check is supplierFk exists as supplier', - accessType: 'READ', - returns: { - type: 'boolean', - root: true - }, - http: { - path: `/isSupplier`, - verb: 'GET' - } - }); - - Self.isSupplier = async(ctx, options) => { - const myOptions = {validate: false}; - - if (typeof options == 'object') - Object.assign(myOptions, options); - - const userId = ctx.req.accessToken.userId; - const exists = await Self.findById(userId); - - return !!exists; - }; -}; diff --git a/modules/supplier/back/models/supplier.js b/modules/supplier/back/models/supplier.js index 6094602b6..2d3ffef3e 100644 --- a/modules/supplier/back/models/supplier.js +++ b/modules/supplier/back/models/supplier.js @@ -12,7 +12,6 @@ module.exports = Self => { require('../methods/supplier/campaignMetricsEmail')(Self); require('../methods/supplier/newSupplier')(Self); require('../methods/supplier/getItemsPackaging')(Self); - require('../methods/supplier/isSupplier')(Self); Self.validatesPresenceOf('name', { message: 'The social name cannot be empty' From 08cf79b09bc68104a2547e95e1f4b165b8ac6ea8 Mon Sep 17 00:00:00 2001 From: sergiodt Date: Tue, 2 Jul 2024 08:39:42 +0200 Subject: [PATCH 42/61] feat roadmap refs #7195 --- .../back/methods/roadmapStop/getPalletMatchState.js | 9 ++++----- .../roadmapStop/specs/getPalletMatchState.spec.js | 4 ++-- 2 files changed, 6 insertions(+), 7 deletions(-) diff --git a/modules/route/back/methods/roadmapStop/getPalletMatchState.js b/modules/route/back/methods/roadmapStop/getPalletMatchState.js index efed64327..138d62411 100644 --- a/modules/route/back/methods/roadmapStop/getPalletMatchState.js +++ b/modules/route/back/methods/roadmapStop/getPalletMatchState.js @@ -1,6 +1,6 @@ module.exports = Self => { Self.remoteMethod('getPalletMatchState', { - description: 'Get pallet', + description: 'Get list of pallet from roadMapStop with true or false if state is matched', accessType: 'WRITE', accepts: [{ arg: 'roadMapStopFk', @@ -32,7 +32,7 @@ module.exports = Self => { const result = await Self.rawSql(` WITH tPallet AS( - SELECT ep.truckFk roadMapStop,ep.id pallet, e.id expedition, e.stateTypeFk + SELECT ep.id pallet, e.id expedition, e.stateTypeFk FROM vn.expeditionPallet ep JOIN vn.expeditionScan es ON es.palletFk = ep.id JOIN expedition e ON e.id = es.expeditionFk @@ -48,9 +48,8 @@ module.exports = Self => { WHERE code = ? GROUP BY expedition ) - SELECT t.roadMapStop, - t.pallet, - IF (tpe.totalPalletExpedition = tpec.totalPalletExpeditionCode, 'TRUE', 'FALSE') hasMatchStateCode + SELECT t.pallet, + tpe.totalPalletExpedition = tpec.totalPalletExpeditionCode hasMatchStateCode FROM tPallet t LEFT JOIN totalPalletExpedition tpe ON tpe.expedition = t.expedition LEFT JOIN totalPalletExpeditionCode tpec ON tpec.expedition = t.expedition diff --git a/modules/route/back/methods/roadmapStop/specs/getPalletMatchState.spec.js b/modules/route/back/methods/roadmapStop/specs/getPalletMatchState.spec.js index ac782561a..3e89bd528 100644 --- a/modules/route/back/methods/roadmapStop/specs/getPalletMatchState.spec.js +++ b/modules/route/back/methods/roadmapStop/specs/getPalletMatchState.spec.js @@ -2,11 +2,11 @@ const {models} = require('vn-loopback/server/server'); describe('roadMapStop getPalletMatchState()', () => { - fit('should return list of pallet with true or false if state is matched', async() => { + it('should return list of pallet with true or false if state is matched', async() => { const roadmapStopFk = 1; const state = 'ON DELIVERY'; const result = await models.RoadmapStop.getPalletMatchState(roadmapStopFk, state); - expect(result[0].hasMatchStateCode).toBe('TRUE'); + expect(result[0].hasMatchStateCode).toBe(1); }); }); From 89a394a10def74e4b9c11cd3986bf7b91b24aab2 Mon Sep 17 00:00:00 2001 From: Javier Segarra Date: Tue, 2 Jul 2024 09:52:18 +0200 Subject: [PATCH 43/61] test(salix): refs #7648 #7648 entry.filter --- modules/entry/back/methods/entry/filter.js | 2 +- .../back/methods/entry/specs/filter.spec.js | 82 +++++++++++++++---- 2 files changed, 65 insertions(+), 19 deletions(-) diff --git a/modules/entry/back/methods/entry/filter.js b/modules/entry/back/methods/entry/filter.js index 2a127b496..700d251a2 100644 --- a/modules/entry/back/methods/entry/filter.js +++ b/modules/entry/back/methods/entry/filter.js @@ -149,7 +149,7 @@ module.exports = Self => { const isSupplier = await Self.app.models.Supplier.findById(userId, options); if (isSupplier) { if (!filter.where) filter.where = {}; - filter.where.supplierFk = ctx.req.accessToken.userId; + filter.where[`e.supplierFk`] = ctx.req.accessToken.userId; } const stmts = []; let stmt; diff --git a/modules/entry/back/methods/entry/specs/filter.spec.js b/modules/entry/back/methods/entry/specs/filter.spec.js index e116d1c5f..76dc7b786 100644 --- a/modules/entry/back/methods/entry/specs/filter.spec.js +++ b/modules/entry/back/methods/entry/specs/filter.spec.js @@ -1,6 +1,6 @@ const models = require('vn-loopback/server/server').models; -describe('Entry filter()', () => { +fdescribe('Entry filter()', () => { it('should return the entry matching "search"', async() => { const tx = await models.Entry.beginTransaction({}); const options = {transaction: tx}; @@ -48,27 +48,73 @@ describe('Entry filter()', () => { } }); - it('should return the entry matching the supplier', async() => { - const tx = await models.Entry.beginTransaction({}); - const options = {transaction: tx}; + describe('should return the entry matching the supplier', () => { + it('when userId is supplier ', async() => { + const tx = await models.Entry.beginTransaction({}); + const options = {transaction: tx}; - try { - const ctx = { - args: { - supplierFk: 2 - }, - req: {accessToken: {userId: 9}} - }; + try { + const ctx = { + args: {}, + req: {accessToken: {userId: 2}} + }; - const result = await models.Entry.filter(ctx, options); + const result = await models.Entry.filter(ctx, options); - expect(result.length).toEqual(6); + expect(result.length).toEqual(6); - await tx.rollback(); - } catch (e) { - await tx.rollback(); - throw e; - } + await tx.rollback(); + } catch (e) { + await tx.rollback(); + throw e; + } + }); + + it('when userId is supplier fetching other supplier', async() => { + const tx = await models.Entry.beginTransaction({}); + const options = {transaction: tx}; + + try { + const ctx = { + args: { + supplierFk: 1 + }, + req: {accessToken: {userId: 2}} + }; + + const result = await models.Entry.filter(ctx, options); + + expect(result.length).toEqual(6); + + await tx.rollback(); + } catch (e) { + await tx.rollback(); + throw e; + } + }); + + it('when userId is not supplier', async() => { + const tx = await models.Entry.beginTransaction({}); + const options = {transaction: tx}; + + try { + const ctx = { + args: { + supplierFk: 2 + }, + req: {accessToken: {userId: 9}} + }; + + const result = await models.Entry.filter(ctx, options); + + expect(result.length).toEqual(6); + + await tx.rollback(); + } catch (e) { + await tx.rollback(); + throw e; + } + }); }); it('should return the entry matching the company', async() => { From 30520cbe4895357a1026e236a0d8caa90442e6bf Mon Sep 17 00:00:00 2001 From: Javier Segarra Date: Tue, 2 Jul 2024 10:06:26 +0200 Subject: [PATCH 44/61] test(salix): refs #7648 #7648 getBuys.filter --- .../back/methods/entry/specs/getBuys.spec.js | 93 ++++++++++++++----- 1 file changed, 72 insertions(+), 21 deletions(-) diff --git a/modules/entry/back/methods/entry/specs/getBuys.spec.js b/modules/entry/back/methods/entry/specs/getBuys.spec.js index 44b2ff5bc..801cd6f1a 100644 --- a/modules/entry/back/methods/entry/specs/getBuys.spec.js +++ b/modules/entry/back/methods/entry/specs/getBuys.spec.js @@ -1,31 +1,82 @@ +const UserError = require('vn-loopback/util/user-error'); const models = require('vn-loopback/server/server').models; -describe('entry getBuys()', () => { +fdescribe('entry getBuys()', () => { const entryId = 4; - it('should get the buys and items of an entry', async() => { - const tx = await models.Entry.beginTransaction({}); - const options = {transaction: tx}; + describe('should get the buys and items of an entry ', () => { + it('when is supplier and entry owner', async() => { + const tx = await models.Entry.beginTransaction({}); + const options = {transaction: tx}; - try { - const ctx = { - args: { - search: 1 - }, - req: {accessToken: {userId: 2}} - }; + try { + const ctx = { + args: { + search: 1 + }, + req: {accessToken: {userId: 2}} + }; - const result = await models.Entry.getBuys(ctx, entryId, options); + const result = await models.Entry.getBuys(ctx, entryId, options); - const length = result.length; - const anyResult = result[Math.floor(Math.random() * Math.floor(length))]; + const length = result.length; + const anyResult = result[Math.floor(Math.random() * Math.floor(length))]; - expect(result.length).toEqual(4); - expect(anyResult.item).toBeDefined(); + expect(result.length).toEqual(4); + expect(anyResult.item).toBeDefined(); - await tx.rollback(); - } catch (e) { - await tx.rollback(); - throw e; - } + await tx.rollback(); + } catch (e) { + await tx.rollback(); + throw e; + } + }); + + it('when is supplier but not entry owner', async() => { + const tx = await models.Entry.beginTransaction({}); + const options = {transaction: tx}; + const entryId = 1; + try { + const ctx = { + args: { + search: 1 + }, + req: {accessToken: {userId: 2}} + }; + + const result = await models.Entry.getBuys(ctx, entryId, options); + + expect(result).toBeUndefined(); + } catch (error) { + expect(error).toBeInstanceOf(UserError); + expect(error.message).toBe('Access Denied'); + } + }); + + it('when is not supplier', async() => { + const tx = await models.Entry.beginTransaction({}); + const options = {transaction: tx}; + + try { + const ctx = { + args: { + search: 1 + }, + req: {accessToken: {userId: 9}} + }; + + const result = await models.Entry.getBuys(ctx, entryId, options); + + const length = result.length; + const anyResult = result[Math.floor(Math.random() * Math.floor(length))]; + + expect(result.length).toEqual(4); + expect(anyResult.item).toBeDefined(); + + await tx.rollback(); + } catch (e) { + await tx.rollback(); + throw e; + } + }); }); }); From 08612fc70cccafdc802673e96032cc3787913842 Mon Sep 17 00:00:00 2001 From: Javier Segarra Date: Tue, 2 Jul 2024 10:07:23 +0200 Subject: [PATCH 45/61] perf(salix): refs #7648 #7648 fixtures and firstScript --- db/dump/fixtures.before.sql | 3 +++ db/versions/11118-limeCymbidium/00-firstScript.sql | 1 + 2 files changed, 4 insertions(+) diff --git a/db/dump/fixtures.before.sql b/db/dump/fixtures.before.sql index 27f84bdfb..b27bc8ef6 100644 --- a/db/dump/fixtures.before.sql +++ b/db/dump/fixtures.before.sql @@ -3913,3 +3913,6 @@ INSERT INTO dipole.expedition_PrintOut (expeditionFk, ticketFk, addressFk, stree truckName, clientFk, phone, province, agency, m3, workerCode, itemFk, quantity, longName, shelvingFk, comments) VALUES(1, 1, 0, ' ', ' ', ' ', ' ', 0, '2001-01-01 00:00:00', 1, 0, ' ', ' ', 0, NULL, '', NULL, 0.000, NULL, 10, NULL, NULL, 'NCC', NULL); +UPDATE account.`user` + SET `role`=131 + WHERE id=2; diff --git a/db/versions/11118-limeCymbidium/00-firstScript.sql b/db/versions/11118-limeCymbidium/00-firstScript.sql index 0ed1337a0..3921a8a13 100644 --- a/db/versions/11118-limeCymbidium/00-firstScript.sql +++ b/db/versions/11118-limeCymbidium/00-firstScript.sql @@ -18,3 +18,4 @@ UPDATE salix.ACL SET principalId='$authenticated' WHERE id=264; + From 3539b5a33e906cc182ae4468929a43790b76a53d Mon Sep 17 00:00:00 2001 From: Javier Segarra Date: Tue, 2 Jul 2024 10:08:51 +0200 Subject: [PATCH 46/61] test(salix): refs #7648 #7648 remove fdescribe --- modules/entry/back/methods/entry/specs/filter.spec.js | 2 +- modules/entry/back/methods/entry/specs/getBuys.spec.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/modules/entry/back/methods/entry/specs/filter.spec.js b/modules/entry/back/methods/entry/specs/filter.spec.js index 76dc7b786..9d954cdc4 100644 --- a/modules/entry/back/methods/entry/specs/filter.spec.js +++ b/modules/entry/back/methods/entry/specs/filter.spec.js @@ -1,6 +1,6 @@ const models = require('vn-loopback/server/server').models; -fdescribe('Entry filter()', () => { +describe('Entry filter()', () => { it('should return the entry matching "search"', async() => { const tx = await models.Entry.beginTransaction({}); const options = {transaction: tx}; diff --git a/modules/entry/back/methods/entry/specs/getBuys.spec.js b/modules/entry/back/methods/entry/specs/getBuys.spec.js index 801cd6f1a..cb7f7cb80 100644 --- a/modules/entry/back/methods/entry/specs/getBuys.spec.js +++ b/modules/entry/back/methods/entry/specs/getBuys.spec.js @@ -1,7 +1,7 @@ const UserError = require('vn-loopback/util/user-error'); const models = require('vn-loopback/server/server').models; -fdescribe('entry getBuys()', () => { +describe('entry getBuys()', () => { const entryId = 4; describe('should get the buys and items of an entry ', () => { it('when is supplier and entry owner', async() => { From 028278ebcfd923335abff83b89da0148386a3130 Mon Sep 17 00:00:00 2001 From: guillermo Date: Tue, 2 Jul 2024 11:52:25 +0200 Subject: [PATCH 47/61] refs #6626 Hotfix --- .../vn/procedures/invoiceInTax_afterUpsert.sql | 13 ------------- db/routines/vn/procedures/invoiceIn_booking.sql | 13 +++++++++++++ 2 files changed, 13 insertions(+), 13 deletions(-) diff --git a/db/routines/vn/procedures/invoiceInTax_afterUpsert.sql b/db/routines/vn/procedures/invoiceInTax_afterUpsert.sql index 60ec34696..962cc5224 100644 --- a/db/routines/vn/procedures/invoiceInTax_afterUpsert.sql +++ b/db/routines/vn/procedures/invoiceInTax_afterUpsert.sql @@ -8,7 +8,6 @@ BEGIN */ DECLARE vTaxRowLimit INT; DECLARE vLines INT; - DECLARE vHasDistinctTransactions INT; SELECT taxRowLimit INTO vTaxRowLimit FROM invoiceInConfig; @@ -20,17 +19,5 @@ BEGIN IF vLines >= vTaxRowLimit THEN CALL util.throw (CONCAT('The maximum number of lines is ', vTaxRowLimit)); END IF; - - SELECT COUNT(DISTINCT transactionTypeSageFk) INTO vHasDistinctTransactions - FROM invoiceIn ii - JOIN invoiceInTax iit ON iit.invoiceInFk = ii.id - JOIN invoiceInSerial iis ON iis.code = ii.serial - WHERE ii.id = vInvoiceInFk - AND iis.taxAreaFk = 'CEE' - AND transactionTypeSageFk; - - IF vHasDistinctTransactions > 1 THEN - CALL util.throw ('This invoice does not allow different types of transactions'); - END IF; END$$ DELIMITER ; diff --git a/db/routines/vn/procedures/invoiceIn_booking.sql b/db/routines/vn/procedures/invoiceIn_booking.sql index ef124bb46..cd838861a 100644 --- a/db/routines/vn/procedures/invoiceIn_booking.sql +++ b/db/routines/vn/procedures/invoiceIn_booking.sql @@ -13,6 +13,19 @@ BEGIN * @param vBookEntry Id de asiento, si es NULL se genera uno nuevo */ DECLARE vFiscalYear INT; + DECLARE vHasDistinctTransactions INT; + + SELECT COUNT(DISTINCT transactionTypeSageFk) INTO vHasDistinctTransactions + FROM invoiceIn ii + JOIN invoiceInTax iit ON iit.invoiceInFk = ii.id + JOIN invoiceInSerial iis ON iis.code = ii.serial + WHERE ii.id = vSelf + AND iis.taxAreaFk = 'CEE' + AND transactionTypeSageFk; + + IF vHasDistinctTransactions > 1 THEN + CALL util.throw ('This invoice does not allow different types of transactions'); + END IF; CREATE OR REPLACE TEMPORARY TABLE tInvoiceIn ENGINE = MEMORY From 7f213a7435550314bb71556a89c6f97062ef681e Mon Sep 17 00:00:00 2001 From: carlossa Date: Tue, 2 Jul 2024 12:02:44 +0200 Subject: [PATCH 48/61] refs #6952 fix producer --- print/templates/reports/delivery-note/delivery-note.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/print/templates/reports/delivery-note/delivery-note.html b/print/templates/reports/delivery-note/delivery-note.html index 540a80a3a..c1701e084 100644 --- a/print/templates/reports/delivery-note/delivery-note.html +++ b/print/templates/reports/delivery-note/delivery-note.html @@ -81,7 +81,7 @@ {{sale.tag5}} {{sale.value5}} {{sale.tag6}} {{sale.value6}} {{sale.tag7}} {{sale.value7}} - {{$t('producer')}} {{ sale.subName }} + {{$t('producer')}} {{ sale.subName }} From e1b6ba4276dff0aa80476c9dfc33e33dfcd5b8d1 Mon Sep 17 00:00:00 2001 From: sergiodt Date: Tue, 2 Jul 2024 12:03:21 +0200 Subject: [PATCH 49/61] feat roadmap refs #7195 --- .../back/methods/roadmapStop/getPalletMatchState.js | 10 +++++----- .../roadmapStop/specs/getPalletMatchState.spec.js | 4 ++-- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/modules/route/back/methods/roadmapStop/getPalletMatchState.js b/modules/route/back/methods/roadmapStop/getPalletMatchState.js index 138d62411..828dbb689 100644 --- a/modules/route/back/methods/roadmapStop/getPalletMatchState.js +++ b/modules/route/back/methods/roadmapStop/getPalletMatchState.js @@ -1,12 +1,12 @@ module.exports = Self => { Self.remoteMethod('getPalletMatchState', { - description: 'Get list of pallet from roadMapStop with true or false if state is matched', + description: 'Get list of pallet from truckFk with true or false if state is matched', accessType: 'WRITE', accepts: [{ - arg: 'roadMapStopFk', + arg: 'truckFk', type: 'number', required: true, - description: 'The roadmapFk id' + description: 'The truckFk id' }, { arg: 'state', @@ -24,7 +24,7 @@ module.exports = Self => { } }); - Self.getPalletMatchState = async(roadMapStopFk, state, options) => { + Self.getPalletMatchState = async(truckFk, state, options) => { const myOptions = {}; if (typeof options == 'object') @@ -54,7 +54,7 @@ module.exports = Self => { LEFT JOIN totalPalletExpedition tpe ON tpe.expedition = t.expedition LEFT JOIN totalPalletExpeditionCode tpec ON tpec.expedition = t.expedition GROUP BY t.pallet;`, - [roadMapStopFk, state], + [truckFk, state], myOptions); return result; diff --git a/modules/route/back/methods/roadmapStop/specs/getPalletMatchState.spec.js b/modules/route/back/methods/roadmapStop/specs/getPalletMatchState.spec.js index 3e89bd528..4a79b589e 100644 --- a/modules/route/back/methods/roadmapStop/specs/getPalletMatchState.spec.js +++ b/modules/route/back/methods/roadmapStop/specs/getPalletMatchState.spec.js @@ -3,9 +3,9 @@ const {models} = require('vn-loopback/server/server'); describe('roadMapStop getPalletMatchState()', () => { it('should return list of pallet with true or false if state is matched', async() => { - const roadmapStopFk = 1; + const truckFk = 1; const state = 'ON DELIVERY'; - const result = await models.RoadmapStop.getPalletMatchState(roadmapStopFk, state); + const result = await models.RoadmapStop.getPalletMatchState(truckFk, state); expect(result[0].hasMatchStateCode).toBe(1); }); From 9708e79e5518addc77a0e447c65744d96a48a149 Mon Sep 17 00:00:00 2001 From: alexm Date: Tue, 2 Jul 2024 12:41:51 +0200 Subject: [PATCH 50/61] build: increase version 2430 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 95d696fc3..ea126bce3 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "salix-back", - "version": "24.28.0", + "version": "24.30.0", "author": "Verdnatura Levante SL", "description": "Salix backend", "license": "GPL-3.0", From 0bb4439f85d07c6765d2873c0ca82f1b42a25358 Mon Sep 17 00:00:00 2001 From: guillermo Date: Tue, 2 Jul 2024 14:37:22 +0200 Subject: [PATCH 51/61] refs #7443 Deleted ekt barcode --- db/routines/edi/procedures/ekt_refresh.sql | 19 +++---------------- db/routines/edi/views/ektRecent.sql | 1 - db/routines/vn2008/views/buy_edi.sql | 1 - 3 files changed, 3 insertions(+), 18 deletions(-) diff --git a/db/routines/edi/procedures/ekt_refresh.sql b/db/routines/edi/procedures/ekt_refresh.sql index 0e9ed7d3c..8ba438c0a 100644 --- a/db/routines/edi/procedures/ekt_refresh.sql +++ b/db/routines/edi/procedures/ekt_refresh.sql @@ -7,7 +7,6 @@ BEGIN */ DECLARE vRewriteKop INT DEFAULT NULL; DECLARE vTruncatePutOrder INT DEFAULT NULL; - DECLARE vBarcode CHAR(15) DEFAULT NULL; DECLARE vKop INT; DECLARE vPutOrderFk BIGINT; @@ -16,17 +15,6 @@ BEGIN FROM ekt WHERE id = vSelf; - -- Generates the barcode - - SELECT CONCAT( - LPAD(IFNULL(auction,0), 3, 0), - LPAD(IFNULL(klo, 99), 2, 0), - LPAD(DAYOFYEAR(fec), 3, 0), - COALESCE(agj, RIGHT(batchNumber,7), id)) - INTO vBarcode - FROM ekt - WHERE id = vSelf; - -- Rewrites the kop parameter IF vKop IS NULL THEN @@ -46,10 +34,9 @@ BEGIN -- Refresh EKT - UPDATE ekt SET - barcode = vBarcode - ,kop = vKop - ,putOrderFk = vTruncatePutOrder + UPDATE ekt + SET kop = vKop, + putOrderFk = vTruncatePutOrder WHERE id = vSelf; END$$ DELIMITER ; diff --git a/db/routines/edi/views/ektRecent.sql b/db/routines/edi/views/ektRecent.sql index 3e41490ab..66ff7875e 100644 --- a/db/routines/edi/views/ektRecent.sql +++ b/db/routines/edi/views/ektRecent.sql @@ -2,7 +2,6 @@ CREATE OR REPLACE DEFINER=`root`@`localhost` SQL SECURITY DEFINER VIEW `edi`.`ektRecent` AS SELECT `e`.`id` AS `id`, - `e`.`barcode` AS `barcode`, `e`.`entryYear` AS `entryYear`, `e`.`batchNumber` AS `batchNumber`, `e`.`deliveryNumber` AS `deliveryNumber`, diff --git a/db/routines/vn2008/views/buy_edi.sql b/db/routines/vn2008/views/buy_edi.sql index 0d194c89e..d00196e95 100644 --- a/db/routines/vn2008/views/buy_edi.sql +++ b/db/routines/vn2008/views/buy_edi.sql @@ -2,7 +2,6 @@ CREATE OR REPLACE DEFINER=`root`@`localhost` SQL SECURITY DEFINER VIEW `vn2008`.`buy_edi` AS SELECT `t`.`id` AS `id`, - `t`.`barcode` AS `barcode`, `t`.`entryYear` AS `entry_year`, `t`.`deliveryNumber` AS `delivery_number`, `t`.`fec` AS `fec`, From 0d70cb892909348e98086e07d564ea3df8f5fa0c Mon Sep 17 00:00:00 2001 From: jgallego Date: Tue, 2 Jul 2024 17:39:46 +0200 Subject: [PATCH 52/61] fix: informatica no necesita este correo --- db/routines/vn/procedures/XDiario_check.sql | 13 ------------- 1 file changed, 13 deletions(-) diff --git a/db/routines/vn/procedures/XDiario_check.sql b/db/routines/vn/procedures/XDiario_check.sql index 0fb1c410d..ef969924b 100644 --- a/db/routines/vn/procedures/XDiario_check.sql +++ b/db/routines/vn/procedures/XDiario_check.sql @@ -6,19 +6,6 @@ BEGIN * identificando y notificando los asientos descuadrados * y ajustando los saldos en caso necesario. */ - INSERT INTO mail (receiver, subject, body) - SELECT 'cau@verdnatura.es', - 'Asientos descuadrados', - GROUP_CONCAT(CONCAT(' Asiento: ', ASIEN, ' - Importe:', recon) SEPARATOR ' | \n') - FROM ( - SELECT ASIEN, - SUM(IFNULL(ROUND(Eurodebe, 2), 0)) - SUM(IFNULL(ROUND(EUROHABER, 2), 0)) recon - FROM XDiario - WHERE NOT enlazado - GROUP BY ASIEN - HAVING ABS(SUM(IFNULL(ROUND(Eurodebe, 2), 0)) - SUM(IFNULL(ROUND(EUROHABER, 2), 0))) > 0.01 - ) sub - HAVING COUNT(*); UPDATE XDiario xd JOIN ( From cc004a864a58397e0e2701aa7f7bbac29ad02575 Mon Sep 17 00:00:00 2001 From: Javier Segarra Date: Tue, 2 Jul 2024 20:41:53 +0200 Subject: [PATCH 53/61] feat(salix): refs #7648 #7648 rename some travel fields --- modules/entry/back/methods/entry/filter.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/modules/entry/back/methods/entry/filter.js b/modules/entry/back/methods/entry/filter.js index 700d251a2..c25a7527e 100644 --- a/modules/entry/back/methods/entry/filter.js +++ b/modules/entry/back/methods/entry/filter.js @@ -178,10 +178,10 @@ module.exports = Self => { s.nickname AS supplierAlias, co.code AS companyCode, cu.code AS currencyCode, - t.shipped AS shipped, - t.landed AS landed, - t.warehouseInFk AS warehouseId, - w.name AS warehouseName + t.shipped, + t.landed, + t.warehouseInFk, + w.name AS warehouseInName FROM vn.entry e JOIN vn.supplier s ON s.id = e.supplierFk JOIN vn.travel t ON t.id = e.travelFk From adbbe4aef9c57513be79fb8e4804d9bf40a8f9fe Mon Sep 17 00:00:00 2001 From: Javier Segarra Date: Wed, 3 Jul 2024 01:46:01 +0200 Subject: [PATCH 54/61] fix(salix): refs #7648 #7648 solve big bug --- modules/entry/back/methods/entry/getBuys.js | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/modules/entry/back/methods/entry/getBuys.js b/modules/entry/back/methods/entry/getBuys.js index e392ba3ce..444e6cb14 100644 --- a/modules/entry/back/methods/entry/getBuys.js +++ b/modules/entry/back/methods/entry/getBuys.js @@ -1,4 +1,3 @@ -const ForbiddenError = require('vn-loopback/util/forbiddenError'); const UserError = require('vn-loopback/util/user-error'); const mergeFilters = require('vn-loopback/util/filter').mergeFilters; @@ -37,7 +36,7 @@ module.exports = Self => { if (typeof options == 'object') Object.assign(myOptions, options); - const isSupplier = await Self.app.models.Supplier.findById(userId, options); + const isSupplier = await Self.app.models.Supplier.findById(userId, myOptions); if (isSupplier) { const isEntryOwner = (await Self.findById(id)).supplierFk === userId; From 946d6f553af0be220e5b9d882397c6fda4252daf Mon Sep 17 00:00:00 2001 From: Javier Segarra Date: Wed, 3 Jul 2024 08:16:55 +0200 Subject: [PATCH 55/61] perf(salix): refs #7648 #7648 sql conventions --- modules/entry/back/methods/entry/filter.js | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/modules/entry/back/methods/entry/filter.js b/modules/entry/back/methods/entry/filter.js index c25a7527e..9bbce1c95 100644 --- a/modules/entry/back/methods/entry/filter.js +++ b/modules/entry/back/methods/entry/filter.js @@ -162,7 +162,7 @@ module.exports = Self => { e.invoiceNumber, e.isBooked, e.isExcludedFromAvailable, - e.evaNotes AS observation, + e.evaNotes observation, e.isConfirmed, e.isOrdered, e.isRaid, @@ -174,14 +174,14 @@ module.exports = Self => { e.gestDocFk, e.invoiceInFk, t.landed, - s.name AS supplierName, - s.nickname AS supplierAlias, - co.code AS companyCode, - cu.code AS currencyCode, + s.name supplierName, + s.nickname supplierAlias, + co.code companyCode, + cu.code currencyCode, t.shipped, t.landed, t.warehouseInFk, - w.name AS warehouseInName + w.name warehouseInName FROM vn.entry e JOIN vn.supplier s ON s.id = e.supplierFk JOIN vn.travel t ON t.id = e.travelFk From beff905e02bfb6b2d074eb122d0e01f8c9668ec8 Mon Sep 17 00:00:00 2001 From: Javier Segarra Date: Wed, 3 Jul 2024 08:54:58 +0200 Subject: [PATCH 56/61] perf(salix): refs #7648 #7648 remove change role for user 2 --- db/dump/fixtures.before.sql | 4 ---- 1 file changed, 4 deletions(-) diff --git a/db/dump/fixtures.before.sql b/db/dump/fixtures.before.sql index b27bc8ef6..359410564 100644 --- a/db/dump/fixtures.before.sql +++ b/db/dump/fixtures.before.sql @@ -3912,7 +3912,3 @@ VALUES(1, ''); INSERT INTO dipole.expedition_PrintOut (expeditionFk, ticketFk, addressFk, street, postalCode, city, shopName, isPrinted, created, printerFk, routeFk, parkingCode, truckName, clientFk, phone, province, agency, m3, workerCode, itemFk, quantity, longName, shelvingFk, comments) VALUES(1, 1, 0, ' ', ' ', ' ', ' ', 0, '2001-01-01 00:00:00', 1, 0, ' ', ' ', 0, NULL, '', NULL, 0.000, NULL, 10, NULL, NULL, 'NCC', NULL); - -UPDATE account.`user` - SET `role`=131 - WHERE id=2; From 1561e15d5ed1e567996319ad00bf47d7d7889417 Mon Sep 17 00:00:00 2001 From: sergiodt Date: Wed, 3 Jul 2024 09:21:58 +0200 Subject: [PATCH 57/61] feat roadmap refs #7195 --- back/models/warehouse.json | 107 ++++++++------ .../11081-wheatRaphis/00-firstScript.sql | 8 + .../roadmapStop/getPalletMatchState.js | 62 ++++++++ .../specs/getPalletMatchState.spec.js | 12 ++ modules/route/back/models/roadmap.json | 138 ++++++++++-------- modules/route/back/models/roadmapStop.js | 3 + modules/route/back/models/roadmapStop.json | 86 +++++------ 7 files changed, 262 insertions(+), 154 deletions(-) create mode 100644 db/versions/11081-wheatRaphis/00-firstScript.sql create mode 100644 modules/route/back/methods/roadmapStop/getPalletMatchState.js create mode 100644 modules/route/back/methods/roadmapStop/specs/getPalletMatchState.spec.js create mode 100644 modules/route/back/models/roadmapStop.js diff --git a/back/models/warehouse.json b/back/models/warehouse.json index f12b5e86e..756a538c0 100644 --- a/back/models/warehouse.json +++ b/back/models/warehouse.json @@ -1,48 +1,59 @@ -{ - "name": "Warehouse", - "description": "Warehouses from where orders are sent", - "base": "VnModel", - "options": { - "mysql": { - "table": "warehouse" - } - }, - "properties": { - "id": { - "id": true, - "type": "number", - "forceId": false - }, - "name": { - "type": "string" - }, - "code": { - "type": "string" - }, - "isInventory": { - "type": "number" - }, - "isManaged":{ - "type": "boolean" - }, - "countryFk": { - "type": "number" - } - }, - "relations": { - "country": { - "type": "belongsTo", - "model": "Country", - "foreignKey": "countryFk" - } - }, - "acls": [ - { - "accessType": "READ", - "principalType": "ROLE", - "principalId": "$everyone", - "permission": "ALLOW" - } - ], - "scope" : {"where": {"isForTicket": {"neq": 0}}} -} +{ + "name": "Warehouse", + "description": "Warehouses from where orders are sent", + "base": "VnModel", + "options": { + "mysql": { + "table": "warehouse" + } + }, + "properties": { + "id": { + "id": true, + "type": "number", + "forceId": false + }, + "name": { + "type": "string" + }, + "code": { + "type": "string" + }, + "isInventory": { + "type": "number" + }, + "isManaged": { + "type": "boolean" + }, + "countryFk": { + "type": "number" + } + }, + "relations": { + "country": { + "type": "belongsTo", + "model": "Country", + "foreignKey": "countryFk" + }, + "address": { + "type": "belongsTo", + "model": "Address", + "foreignKey": "addressFk" + } + }, + "acls": [ + { + "accessType": "READ", + "principalType": "ROLE", + "principalId": "$everyone", + "permission": "ALLOW" + } + ], + "scope": { + "where": { + "isForTicket": { + "neq": 0 + } + } + } +} \ No newline at end of file diff --git a/db/versions/11081-wheatRaphis/00-firstScript.sql b/db/versions/11081-wheatRaphis/00-firstScript.sql new file mode 100644 index 000000000..2e4424c5a --- /dev/null +++ b/db/versions/11081-wheatRaphis/00-firstScript.sql @@ -0,0 +1,8 @@ +-- Place your SQL code here + +USE vn; + +ALTER TABLE vn.roadmap ADD kmStart mediumint(9) DEFAULT NULL NULL; +ALTER TABLE vn.roadmap ADD kmEnd mediumint(9) DEFAULT NULL NULL; +ALTER TABLE vn.roadmap ADD started DATETIME NULL; +ALTER TABLE vn.roadmap ADD finished DATETIME NULL; diff --git a/modules/route/back/methods/roadmapStop/getPalletMatchState.js b/modules/route/back/methods/roadmapStop/getPalletMatchState.js new file mode 100644 index 000000000..234c254c4 --- /dev/null +++ b/modules/route/back/methods/roadmapStop/getPalletMatchState.js @@ -0,0 +1,62 @@ +module.exports = Self => { + Self.remoteMethod('getPalletMatchState', { + description: 'Get list of pallet from truckFk with true or false if state is matched', + accessType: 'WRITE', + accepts: [{ + arg: 'truckFk', + type: 'number', + required: true, + description: 'The truckFk id' + }, + { + arg: 'state', + type: 'string', + required: true, + description: 'State code' + }], + returns: { + type: 'object', + root: true + }, + http: { + path: `/getPalletMatchState`, + verb: 'GET' + } + }); + + Self.getPalletMatchState = async(truckFk, state, options) => { + const myOptions = {}; + + if (typeof options == 'object') + Object.assign(myOptions, options); + + const result = await Self.rawSql(` + WITH tPallet AS( + SELECT ep.id pallet, e.id expedition, e.stateTypeFk + FROM vn.expeditionPallet ep + JOIN vn.expeditionScan es ON es.palletFk = ep.id + JOIN expedition e ON e.id = es.expeditionFk + WHERE ep.truckFk = ? + ),totalPalletExpedition AS( + SELECT t.*, COUNT(expedition) totalPalletExpedition + FROM tPallet t + GROUP BY expedition + ),totalPalletExpeditionCode AS( + SELECT t.*, COUNT(expedition) totalPalletExpeditionCode + FROM tPallet t + JOIN vn.expeditionStateType est ON est.id = t.stateTypeFk + WHERE code = ? + GROUP BY expedition + ) + SELECT t.pallet, + tpe.totalPalletExpedition = tpec.totalPalletExpeditionCode hasMatchStateCode + FROM tPallet t + LEFT JOIN totalPalletExpedition tpe ON tpe.expedition = t.expedition + LEFT JOIN totalPalletExpeditionCode tpec ON tpec.expedition = t.expedition + GROUP BY t.pallet;`, + [truckFk, state], + myOptions); + + return result; + }; +}; diff --git a/modules/route/back/methods/roadmapStop/specs/getPalletMatchState.spec.js b/modules/route/back/methods/roadmapStop/specs/getPalletMatchState.spec.js new file mode 100644 index 000000000..24f742c76 --- /dev/null +++ b/modules/route/back/methods/roadmapStop/specs/getPalletMatchState.spec.js @@ -0,0 +1,12 @@ + +const {models} = require('vn-loopback/server/server'); + +describe('roadMapStop getPalletMatchState()', () => { + it('should return list of pallet with true or false if state is matched', async() => { + const truckFk = 1; + const state = 'ON DELIVERY'; + const result = await models.RoadmapStop.getPalletMatchState(truckFk, state); + + expect(result[0].hasMatchStateCode).toBe(1); + }); +}); diff --git a/modules/route/back/models/roadmap.json b/modules/route/back/models/roadmap.json index 01572d718..dcac035ce 100644 --- a/modules/route/back/models/roadmap.json +++ b/modules/route/back/models/roadmap.json @@ -1,63 +1,75 @@ -{ - "name": "Roadmap", - "base": "VnModel", - "options": { - "mysql": { - "table": "roadmap" - } - }, - "properties": { - "id": { - "type": "number", - "id": true, - "description": "Identifier" - }, - "name": { - "type": "string" - }, - "tractorPlate": { - "type": "string" - }, - "trailerPlate": { - "type": "string" - }, - "phone": { - "type": "string" - }, - "supplierFk": { - "type": "number" - }, - "etd": { - "type": "date" - }, - "observations": { - "type": "string" - }, - "userFk": { - "type": "number" - }, - "price": { - "type": "number" - }, - "driverName": { - "type": "string" - } - }, - "relations": { - "worker": { - "type": "belongsTo", - "model": "Worker", - "foreignKey": "id" - }, - "supplier": { - "type": "belongsTo", - "model": "Supplier", - "foreignKey": "supplierFk" - }, - "roadmapStop": { - "type": "hasMany", - "model": "RoadmapStop", - "foreignKey": "roadmapFk" - } - } -} +{ + "name": "Roadmap", + "base": "VnModel", + "options": { + "mysql": { + "table": "roadmap" + } + }, + "properties": { + "id": { + "type": "number", + "id": true, + "description": "Identifier" + }, + "name": { + "type": "string" + }, + "tractorPlate": { + "type": "string" + }, + "trailerPlate": { + "type": "string" + }, + "phone": { + "type": "string" + }, + "supplierFk": { + "type": "number" + }, + "etd": { + "type": "date" + }, + "observations": { + "type": "string" + }, + "userFk": { + "type": "number" + }, + "price": { + "type": "number" + }, + "driverName": { + "type": "string" + }, + "kmStart": { + "type": "number" + }, + "kmEnd": { + "type": "number" + }, + "started": { + "type": "date" + }, + "finished": { + "type": "date" + } + }, + "relations": { + "worker": { + "type": "belongsTo", + "model": "Worker", + "foreignKey": "id" + }, + "supplier": { + "type": "belongsTo", + "model": "Supplier", + "foreignKey": "supplierFk" + }, + "roadmapStop": { + "type": "hasMany", + "model": "RoadmapStop", + "foreignKey": "roadmapFk" + } + } +} \ No newline at end of file diff --git a/modules/route/back/models/roadmapStop.js b/modules/route/back/models/roadmapStop.js new file mode 100644 index 000000000..1ce3f409e --- /dev/null +++ b/modules/route/back/models/roadmapStop.js @@ -0,0 +1,3 @@ +module.exports = Self => { + require('../methods/roadmapStop/getPalletMatchState')(Self); +}; diff --git a/modules/route/back/models/roadmapStop.json b/modules/route/back/models/roadmapStop.json index 74b02cd7a..edd615aae 100644 --- a/modules/route/back/models/roadmapStop.json +++ b/modules/route/back/models/roadmapStop.json @@ -1,43 +1,43 @@ -{ - "name": "RoadmapStop", - "base": "VnModel", - "options": { - "mysql": { - "table": "roadmapStop" - } - }, - "properties": { - "id": { - "type": "number", - "id": true, - "description": "Identifier" - }, - "roadmapFk": { - "type": "number" - }, - "addressFk": { - "type": "number" - }, - "eta": { - "type": "date" - }, - "description": { - "type": "string" - }, - "userFk": { - "type": "number" - } - }, - "relations": { - "roadmap": { - "type": "belongsTo", - "model": "Roadmap", - "foreignKey": "roadmapFk" - }, - "address": { - "type": "belongsTo", - "model": "Address", - "foreignKey": "addressFk" - } - } -} +{ + "name": "RoadmapStop", + "base": "VnModel", + "options": { + "mysql": { + "table": "roadmapStop" + } + }, + "properties": { + "id": { + "type": "number", + "id": true, + "description": "Identifier" + }, + "roadmapFk": { + "type": "number" + }, + "addressFk": { + "type": "number" + }, + "eta": { + "type": "date" + }, + "description": { + "type": "string" + }, + "userFk": { + "type": "number" + } + }, + "relations": { + "roadmap": { + "type": "belongsTo", + "model": "Roadmap", + "foreignKey": "roadmapFk" + }, + "address": { + "type": "belongsTo", + "model": "RoadmapAddress", + "foreignKey": "addressFk" + } + } +} \ No newline at end of file From 77d86c9fd979fe92aaa4b416c73c07a25f392f3d Mon Sep 17 00:00:00 2001 From: guillermo Date: Wed, 3 Jul 2024 09:55:14 +0200 Subject: [PATCH 58/61] feat: refs #7664 Added created in calendar table --- db/versions/11128-turquoiseCymbidium/00-firstScript.sql | 1 + 1 file changed, 1 insertion(+) create mode 100644 db/versions/11128-turquoiseCymbidium/00-firstScript.sql diff --git a/db/versions/11128-turquoiseCymbidium/00-firstScript.sql b/db/versions/11128-turquoiseCymbidium/00-firstScript.sql new file mode 100644 index 000000000..4f6cafcf8 --- /dev/null +++ b/db/versions/11128-turquoiseCymbidium/00-firstScript.sql @@ -0,0 +1 @@ +ALTER TABLE vn.calendar ADD created timestamp DEFAULT current_timestamp() NOT NULL AFTER dated; From aaca2d12c5e2eda72d92a0fc109806b6ae4e3336 Mon Sep 17 00:00:00 2001 From: guillermo Date: Wed, 3 Jul 2024 10:20:20 +0200 Subject: [PATCH 59/61] refactor: refs #7504 Rename id greuge --- db/versions/11129-limeHydrangea/00-firstScript.sql | 1 + 1 file changed, 1 insertion(+) create mode 100644 db/versions/11129-limeHydrangea/00-firstScript.sql diff --git a/db/versions/11129-limeHydrangea/00-firstScript.sql b/db/versions/11129-limeHydrangea/00-firstScript.sql new file mode 100644 index 000000000..eb2320ee1 --- /dev/null +++ b/db/versions/11129-limeHydrangea/00-firstScript.sql @@ -0,0 +1 @@ +ALTER TABLE vn.greuge CHANGE Id id int(10) unsigned auto_increment NOT NULL; From fafebb4339c76ea80d4d29ccc34165a66e244db6 Mon Sep 17 00:00:00 2001 From: carlossa Date: Wed, 3 Jul 2024 12:13:40 +0200 Subject: [PATCH 60/61] refs #6897 fix filter --- modules/entry/back/methods/entry/filter.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/entry/back/methods/entry/filter.js b/modules/entry/back/methods/entry/filter.js index df5fef1bc..69bcb46da 100644 --- a/modules/entry/back/methods/entry/filter.js +++ b/modules/entry/back/methods/entry/filter.js @@ -180,7 +180,7 @@ module.exports = Self => { cu.code currencyCode, t.shipped, t.landed, - t.ref AS travelRef + t.ref AS travelRef, t.warehouseInFk, w.name warehouseInName FROM vn.entry e From 900fa2de5ed71fb921517578787e930a35e889c7 Mon Sep 17 00:00:00 2001 From: jorgep Date: Wed, 3 Jul 2024 13:03:19 +0200 Subject: [PATCH 61/61] fix: refs #7648 add myOpts --- modules/entry/back/methods/entry/filter.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/entry/back/methods/entry/filter.js b/modules/entry/back/methods/entry/filter.js index 69bcb46da..5989494a4 100644 --- a/modules/entry/back/methods/entry/filter.js +++ b/modules/entry/back/methods/entry/filter.js @@ -146,7 +146,7 @@ module.exports = Self => { }); filter = mergeFilters(ctx.args.filter, {where}); const userId = ctx.req.accessToken.userId; - const isSupplier = await Self.app.models.Supplier.findById(userId, options); + const isSupplier = await Self.app.models.Supplier.findById(userId, myOptions); if (isSupplier) { if (!filter.where) filter.where = {}; filter.where[`e.supplierFk`] = ctx.req.accessToken.userId;