diff --git a/db/tests/cache/last_buy_refresh.spec.js b/db/tests/cache/last_buy_refresh.spec.js index 485c725bb..0036e2762 100644 --- a/db/tests/cache/last_buy_refresh.spec.js +++ b/db/tests/cache/last_buy_refresh.spec.js @@ -20,27 +20,27 @@ describe('last_buy_refresh()', () => { let lastBuyTable = result[lastBuyTableIndex]; - expect(lastBuyTable.length).toEqual(6); + expect(lastBuyTable.length).toEqual(12); expect(lastBuyTable[0].item_id).toEqual(1); - expect(lastBuyTable[1].item_id).toEqual(2); - expect(lastBuyTable[2].item_id).toEqual(3); - expect(lastBuyTable[3].item_id).toEqual(4); - expect(lastBuyTable[4].item_id).toEqual(8); - expect(lastBuyTable[5].item_id).toEqual(9); + expect(lastBuyTable[1].item_id).toEqual(1); + expect(lastBuyTable[2].item_id).toEqual(1); + expect(lastBuyTable[3].item_id).toEqual(2); + expect(lastBuyTable[4].item_id).toEqual(2); + expect(lastBuyTable[5].item_id).toEqual(3); expect(lastBuyTable[0].warehouse_id).toEqual(1); - expect(lastBuyTable[1].warehouse_id).toEqual(1); - expect(lastBuyTable[2].warehouse_id).toEqual(1); + expect(lastBuyTable[1].warehouse_id).toEqual(3); + expect(lastBuyTable[2].warehouse_id).toEqual(5); expect(lastBuyTable[3].warehouse_id).toEqual(1); - expect(lastBuyTable[4].warehouse_id).toEqual(1); + expect(lastBuyTable[4].warehouse_id).toEqual(5); expect(lastBuyTable[5].warehouse_id).toEqual(1); - expect(lastBuyTable[1].buy_id).toEqual(4); + expect(lastBuyTable[1].buy_id).toEqual(10); expect(lastBuyTable[0].buy_id).toEqual(3); - expect(lastBuyTable[2].buy_id).toEqual(5); - expect(lastBuyTable[3].buy_id).toEqual(8); - expect(lastBuyTable[4].buy_id).toEqual(6); - expect(lastBuyTable[5].buy_id).toEqual(7); + expect(lastBuyTable[2].buy_id).toEqual(13); + expect(lastBuyTable[3].buy_id).toEqual(4); + expect(lastBuyTable[4].buy_id).toEqual(14); + expect(lastBuyTable[5].buy_id).toEqual(5); }); }); diff --git a/db/tests/vn/ticketComponentUpdateSale.spec.js b/db/tests/vn/ticketComponentUpdateSale.spec.js index 45551c165..9e252200b 100644 --- a/db/tests/vn/ticketComponentUpdateSale.spec.js +++ b/db/tests/vn/ticketComponentUpdateSale.spec.js @@ -8,7 +8,7 @@ describe('ticketComponentUpdateSale()', () => { let params = { warehouseFk: 1, - ticketFk: 1 + ticketFk: 13 }; stmts.push('START TRANSACTION'); @@ -48,26 +48,29 @@ describe('ticketComponentUpdateSale()', () => { let insertTicketComponentTable = ` INSERT INTO tmp.ticketComponent (warehouseFk, itemFk, componentFk, cost) VALUES - (1 , 2 , 23 , 999.00), - (1 , 2 , 28 , 2.00), - (1 , 4 , 23 , 999.00), - (1 , 4 , 28 , 1.00) + (1 , 4 , 15 , 999.00), + (1 , 4 , 17 , 2.00), + (1 , 4 , 22 , 999.00), + (1 , 4 , 28 , 1.00), + (1 , 4 , 29 , 2.00), + (1 , 4 , 32 , 999.00), + (1 , 4 , 39 , 1.00) `; stmts.push(insertTicketComponentTable); - let updateComponentTwentyThree = ` + let updateComponentTwentyNine = ` UPDATE vn.saleComponent SET value = '5' - WHERE saleFk = 1 AND componentFk = 23 + WHERE saleFk = 26 AND componentFk = 29 `; - stmts.push(updateComponentTwentyThree); + stmts.push(updateComponentTwentyNine); let updateComponentTwentyEight = ` UPDATE vn.saleComponent SET value = '5' - WHERE saleFk = 1 AND componentFk = 28 + WHERE saleFk = 26 AND componentFk = 28 `; stmts.push(updateComponentTwentyEight); @@ -75,24 +78,24 @@ describe('ticketComponentUpdateSale()', () => { let priceFixtedToZero = ` UPDATE vn.sale SET priceFixed = 0 - WHERE id = 1 + WHERE id = 26 `; stmts.push(priceFixtedToZero); - let firstSalePriceIndexBefore = stmts.push('SELECT price FROM vn.sale WHERE id = 1') - 1; + let firstSalePriceIndexBefore = stmts.push('SELECT price FROM vn.sale WHERE id = 26') - 1; stmts.push('CALL vn.ticketComponentUpdateSale(1)'); - let firstSalePriceIndexAfter = stmts.push('SELECT price FROM vn.sale WHERE id = 1') - 1; + let firstSalePriceIndexAfter = stmts.push('SELECT price FROM vn.sale WHERE id = 26') - 1; stmts.push('ROLLBACK'); let sql = ParameterizedSQL.join(stmts, ';'); let result = await app.models.Ticket.rawStmt(sql); - expect(result[firstSalePriceIndexBefore][0].price).toEqual(9.1); - expect(result[firstSalePriceIndexAfter][0].price).toEqual(5); + expect(result[firstSalePriceIndexBefore][0].price).toEqual(1.72); + expect(result[firstSalePriceIndexAfter][0].price).toEqual(1005); }); it(`should keep the sale price when option TWO using the base components and save the difference in a new component`, async() => { @@ -101,7 +104,7 @@ describe('ticketComponentUpdateSale()', () => { let params = { warehouseFk: 1, - ticketFk: 1 + ticketFk: 13 }; stmts.push('START TRANSACTION'); @@ -139,28 +142,31 @@ describe('ticketComponentUpdateSale()', () => { stmts.push(createTicketComponentTable); let insertTicketComponentTable = ` - INSERT INTO tmp.ticketComponent (warehouseFk, itemFk, componentFk, cost) - VALUES - (1 , 2 , 23 , 999.00), - (1 , 2 , 28 , 2.00), - (1 , 4 , 23 , 999.00), - (1 , 4 , 28 , 1.00) + INSERT INTO tmp.ticketComponent (warehouseFk, itemFk, componentFk, cost) + VALUES + (1 , 4 , 15 , 999.00), + (1 , 4 , 17 , 2.00), + (1 , 4 , 22 , 999.00), + (1 , 4 , 28 , 1.00), + (1 , 4 , 29 , 2.00), + (1 , 4 , 32 , 999.00), + (1 , 4 , 39 , 1.00) `; stmts.push(insertTicketComponentTable); - let updateComponentTwentyThree = ` + let updateComponentTwentyNine = ` UPDATE vn.saleComponent SET value = '5' - WHERE saleFk = 1 AND componentFk = 23 + WHERE saleFk = 26 AND componentFk = 29 `; - stmts.push(updateComponentTwentyThree); + stmts.push(updateComponentTwentyNine); let updateComponentTwentyEight = ` UPDATE vn.saleComponent SET value = '5' - WHERE saleFk = 1 AND componentFk = 28 + WHERE saleFk = 26 AND componentFk = 28 `; stmts.push(updateComponentTwentyEight); @@ -168,24 +174,24 @@ describe('ticketComponentUpdateSale()', () => { let priceFixtedToZero = ` UPDATE vn.sale SET priceFixed = 0 - WHERE id = 1 + WHERE id = 26 `; stmts.push(priceFixtedToZero); - let firstSalePriceIndexBefore = stmts.push('SELECT price FROM vn.sale WHERE id = 1') - 1; + let firstSalePriceIndexBefore = stmts.push('SELECT price FROM vn.sale WHERE id = 26') - 1; stmts.push('CALL vn.ticketComponentUpdateSale(2)'); - let addedComponentIndex = stmts.push('SELECT * FROM vn.saleComponent WHERE saleFk = 1 AND componentFk = 17') - 1; - let firstSalePriceIndexAfter = stmts.push('SELECT price FROM vn.sale WHERE id = 1') - 1; + let addedComponentIndex = stmts.push('SELECT * FROM vn.saleComponent WHERE saleFk = 26 AND componentFk = 17') - 1; + let firstSalePriceIndexAfter = stmts.push('SELECT price FROM vn.sale WHERE id = 26') - 1; stmts.push('ROLLBACK'); let sql = ParameterizedSQL.join(stmts, ';'); let result = await app.models.Ticket.rawStmt(sql); - expect(result[addedComponentIndex][0].value).toEqual(4.1); + expect(result[addedComponentIndex][0].value).toEqual(-1003.28); expect(result[firstSalePriceIndexBefore][0].price).toEqual(result[firstSalePriceIndexAfter][0].price); }); @@ -280,8 +286,8 @@ describe('ticketComponentUpdateSale()', () => { let sql = ParameterizedSQL.join(stmts, ';'); let result = await app.models.Ticket.rawStmt(sql); - expect(result[componentTwentyEightIndex][0].value).toEqual(1.6); - expect(result[componentTwentyNineIndex][0].value).toEqual(0.4); + expect(result[componentTwentyEightIndex][0].value).toEqual(79.517); + expect(result[componentTwentyNineIndex][0].value).toEqual(19.879); expect(result[firstSalePriceIndexBefore][0].price).toEqual(result[firstSalePriceIndexAfter][0].price); }); });