Merge branch '1893-dbTest_ticket_recalcComponents' of verdnatura/salix into dev
gitea/salix/dev There was a failure building this commit Details

This commit is contained in:
Carlos Jimenez Ruiz 2020-02-12 13:13:56 +00:00 committed by Gitea
commit 8002fa459b
3 changed files with 75 additions and 13 deletions

View File

@ -753,7 +753,7 @@ INSERT INTO `vn`.`sale`(`id`, `itemFk`, `ticketFk`, `concept`, `quantity`, `pric
(7, 2, 11, 'Melee weapon combat fist 15cm', 15, 7.44, 0, 0, 0, CURDATE()),
(8, 4, 11, 'Melee weapon heavy shield 1x0.5m', 10, 1.79, 0, 0, 0, CURDATE()),
(9, 1, 16, 'Ranged weapon longbow 2m', 1, 103.49, 0, 0, 0, CURDATE()),
(10, 2, 16, 'Melee weapon combat fist 15cm', 10, 7.08, 0, 0, 0, CURDATE()),
(10, 2, 16, 'Melee weapon combat fist 15cm', 10, 7.09, 0, 0, 0, CURDATE()),
(11, 1, 16, 'Ranged weapon longbow 2m', 1, 103.49, 0, 0, 0, CURDATE()),
(12, 4, 16, 'Melee weapon heavy shield 1x0.5m', 20, 1.71, 0, 0, 0, CURDATE()),
(13, 2, 8, 'Melee weapon combat fist 15cm', 10, 7.08, 0, 0, 0, CURDATE()),
@ -814,25 +814,25 @@ INSERT INTO `vn`.`saleComponent`(`saleFk`, `componentFk`, `value`)
(8, 28, 1.25),
(8, 29, 0.42),
(8, 39, 0.017),
(9, 15, 3.0949),
(9, 21, 0.001),
(9, 28, 50),
(9, 29, 49.4),
(9, 28, 53),
(9, 29, 46.4),
(9, 39, 0.994),
(10, 15, 0.0111),
(10, 21, -0.001),
(10, 28, 5),
(10, 29, 2),
(10, 15, 0.0199),
(10, 28, 7),
(10, 29, 0),
(10, 39, 0.07),
(11, 15, 3.0949),
(11, 21, 0.001),
(11, 28, 50),
(11, 29, 49.4),
(11, 28, 53),
(11, 29, 46.4),
(11, 39, 0.994),
(12, 15, 0.0199),
(12, 21, 0.003),
(12, 28, 1.25),
(12, 29, 0.42),
(12, 28, 2.25),
(12, 29, -0.58),
(12, 39, 0.017),
(13, 15, 0.114),
(13, 28, 5),

View File

@ -0,0 +1,62 @@
const app = require('vn-loopback/server/server');
const ParameterizedSQL = require('loopback-connector').ParameterizedSQL;
describe('ticket_recalcComponents()', () => {
it('should recalculate the components in a ticket and check it', async() => {
let stmts = [];
let stmt;
const ticketId = 11;
stmts.push('START TRANSACTION');
let sales = await app.models.Sale.find({where: {ticketFk: ticketId}});
stmt = new ParameterizedSQL('UPDATE vn.sale SET price=100 WHERE id IN(?,?)', [
sales[0].id,
sales[1].id
]);
stmts.push(stmt);
stmt = new ParameterizedSQL('SELECT * FROM vn.sale WHERE ticketFk = ?', [
ticketId
]);
stmts.push(stmt);
let modifiedSales = stmts.push(stmt) - 1;
stmt = new ParameterizedSQL('CALL vn.ticket_recalcComponents(?)', [
ticketId,
]);
stmts.push(stmt);
stmt = new ParameterizedSQL('SELECT * FROM vn.sale WHERE ticketFk = ?', [
ticketId
]);
stmts.push(stmt);
let expectedSales = stmts.push(stmt) - 1;
stmts.push('ROLLBACK');
let sql = ParameterizedSQL.join(stmts, ';');
let result = await app.models.Ticket.rawStmt(sql);
// original data
const firstPrice = sales[0].price;
const secondPrice = sales[1].price;
// alteratons for test purposes
const modifiedFirstPrice = result[modifiedSales][0].price;
const modifiedSecondPrice = result[modifiedSales][1].price;
// expected data after recalc
const expectedSalesFirstPrice = result[expectedSales][0].price;
const expectedSalesSecondPrice = result[expectedSales][1].price;
expect(firstPrice).not.toEqual(modifiedFirstPrice);
expect(secondPrice).not.toEqual(modifiedSecondPrice);
expect(firstPrice).toEqual(expectedSalesFirstPrice);
expect(secondPrice).toEqual(expectedSalesSecondPrice);
});
});

View File

@ -17,8 +17,8 @@ describe('sale priceDifference()', () => {
let result = await app.models.Ticket.priceDifference(httpCtx, ticketId, landed,
addressId, agencyModeId, zoneId, warehouseId);
expect(result.totalUnitPrice).toEqual(215.77);
expect(result.totalNewPrice).toEqual(215.77);
expect(result.totalUnitPrice).toEqual(215.78);
expect(result.totalNewPrice).toEqual(215.78);
expect(result.totalDifference).toEqual(0);
});