From ac053814e69f13669cc3ba9ab5ea135eba4a4b2c Mon Sep 17 00:00:00 2001 From: Javier Segarra Date: Wed, 29 Jan 2025 12:26:42 +0100 Subject: [PATCH] test: refs #6321 fixing test --- db/dump/fixtures.before.sql | 5 +++++ .../back/methods/sales-monitor/salesFilter.js | 2 +- .../ticket/specs/itemLackDetail.spec.js | 21 ++++++++----------- .../back/methods/ticket/specs/split.spec.js | 12 +++++------ modules/ticket/back/methods/ticket/split.js | 2 +- .../back/methods/ticket/transferSales.js | 9 ++------ 6 files changed, 24 insertions(+), 27 deletions(-) diff --git a/db/dump/fixtures.before.sql b/db/dump/fixtures.before.sql index 2a655ba7e..fd15f570d 100644 --- a/db/dump/fixtures.before.sql +++ b/db/dump/fixtures.before.sql @@ -321,6 +321,11 @@ UPDATE `vn`.`agencyMode` SET `web` = 1, `reportMail` = 'no-reply@gothamcity.com' UPDATE `vn`.`agencyMode` SET `code` = 'refund' WHERE `id` = 23; +INSERT INTO `vn`.`agencyIncoming`(`agencyModeFk`) + VALUES + (1), + (2); + INSERT INTO `vn`.`payMethod`(`id`,`code`, `name`, `graceDays`, `outstandingDebt`, `isIbanRequiredForClients`, `isIbanRequiredForSuppliers`, `hasVerified`) VALUES (1, NULL, 'PayMethod one', 0, 001, 0, 0, 0), diff --git a/modules/monitor/back/methods/sales-monitor/salesFilter.js b/modules/monitor/back/methods/sales-monitor/salesFilter.js index e98223d5a..4947edeaf 100644 --- a/modules/monitor/back/methods/sales-monitor/salesFilter.js +++ b/modules/monitor/back/methods/sales-monitor/salesFilter.js @@ -402,6 +402,6 @@ module.exports = Self => { const sql = ParameterizedSQL.join(stmts, ';'); const result = await conn.executeStmt(sql, myOptions); - return Array(19).fill().flatMap(() => result[ticketsIndex]); + return result[ticketsIndex]; }; }; diff --git a/modules/ticket/back/methods/ticket/specs/itemLackDetail.spec.js b/modules/ticket/back/methods/ticket/specs/itemLackDetail.spec.js index be8082b32..4e7b68bdc 100644 --- a/modules/ticket/back/methods/ticket/specs/itemLackDetail.spec.js +++ b/modules/ticket/back/methods/ticket/specs/itemLackDetail.spec.js @@ -6,11 +6,10 @@ describe('Item Lack Detail', () => { try { const options = {transaction: tx}; - const id = null; + const itemFk = null; - const filter = {where: {id: 0}}; - const warehouseFk = 60; - const result = await models.Ticket.itemLackDetail(id, warehouseFk, filter, options); + const filter = {where: {warehouseFk: 60}}; + const result = await models.Ticket.itemLackDetail(itemFk, filter, options); expect(result.length).toEqual(0); await tx.rollback(); @@ -25,10 +24,9 @@ describe('Item Lack Detail', () => { try { const options = {transaction: tx}; - const id = 1167; - const filter = {where: {id: 0}}; - const warehouseFk = 60; - const result = await models.Ticket.itemLackDetail(id, warehouseFk, filter, options); + const itemFk = 1167; + const filter = {where: {warehouseFk: 60}}; + const result = await models.Ticket.itemLackDetail(itemFk, filter, options); expect(result.length).toEqual(0); await tx.rollback(); @@ -43,10 +41,9 @@ describe('Item Lack Detail', () => { try { const options = {transaction: tx}; - const id = 0; - const filter = {where: {id: 0}}; - const warehouseFk = 60; - const result = await models.Ticket.itemLackDetail(id, warehouseFk, filter, options); + const itemFk = 0; + const filter = {where: {warehouseFk: 60}}; + const result = await models.Ticket.itemLackDetail(itemFk, filter, options); expect(result.length).toEqual(0); await tx.rollback(); diff --git a/modules/ticket/back/methods/ticket/specs/split.spec.js b/modules/ticket/back/methods/ticket/specs/split.spec.js index 8447b8a01..a74ff83db 100644 --- a/modules/ticket/back/methods/ticket/specs/split.spec.js +++ b/modules/ticket/back/methods/ticket/specs/split.spec.js @@ -1,10 +1,10 @@ const models = require('vn-loopback/server/server').models; -fdescribe('Split', () => { +describe('Split', () => { beforeAll(async() => { ctx = { req: { - accessToken: {}, + accessToken: {userId: 9}, headers: {origin: 'http://localhost'}, } }; @@ -21,7 +21,7 @@ fdescribe('Split', () => { const result = await models.Ticket.split(ctx, data, options); expect(result.length).toEqual(1); - expect(result[0].ticket).toEqual(7); + expect(result[0].ticket).toEqual(data[0].ticketFk); expect(result[0].status).toEqual('noSplit'); await tx.rollback(); @@ -42,7 +42,7 @@ fdescribe('Split', () => { const result = await models.Ticket.split(ctx, data, options); expect(result.length).toEqual(1); - expect(result[0].ticket).toEqual(8); + expect(result[0].ticket).toEqual(data[0].ticketFk); expect(result[0].status).toEqual('error'); expect(result[0].message).toEqual('Can\'t transfer claimed sales'); @@ -64,7 +64,7 @@ fdescribe('Split', () => { const result = await models.Ticket.split(ctx, data, options); expect(result.length).toEqual(1); - expect(result[0].ticket).toEqual(16); + expect(result[0].ticket).toEqual(data[0].ticketFk); expect(result[0].status).toEqual('error'); expect(result[0].message).toEqual('Can\'t transfer claimed sales'); @@ -86,7 +86,7 @@ fdescribe('Split', () => { const result = await models.Ticket.split(ctx, data, options); expect(result.length).toEqual(1); - expect(result[0].ticket).toEqual(32); + expect(result[0].ticket).toEqual(data[0].ticketFk); expect(result[0].status).toEqual('split'); await tx.rollback(); diff --git a/modules/ticket/back/methods/ticket/split.js b/modules/ticket/back/methods/ticket/split.js index 83a4e8b0c..41cc221d2 100644 --- a/modules/ticket/back/methods/ticket/split.js +++ b/modules/ticket/back/methods/ticket/split.js @@ -68,7 +68,7 @@ module.exports = Self => { await Self.rawSql(`CALL vn.ticket_setState(?, ?)`, [tid, 'FIXING'], myOptions); results.push({ticket: tid, newTicket: vNewTicket, status: 'split'}); - await tx.commit(); + if (tx) await tx.commit(); } catch ({message}) { results.push({ticket: tid, status: 'error', message}); } diff --git a/modules/ticket/back/methods/ticket/transferSales.js b/modules/ticket/back/methods/ticket/transferSales.js index 04a9e12f1..9c616527d 100644 --- a/modules/ticket/back/methods/ticket/transferSales.js +++ b/modules/ticket/back/methods/ticket/transferSales.js @@ -17,12 +17,6 @@ module.exports = Self => { description: 'Destination ticket id', required: false }, - { - arg: 'newDate', - type: 'date', - description: 'Custom new date', - required: false - }, { arg: 'sales', type: ['object'], @@ -39,7 +33,8 @@ module.exports = Self => { } }); - Self.transferSales = async(ctx, id, ticketId, sales, newDate, options) => { + Self.transferSales = async(ctx, id, ticketId, sales, + options) => { const userId = ctx.req.accessToken.userId; const models = Self.app.models; const myOptions = {userId};