refs #6321 test: negativeOrigin

This commit is contained in:
Javier Segarra 2024-04-01 13:11:58 +02:00
parent 2cff160c6a
commit d62c55dc9f
3 changed files with 52 additions and 20 deletions

View File

@ -31,7 +31,7 @@ module.exports = Self => {
const conn = Self.dataSource.connector; const conn = Self.dataSource.connector;
const stmts = data.map(({itemFk, negativeType, lack}) => const stmts = data.map(({itemFk, negativeType, lack}) =>
`INSERT INTO vn.negativeOrigin (itemFk, type, quantity) `INSERT INTO vn.negativeOrigin (itemFk, type, quantity)
VALUES (${itemFk}, '${negativeType}', ${lack}) VALUES (${itemFk}, "${negativeType}", ${lack})
ON DUPLICATE KEY UPDATE quantity = quantity + VALUES(quantity)`) ?? []; ON DUPLICATE KEY UPDATE quantity = quantity + VALUES(quantity)`) ?? [];
const sql = ParameterizedSQL.join(stmts, ';'); const sql = ParameterizedSQL.join(stmts, ';');
const result = await conn.executeStmt(sql, myOptions); const result = await conn.executeStmt(sql, myOptions);

View File

@ -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);
});
});

View File

@ -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;
}
});
});