From d62c55dc9feb0b76dea34d5fe5d5c840630816cf Mon Sep 17 00:00:00 2001 From: Javier Segarra Date: Mon, 1 Apr 2024 13:11:58 +0200 Subject: [PATCH] refs #6321 test: negativeOrigin --- .../back/methods/ticket/itemLackOrigin.js | 2 +- .../ticket/specs/itemLackoOrigin.spec.js | 19 ------- .../ticket/specs/negativeOrigin.spec.js | 51 +++++++++++++++++++ 3 files changed, 52 insertions(+), 20 deletions(-) delete mode 100644 modules/ticket/back/methods/ticket/specs/itemLackoOrigin.spec.js create mode 100644 modules/ticket/back/methods/ticket/specs/negativeOrigin.spec.js diff --git a/modules/ticket/back/methods/ticket/itemLackOrigin.js b/modules/ticket/back/methods/ticket/itemLackOrigin.js index ca485b987..73673c17d 100644 --- a/modules/ticket/back/methods/ticket/itemLackOrigin.js +++ b/modules/ticket/back/methods/ticket/itemLackOrigin.js @@ -31,7 +31,7 @@ module.exports = Self => { const conn = Self.dataSource.connector; const stmts = data.map(({itemFk, negativeType, lack}) => `INSERT INTO vn.negativeOrigin (itemFk, type, quantity) - VALUES (${itemFk}, '${negativeType}', ${lack}) + VALUES (${itemFk}, "${negativeType}", ${lack}) ON DUPLICATE KEY UPDATE quantity = quantity + VALUES(quantity)`) ?? []; const sql = ParameterizedSQL.join(stmts, ';'); const result = await conn.executeStmt(sql, myOptions); diff --git a/modules/ticket/back/methods/ticket/specs/itemLackoOrigin.spec.js b/modules/ticket/back/methods/ticket/specs/itemLackoOrigin.spec.js deleted file mode 100644 index 901bd12bb..000000000 --- a/modules/ticket/back/methods/ticket/specs/itemLackoOrigin.spec.js +++ /dev/null @@ -1,19 +0,0 @@ -const models = require('vn-loopback/server/server').models; - -describe('Item Lack NegativeOrigin', () => { - it('should return OK', async() => { - const tx = await models.Ticket.beginTransaction({}); - const ctx = {req: {accessToken: {userId: 9}}}; - - const options = {transaction: tx}; - const data = [{itemFk: 1, negativeType: 'FALTAS', lack: 1}, {itemFk: 1, negativeType: 'FALTAS', lack: 2}]; - - await models.Ticket.itemLackOrigin(ctx, data, options); - const query = 'SELECT * FROM vn.negativeOrigin'; - - const negativeOrigin = await models.Application.rawSql(query, null, options); - - expect(negativeOrigin.length).toEqual(1); - expect(negativeOrigin[0].quantity).toEqual(3); - }); -}); diff --git a/modules/ticket/back/methods/ticket/specs/negativeOrigin.spec.js b/modules/ticket/back/methods/ticket/specs/negativeOrigin.spec.js new file mode 100644 index 000000000..899f3c63a --- /dev/null +++ b/modules/ticket/back/methods/ticket/specs/negativeOrigin.spec.js @@ -0,0 +1,51 @@ +const models = require('vn-loopback/server/server').models; + +fdescribe('NegativeOrigin', () => { + it('should return OK', async() => { + const tx = await models.Ticket.beginTransaction({}); + const ctx = {req: {accessToken: {userId: 9}}}; + + const options = {transaction: tx}; + const data = [ + {itemFk: 1, negativeType: 'FALTAS', lack: 1}, + {itemFk: 1, negativeType: 'FALTAS', lack: 2} + ]; + try { + await models.Ticket.itemLackOrigin(ctx, data, options); + const query = 'SELECT * FROM vn.negativeOrigin'; + + const negativeOrigin = await models.Application.rawSql(query, null, options); + + expect(negativeOrigin.length).toEqual(1); + expect(negativeOrigin[0].quantity).toEqual(3); + await tx.rollback(); + } catch (e) { + await tx.rollback(); + throw e; + } + }); + + it('should add 2 lines', async() => { + const tx = await models.Ticket.beginTransaction({}); + const ctx = {req: {accessToken: {userId: 9}}}; + + const options = {transaction: tx}; + const data = [ + {itemFk: 2, negativeType: 'FALTAS', lack: 1}, + {itemFk: 3, negativeType: 'FALTAS', lack: 2} + ]; + try { + await models.Ticket.itemLackOrigin(ctx, data, options); + const query = 'SELECT * FROM vn.negativeOrigin'; + + const negativeOrigin = await models.Application.rawSql(query, null, options); + + expect(negativeOrigin.length).toEqual(2); + expect(negativeOrigin[0].quantity).toEqual(1); + await tx.rollback(); + } catch (e) { + await tx.rollback(); + throw e; + } + }); +});