From dcf6232c1403c2621e8a854bd15a5ab4c0e12392 Mon Sep 17 00:00:00 2001 From: jorgep Date: Tue, 23 Jan 2024 08:39:30 +0100 Subject: [PATCH] feat: refs #6276 test sale_getFromSectorCollection --- db/dump/fixtures.sql | 9 +++--- loopback/locale/es.json | 3 +- .../methods/sale-tracking/specs/mark.spec.js | 2 +- .../methods/sale/getFromSectorCollection.js | 28 ++----------------- .../specs/getFromSectorCollection.spec.js | 23 +++++++++++++++ 5 files changed, 32 insertions(+), 33 deletions(-) create mode 100644 modules/ticket/back/methods/sale/specs/getFromSectorCollection.spec.js diff --git a/db/dump/fixtures.sql b/db/dump/fixtures.sql index 04846435f..e536e694d 100644 --- a/db/dump/fixtures.sql +++ b/db/dump/fixtures.sql @@ -3707,9 +3707,8 @@ INSERT INTO `vn`.`machine` (`plate`, `maker`, `model`, `warehouseFk`, `departmen ('RE-003', 'IRON', 'JPH-24', 60, 23, 'ELECTRIC TOW', 'Drag cars', 2020, 103, 442); -INSERT INTO vn.machineWorker(workerFk,machineFk,inTimed) - VALUES (104,1,'2001-01-01 10:00:00.00.000'); +INSERT INTO vn.machineWorker(workerFk,machineFk,inTimed) VALUES (104,1,'2001-01-01 10:00:00.00.000'); -UPDATE vn.buy - SET itemOriginalFk = 1 - WHERE id = 1; \ No newline at end of file +UPDATE vn.buy SET itemOriginalFk = 1 WHERE id = 1; + +UPDATE vn.saleTracking SET stateFk = 26 WHERE id = 5; \ No newline at end of file diff --git a/loopback/locale/es.json b/loopback/locale/es.json index 25fbbda70..91374a34e 100644 --- a/loopback/locale/es.json +++ b/loopback/locale/es.json @@ -349,5 +349,6 @@ "Este estado no existe": "Este estado no existe", "The line could not be marked": "No se ha podido marcar la línea", "No se ha podido marcar la línea": "No se ha podido marcar la línea", - "The sale can not be tracked": "La línea no puede ser rastreada" + "The sale can not be tracked": "La línea no puede ser rastreada", + "La línea no puede ser rastreada": "La línea no puede ser rastreada" } \ No newline at end of file diff --git a/modules/ticket/back/methods/sale-tracking/specs/mark.spec.js b/modules/ticket/back/methods/sale-tracking/specs/mark.spec.js index 353a39c49..d981aeea5 100644 --- a/modules/ticket/back/methods/sale-tracking/specs/mark.spec.js +++ b/modules/ticket/back/methods/sale-tracking/specs/mark.spec.js @@ -1,5 +1,5 @@ const {models} = require('vn-loopback/server/server'); -fdescribe('saleTracking mark()', () => { +describe('saleTracking mark()', () => { const saleFk = 1; const originalQuantity = 10; const code = 'PREPARED'; diff --git a/modules/ticket/back/methods/sale/getFromSectorCollection.js b/modules/ticket/back/methods/sale/getFromSectorCollection.js index a56966887..c8925c3a9 100644 --- a/modules/ticket/back/methods/sale/getFromSectorCollection.js +++ b/modules/ticket/back/methods/sale/getFromSectorCollection.js @@ -25,36 +25,12 @@ module.exports = Self => { }); Self.getFromSectorCollection = async(ctx, sectorCollectionFk, sectorFk, options) => { - const myOptions = {}; const userId = ctx.req.accessToken.userId; + const myOptions = {userId}; if (typeof options == 'object') Object.assign(myOptions, options); - const sales = await Self.rawSql('CALL sectorCollection_getSale(?)', [sectorCollectionFk], myOptions); - - /* const sales = await Self.rawSql( - `SELECT s.ticketFk, - s.itemFk, - i.longName, - itemPackingTypeFk, - subName, - s.quantity, - w.code workerCode, - sgd.saleFk, - iss.quantity pickedQuantity, - c.salesPersonFk - FROM vn.sale s - JOIN item i ON i.id = s.itemFk - JOIN saleGroupDetail sgd ON sgd.saleFk = s.id - JOIN sectorCollectionSaleGroup scsg ON scsg.saleGroupFk = sgd.saleGroupFk - JOIN saleTracking st ON st.saleFk = s.id - JOIN state stt ON stt.id = st.stateFk AND stt.code = 'PREVIOUS_PREPARATION' - JOIN worker w ON w.id = st.workerFk - JOIN ticket t ON t.id= s.ticketFk - JOIN client c ON c.id=t.clientFk - LEFT JOIN itemShelvingSaleSum iss ON iss.saleFk = s.id - WHERE scsg.sectorCollectionFk = ? - AND st.workerFk = ?;`, [sectorCollectionFk, userId]); */ + const [sales] = await Self.rawSql('CALL sectorCollection_getSale(?)', [sectorCollectionFk], myOptions); const itemShelvings = []; for (let sale of sales) { diff --git a/modules/ticket/back/methods/sale/specs/getFromSectorCollection.spec.js b/modules/ticket/back/methods/sale/specs/getFromSectorCollection.spec.js new file mode 100644 index 000000000..1501426e4 --- /dev/null +++ b/modules/ticket/back/methods/sale/specs/getFromSectorCollection.spec.js @@ -0,0 +1,23 @@ +const {models} = require('vn-loopback/server/server'); + +describe('sale getFromSectorCollection()', () => { + const sectorCollectionFk = 1; + const sectorFk = 1; + + beforeAll(async() => { + ctx = { + req: { + headers: {origin: 'http://localhost'}, + accessToken: {userId: 40} + } + }; + }); + + it('should find an item and a shelving', async() => { + const options = {}; + const itemShelvings = await models.Sale.getFromSectorCollection(ctx, sectorCollectionFk, sectorFk, options); + + expect(itemShelvings.length).toEqual(1); + expect(itemShelvings[0].carros.length).toEqual(1); + }); +});