refactor to parametrizedSql
This commit is contained in:
parent
ea6d1811cc
commit
8b89c64dd2
|
@ -4,7 +4,7 @@ const ParameterizedSQL = server.loopbackConnector.ParameterizedSQL;
|
||||||
|
|
||||||
describe('buyUltimate()', () => {
|
describe('buyUltimate()', () => {
|
||||||
const today = new Date();
|
const today = new Date();
|
||||||
it(`should create buyUltimate temporal table and update it's values`, async() => {
|
it(`should create buyUltimate temporal table and update it's values`, async () => {
|
||||||
let stmts = [];
|
let stmts = [];
|
||||||
let stmt;
|
let stmt;
|
||||||
|
|
||||||
|
|
|
@ -20,7 +20,7 @@ describe('buyUltimateFromInterval()', () => {
|
||||||
future = [year, futureMonth, day].join('-');
|
future = [year, futureMonth, day].join('-');
|
||||||
});
|
});
|
||||||
|
|
||||||
it(`should create a temporal table with it's data`, async() => {
|
it(`should create a temporal table with it's data`, async () => {
|
||||||
let stmts = [];
|
let stmts = [];
|
||||||
let stmt;
|
let stmt;
|
||||||
|
|
||||||
|
@ -63,7 +63,7 @@ describe('buyUltimateFromInterval()', () => {
|
||||||
expect(buyUltimateFromIntervalTable[1].landed).toEqual(today);
|
expect(buyUltimateFromIntervalTable[1].landed).toEqual(today);
|
||||||
});
|
});
|
||||||
|
|
||||||
it(`should create a temporal table with it's data in which started value is assigned to ended`, async() => {
|
it(`should create a temporal table with it's data in which started value is assigned to ended`, async () => {
|
||||||
let params = {
|
let params = {
|
||||||
warehouseFk: 1,
|
warehouseFk: 1,
|
||||||
started: today,
|
started: today,
|
||||||
|
@ -99,7 +99,7 @@ describe('buyUltimateFromInterval()', () => {
|
||||||
expect(buyUltimateFromIntervalTable[1].landed).toEqual(today);
|
expect(buyUltimateFromIntervalTable[1].landed).toEqual(today);
|
||||||
});
|
});
|
||||||
|
|
||||||
it(`should create a temporal table with it's data in which ended value is a date in the future`, async() => {
|
it(`should create a temporal table with it's data in which ended value is a date in the future`, async () => {
|
||||||
let params = {
|
let params = {
|
||||||
warehouseFk: 1,
|
warehouseFk: 1,
|
||||||
started: today,
|
started: today,
|
||||||
|
|
|
@ -3,7 +3,7 @@ const server = require(`../../../loopback/server/server`);
|
||||||
const ParameterizedSQL = server.loopbackConnector.ParameterizedSQL;
|
const ParameterizedSQL = server.loopbackConnector.ParameterizedSQL;
|
||||||
|
|
||||||
describe('logAddWithUser()', () => {
|
describe('logAddWithUser()', () => {
|
||||||
it('should log any action taken by the user in a table ending in Log', async() => {
|
it('should log any action taken by the user in a table ending in Log', async () => {
|
||||||
let stmts = [];
|
let stmts = [];
|
||||||
let stmt;
|
let stmt;
|
||||||
|
|
||||||
|
|
|
@ -4,7 +4,7 @@ const ParameterizedSQL = server.loopbackConnector.ParameterizedSQL;
|
||||||
|
|
||||||
describe('ticket ticketCalculateClon()', () => {
|
describe('ticket ticketCalculateClon()', () => {
|
||||||
const today = new Date();
|
const today = new Date();
|
||||||
it('should add the ticket to the order containing the original ticket', async() => {
|
it('should add the ticket to the order containing the original ticket', async () => {
|
||||||
let stmts = [];
|
let stmts = [];
|
||||||
let stmt;
|
let stmt;
|
||||||
|
|
||||||
|
@ -57,7 +57,7 @@ describe('ticket ticketCalculateClon()', () => {
|
||||||
expect(result[angencyHourIndex][0].landed).toBeDefined();
|
expect(result[angencyHourIndex][0].landed).toBeDefined();
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should add the ticket to the order containing the original ticket and generate landed value if it was null', async() => {
|
it('should add the ticket to the order containing the original ticket and generate landed value if it was null', async () => {
|
||||||
let stmts = [];
|
let stmts = [];
|
||||||
let stmt;
|
let stmt;
|
||||||
|
|
||||||
|
|
|
@ -3,7 +3,7 @@ const server = require(`../../../loopback/server/server`);
|
||||||
const ParameterizedSQL = server.loopbackConnector.ParameterizedSQL;
|
const ParameterizedSQL = server.loopbackConnector.ParameterizedSQL;
|
||||||
|
|
||||||
describe('ticketComponentUpdateSale()', () => {
|
describe('ticketComponentUpdateSale()', () => {
|
||||||
it(`should update the sale price when option ONE using the base components and reclaculate only the ones with isRenewable TRUE`, async() => {
|
it(`should update the sale price when option ONE using the base components and reclaculate only the ones with isRenewable TRUE`, async () => {
|
||||||
let stmts = [];
|
let stmts = [];
|
||||||
let stmt;
|
let stmt;
|
||||||
|
|
||||||
|
@ -96,7 +96,7 @@ describe('ticketComponentUpdateSale()', () => {
|
||||||
expect(result[firstSalePriceIndexAfter][0].price).toEqual(5);
|
expect(result[firstSalePriceIndexAfter][0].price).toEqual(5);
|
||||||
});
|
});
|
||||||
|
|
||||||
it(`should keep the sale price when option TWO using the base components and save the difference in a new component`, async() => {
|
it(`should keep the sale price when option TWO using the base components and save the difference in a new component`, async () => {
|
||||||
let stmts = [];
|
let stmts = [];
|
||||||
let stmt;
|
let stmt;
|
||||||
|
|
||||||
|
@ -190,7 +190,7 @@ describe('ticketComponentUpdateSale()', () => {
|
||||||
expect(result[firstSalePriceIndexBefore][0].price).toEqual(result[firstSalePriceIndexAfter][0].price);
|
expect(result[firstSalePriceIndexBefore][0].price).toEqual(result[firstSalePriceIndexAfter][0].price);
|
||||||
});
|
});
|
||||||
|
|
||||||
it(`should not change the sale price when option SEVEN, instead it stores 80% and 20% of the price in two components and any price difference in a third one`, async() => {
|
it(`should not change the sale price when option SEVEN, instead it stores 80% and 20% of the price in two components and any price difference in a third one`, async () => {
|
||||||
let stmts = [];
|
let stmts = [];
|
||||||
let stmt;
|
let stmt;
|
||||||
|
|
||||||
|
|
|
@ -1,8 +1,15 @@
|
||||||
const app = require(`../../../ticket/server/server`);
|
const app = require(`../../../ticket/server/server`);
|
||||||
|
const server = require(`../../../loopback/server/server`);
|
||||||
|
const ParameterizedSQL = server.loopbackConnector.ParameterizedSQL;
|
||||||
|
|
||||||
describe('ticket ticketCreateWithUser()', () => {
|
describe('ticket ticketCreateWithUser()', () => {
|
||||||
const today = new Date();
|
const today = new Date();
|
||||||
it('should confirm the procedure creates the expected ticket', async() => {
|
it('should confirm the procedure creates the expected ticket', async () => {
|
||||||
|
let stmts = [];
|
||||||
|
let stmt;
|
||||||
|
|
||||||
|
stmts.push('START TRANSACTION');
|
||||||
|
|
||||||
let params = {
|
let params = {
|
||||||
clientFk: 101,
|
clientFk: 101,
|
||||||
shipped: today,
|
shipped: today,
|
||||||
|
@ -15,13 +22,7 @@ describe('ticket ticketCreateWithUser()', () => {
|
||||||
userId: 18
|
userId: 18
|
||||||
};
|
};
|
||||||
|
|
||||||
let query = `
|
stmt = new ParameterizedSQL(`CALL vn.ticketCreateWithUser(?, ?, ?, ?, ?, ?, ?, ?, ?, @newTicketId)`, [
|
||||||
START TRANSACTION;
|
|
||||||
CALL vn.ticketCreateWithUser(?, ?, ?, ?, ?, ?, ?, ?, ?, @newTicketId);
|
|
||||||
SELECT @newTicketId newTicketId;
|
|
||||||
SELECT * FROM vn.ticket WHERE id = @newTicketId;
|
|
||||||
ROLLBACK;`;
|
|
||||||
let result = await app.models.Ticket.rawSql(query, [
|
|
||||||
params.clientFk,
|
params.clientFk,
|
||||||
params.shipped,
|
params.shipped,
|
||||||
params.warehouseFk,
|
params.warehouseFk,
|
||||||
|
@ -32,22 +33,33 @@ describe('ticket ticketCreateWithUser()', () => {
|
||||||
params.landed,
|
params.landed,
|
||||||
params.userId
|
params.userId
|
||||||
]);
|
]);
|
||||||
|
stmts.push(stmt);
|
||||||
|
|
||||||
let ticketResult = result[2][0];
|
let ticketResultIndex = stmts.push(`SELECT * FROM vn.ticket WHERE id = @newTicketId`) - 1;
|
||||||
|
|
||||||
expect(ticketResult.newTicketId).toBeGreaterThan(21);
|
stmts.push('ROLLBACK');
|
||||||
|
|
||||||
let createdTicket = result[3][0];
|
let sql = ParameterizedSQL.join(stmts, ';');
|
||||||
|
let result = await app.models.Ticket.rawStmt(sql);
|
||||||
|
|
||||||
expect(createdTicket.clientFk).toEqual(params.clientFk);
|
let ticketResult = result[ticketResultIndex][0];
|
||||||
expect(createdTicket.warehouseFk).toEqual(params.warehouseFk);
|
|
||||||
expect(createdTicket.companyFk).toEqual(params.companyFk);
|
|
||||||
expect(createdTicket.addressFk).toEqual(params.addressFk);
|
expect(ticketResult.id).toBeGreaterThan(21);
|
||||||
expect(createdTicket.agencyModeFk).toEqual(params.agencyModeFk);
|
expect(ticketResult.clientFk).toEqual(params.clientFk);
|
||||||
expect(createdTicket.routeFk).toEqual(params.routeFk);
|
expect(ticketResult.warehouseFk).toEqual(params.warehouseFk);
|
||||||
|
expect(ticketResult.companyFk).toEqual(params.companyFk);
|
||||||
|
expect(ticketResult.addressFk).toEqual(params.addressFk);
|
||||||
|
expect(ticketResult.agencyModeFk).toEqual(params.agencyModeFk);
|
||||||
|
expect(ticketResult.routeFk).toEqual(params.routeFk);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should confirm the procedure creates the expected observations in the ticket', async() => {
|
it('should confirm the procedure creates the expected observations in the ticket', async () => {
|
||||||
|
let stmts = [];
|
||||||
|
let stmt;
|
||||||
|
|
||||||
|
stmts.push('START TRANSACTION');
|
||||||
|
|
||||||
let params = {
|
let params = {
|
||||||
clientFk: 101,
|
clientFk: 101,
|
||||||
shipped: today,
|
shipped: today,
|
||||||
|
@ -60,13 +72,7 @@ describe('ticket ticketCreateWithUser()', () => {
|
||||||
userId: 18
|
userId: 18
|
||||||
};
|
};
|
||||||
|
|
||||||
let query = `
|
stmt = new ParameterizedSQL('CALL vn.ticketCreateWithUser(?, ?, ?, ?, ?, ?, ?, ?, ?, @newTicketId)', [
|
||||||
START TRANSACTION;
|
|
||||||
CALL vn.ticketCreateWithUser(?, ?, ?, ?, ?, ?, ?, ?, ?, @newTicketId);
|
|
||||||
SELECT @newTicketId newTicketId;
|
|
||||||
SELECT * FROM vn.ticketObservation WHERE ticketFk = @newTicketId;
|
|
||||||
ROLLBACK;`;
|
|
||||||
let result = await app.models.Ticket.rawSql(query, [
|
|
||||||
params.clientFk,
|
params.clientFk,
|
||||||
params.shipped,
|
params.shipped,
|
||||||
params.warehouseFk,
|
params.warehouseFk,
|
||||||
|
@ -77,10 +83,19 @@ describe('ticket ticketCreateWithUser()', () => {
|
||||||
params.landed,
|
params.landed,
|
||||||
params.userId
|
params.userId
|
||||||
]);
|
]);
|
||||||
|
stmts.push(stmt);
|
||||||
|
|
||||||
let firstTicketObservation = result[3][0];
|
let ticketObsevationsIndex = stmts.push(`SELECT * FROM vn.ticketObservation WHERE ticketFk = @newTicketId`) - 1;
|
||||||
let secondTicketObservation = result[3][1];
|
|
||||||
let thirdTicketObservation = result[3][2];
|
stmts.push('ROLLBACK');
|
||||||
|
|
||||||
|
let sql = ParameterizedSQL.join(stmts, ';');
|
||||||
|
let result = await app.models.Ticket.rawStmt(sql);
|
||||||
|
|
||||||
|
|
||||||
|
let firstTicketObservation = result[ticketObsevationsIndex][0];
|
||||||
|
let secondTicketObservation = result[ticketObsevationsIndex][1];
|
||||||
|
let thirdTicketObservation = result[ticketObsevationsIndex][2];
|
||||||
|
|
||||||
expect(firstTicketObservation.observationTypeFk).toEqual(1);
|
expect(firstTicketObservation.observationTypeFk).toEqual(1);
|
||||||
expect(firstTicketObservation.description).toEqual('under the floor');
|
expect(firstTicketObservation.description).toEqual('under the floor');
|
||||||
|
@ -90,7 +105,12 @@ describe('ticket ticketCreateWithUser()', () => {
|
||||||
expect(thirdTicketObservation.description).toEqual('care with the dog');
|
expect(thirdTicketObservation.description).toEqual('care with the dog');
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should confirm the procedure sets companyFk as Tenerife if vProvinceName is SANTA CRUZ DE TENERIFE', async() => {
|
it('should confirm the procedure sets companyFk as Tenerife if vProvinceName is SANTA CRUZ DE TENERIFE', async () => {
|
||||||
|
let stmts = [];
|
||||||
|
let stmt;
|
||||||
|
|
||||||
|
stmts.push('START TRANSACTION');
|
||||||
|
|
||||||
let params = {
|
let params = {
|
||||||
clientFk: 101,
|
clientFk: 101,
|
||||||
shipped: today,
|
shipped: today,
|
||||||
|
@ -105,17 +125,12 @@ describe('ticket ticketCreateWithUser()', () => {
|
||||||
|
|
||||||
let tenerife = 1381;
|
let tenerife = 1381;
|
||||||
|
|
||||||
let changeProvinceToTenerife = `UPDATE province p, client c SET p.name ='SANTA CRUZ DE TENERIFE' WHERE p.id = c.provinceFk AND c.id = ?;`;
|
stmt = new ParameterizedSQL(`UPDATE province p, client c SET p.name ='SANTA CRUZ DE TENERIFE' WHERE p.id = c.provinceFk AND c.id = ?`, [
|
||||||
|
|
||||||
let query = `
|
|
||||||
START TRANSACTION;
|
|
||||||
${changeProvinceToTenerife}
|
|
||||||
CALL vn.ticketCreateWithUser(?, ?, ?, ?, ?, ?, ?, ?, ?, @newTicketId);
|
|
||||||
SELECT @newTicketId newTicketId;
|
|
||||||
SELECT companyFk FROM vn.ticket WHERE id = @newTicketId;
|
|
||||||
ROLLBACK;`;
|
|
||||||
let result = await app.models.Ticket.rawSql(query, [
|
|
||||||
params.clientFk,
|
params.clientFk,
|
||||||
|
]);
|
||||||
|
stmts.push(stmt);
|
||||||
|
|
||||||
|
stmt = new ParameterizedSQL(`CALL vn.ticketCreateWithUser(?, ?, ?, ?, ?, ?, ?, ?, ?, @newTicketId)`, [
|
||||||
params.clientFk,
|
params.clientFk,
|
||||||
params.shipped,
|
params.shipped,
|
||||||
params.warehouseFk,
|
params.warehouseFk,
|
||||||
|
@ -126,13 +141,26 @@ describe('ticket ticketCreateWithUser()', () => {
|
||||||
params.landed,
|
params.landed,
|
||||||
params.userId
|
params.userId
|
||||||
]);
|
]);
|
||||||
|
stmts.push(stmt);
|
||||||
|
|
||||||
let ticket = result[4][0];
|
let ticketCompanyIndex = stmts.push(`SELECT companyFk FROM vn.ticket WHERE id = @newTicketId`) - 1;
|
||||||
|
|
||||||
|
stmts.push('ROLLBACK');
|
||||||
|
|
||||||
|
let sql = ParameterizedSQL.join(stmts, ';');
|
||||||
|
let result = await app.models.Ticket.rawStmt(sql);
|
||||||
|
|
||||||
|
let ticket = result[ticketCompanyIndex][0];
|
||||||
|
|
||||||
expect(ticket.companyFk).toEqual(tenerife);
|
expect(ticket.companyFk).toEqual(tenerife);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should confirm the procedure sets address if it received it null', async() => {
|
it('should confirm the procedure sets address if it received it null', async () => {
|
||||||
|
let stmts = [];
|
||||||
|
let stmt;
|
||||||
|
|
||||||
|
stmts.push('START TRANSACTION');
|
||||||
|
|
||||||
let params = {
|
let params = {
|
||||||
clientFk: 101,
|
clientFk: 101,
|
||||||
shipped: today,
|
shipped: today,
|
||||||
|
@ -145,14 +173,7 @@ describe('ticket ticketCreateWithUser()', () => {
|
||||||
userId: 18
|
userId: 18
|
||||||
};
|
};
|
||||||
|
|
||||||
let query = `
|
stmt = new ParameterizedSQL(`CALL vn.ticketCreateWithUser(?, ?, ?, ?, ?, ?, ?, ?, ?, @newTicketId)`, [
|
||||||
START TRANSACTION;
|
|
||||||
CALL vn.ticketCreateWithUser(?, ?, ?, ?, ?, ?, ?, ?, ?, @newTicketId);
|
|
||||||
SELECT @newTicketId newTicketId;
|
|
||||||
SELECT addressFk FROM vn.ticket WHERE id = @newTicketId;
|
|
||||||
SELECT id FROM vn.address WHERE clientFk = ? AND isDefaultAddress = 1;
|
|
||||||
ROLLBACK;`;
|
|
||||||
let result = await app.models.Ticket.rawSql(query, [
|
|
||||||
params.clientFk,
|
params.clientFk,
|
||||||
params.shipped,
|
params.shipped,
|
||||||
params.warehouseFk,
|
params.warehouseFk,
|
||||||
|
@ -161,17 +182,34 @@ describe('ticket ticketCreateWithUser()', () => {
|
||||||
params.agencyModeFk,
|
params.agencyModeFk,
|
||||||
params.routeFk,
|
params.routeFk,
|
||||||
params.landed,
|
params.landed,
|
||||||
params.userId,
|
params.userId
|
||||||
params.clientFk
|
|
||||||
]);
|
]);
|
||||||
|
stmts.push(stmt);
|
||||||
|
|
||||||
let ticket = result[2][0];
|
let ticketAddressIndex = stmts.push(`SELECT addressFk FROM vn.ticket WHERE id = @newTicketId`) - 1;
|
||||||
let clientDefaultAddress = result[3][0];
|
|
||||||
|
|
||||||
expect(ticket.addressFk).toEqual(clientDefaultAddress.id);
|
stmt = new ParameterizedSQL(`SELECT id FROM vn.address WHERE clientFk = ? AND isDefaultAddress = 1`, [
|
||||||
|
params.clientFk,
|
||||||
|
]);
|
||||||
|
let clientDefaultAddressIndex = stmts.push(stmt) - 1;
|
||||||
|
|
||||||
|
stmts.push('ROLLBACK');
|
||||||
|
|
||||||
|
let sql = ParameterizedSQL.join(stmts, ';');
|
||||||
|
let result = await app.models.Ticket.rawStmt(sql);
|
||||||
|
|
||||||
|
let ticketAddress = result[ticketAddressIndex][0];
|
||||||
|
let clientDefaultAddress = result[clientDefaultAddressIndex][0];
|
||||||
|
|
||||||
|
expect(ticketAddress.addressFk).toEqual(clientDefaultAddress.id);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should confirm the procedure creates the state as delivered if the client has isCreatedAsServed TRUE', async() => {
|
it('should confirm the procedure creates the state as delivered if the client has isCreatedAsServed TRUE', async () => {
|
||||||
|
let stmts = [];
|
||||||
|
let stmt;
|
||||||
|
|
||||||
|
stmts.push('START TRANSACTION');
|
||||||
|
|
||||||
let params = {
|
let params = {
|
||||||
clientFk: 101,
|
clientFk: 101,
|
||||||
shipped: today,
|
shipped: today,
|
||||||
|
@ -184,17 +222,12 @@ describe('ticket ticketCreateWithUser()', () => {
|
||||||
userId: 18
|
userId: 18
|
||||||
};
|
};
|
||||||
|
|
||||||
let setAsIsDelivered = `UPDATE vn.client SET isCreatedAsServed = 1 WHERE id = ?;`;
|
stmt = new ParameterizedSQL(`UPDATE vn.client SET isCreatedAsServed = 1 WHERE id = ?`, [
|
||||||
|
|
||||||
let query = `
|
|
||||||
START TRANSACTION;
|
|
||||||
${setAsIsDelivered}
|
|
||||||
CALL vn.ticketCreateWithUser(?, ?, ?, ?, ?, ?, ?, ?, ?, @newTicketId);
|
|
||||||
SELECT @newTicketId newTicketId;
|
|
||||||
SELECT code FROM vn.ticketState WHERE ticketFk = @newTicketId;
|
|
||||||
ROLLBACK;`;
|
|
||||||
let result = await app.models.Ticket.rawSql(query, [
|
|
||||||
params.clientFk,
|
params.clientFk,
|
||||||
|
]);
|
||||||
|
stmts.push(stmt);
|
||||||
|
|
||||||
|
stmt = new ParameterizedSQL(`CALL vn.ticketCreateWithUser(?, ?, ?, ?, ?, ?, ?, ?, ?, @newTicketId)`, [
|
||||||
params.clientFk,
|
params.clientFk,
|
||||||
params.shipped,
|
params.shipped,
|
||||||
params.warehouseFk,
|
params.warehouseFk,
|
||||||
|
@ -203,12 +236,19 @@ describe('ticket ticketCreateWithUser()', () => {
|
||||||
params.agencyModeFk,
|
params.agencyModeFk,
|
||||||
params.routeFk,
|
params.routeFk,
|
||||||
params.landed,
|
params.landed,
|
||||||
params.userId,
|
params.userId
|
||||||
params.clientFk
|
|
||||||
]);
|
]);
|
||||||
|
stmts.push(stmt);
|
||||||
|
|
||||||
let ticketState = result[4][0];
|
let ticketStateCodeIndex = stmts.push(`SELECT code FROM vn.ticketState WHERE ticketFk = @newTicketId`) - 1;
|
||||||
|
|
||||||
expect(ticketState.code).toEqual('DELIVERED');
|
stmts.push('ROLLBACK');
|
||||||
|
|
||||||
|
let sql = ParameterizedSQL.join(stmts, ';');
|
||||||
|
let result = await app.models.Ticket.rawStmt(sql);
|
||||||
|
|
||||||
|
let ticketStateCode = result[ticketStateCodeIndex][0].code;
|
||||||
|
|
||||||
|
expect(ticketStateCode).toEqual('DELIVERED');
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in New Issue