refactor to parametrizedSql
This commit is contained in:
parent
ea6d1811cc
commit
8b89c64dd2
|
@ -4,7 +4,7 @@ const ParameterizedSQL = server.loopbackConnector.ParameterizedSQL;
|
|||
|
||||
describe('buyUltimate()', () => {
|
||||
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 stmt;
|
||||
|
||||
|
|
|
@ -20,7 +20,7 @@ describe('buyUltimateFromInterval()', () => {
|
|||
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 stmt;
|
||||
|
||||
|
@ -63,7 +63,7 @@ describe('buyUltimateFromInterval()', () => {
|
|||
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 = {
|
||||
warehouseFk: 1,
|
||||
started: today,
|
||||
|
@ -99,7 +99,7 @@ describe('buyUltimateFromInterval()', () => {
|
|||
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 = {
|
||||
warehouseFk: 1,
|
||||
started: today,
|
||||
|
|
|
@ -3,7 +3,7 @@ const server = require(`../../../loopback/server/server`);
|
|||
const ParameterizedSQL = server.loopbackConnector.ParameterizedSQL;
|
||||
|
||||
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 stmt;
|
||||
|
||||
|
|
|
@ -4,7 +4,7 @@ const ParameterizedSQL = server.loopbackConnector.ParameterizedSQL;
|
|||
|
||||
describe('ticket ticketCalculateClon()', () => {
|
||||
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 stmt;
|
||||
|
||||
|
@ -57,7 +57,7 @@ describe('ticket ticketCalculateClon()', () => {
|
|||
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 stmt;
|
||||
|
||||
|
|
|
@ -3,7 +3,7 @@ const server = require(`../../../loopback/server/server`);
|
|||
const ParameterizedSQL = server.loopbackConnector.ParameterizedSQL;
|
||||
|
||||
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 stmt;
|
||||
|
||||
|
@ -96,7 +96,7 @@ describe('ticketComponentUpdateSale()', () => {
|
|||
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 stmt;
|
||||
|
||||
|
@ -190,7 +190,7 @@ describe('ticketComponentUpdateSale()', () => {
|
|||
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 stmt;
|
||||
|
||||
|
|
|
@ -1,8 +1,15 @@
|
|||
const app = require(`../../../ticket/server/server`);
|
||||
const server = require(`../../../loopback/server/server`);
|
||||
const ParameterizedSQL = server.loopbackConnector.ParameterizedSQL;
|
||||
|
||||
describe('ticket ticketCreateWithUser()', () => {
|
||||
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 = {
|
||||
clientFk: 101,
|
||||
shipped: today,
|
||||
|
@ -15,13 +22,7 @@ describe('ticket ticketCreateWithUser()', () => {
|
|||
userId: 18
|
||||
};
|
||||
|
||||
let query = `
|
||||
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, [
|
||||
stmt = new ParameterizedSQL(`CALL vn.ticketCreateWithUser(?, ?, ?, ?, ?, ?, ?, ?, ?, @newTicketId)`, [
|
||||
params.clientFk,
|
||||
params.shipped,
|
||||
params.warehouseFk,
|
||||
|
@ -32,22 +33,33 @@ describe('ticket ticketCreateWithUser()', () => {
|
|||
params.landed,
|
||||
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);
|
||||
expect(createdTicket.warehouseFk).toEqual(params.warehouseFk);
|
||||
expect(createdTicket.companyFk).toEqual(params.companyFk);
|
||||
expect(createdTicket.addressFk).toEqual(params.addressFk);
|
||||
expect(createdTicket.agencyModeFk).toEqual(params.agencyModeFk);
|
||||
expect(createdTicket.routeFk).toEqual(params.routeFk);
|
||||
let ticketResult = result[ticketResultIndex][0];
|
||||
|
||||
|
||||
expect(ticketResult.id).toBeGreaterThan(21);
|
||||
expect(ticketResult.clientFk).toEqual(params.clientFk);
|
||||
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 = {
|
||||
clientFk: 101,
|
||||
shipped: today,
|
||||
|
@ -60,13 +72,7 @@ describe('ticket ticketCreateWithUser()', () => {
|
|||
userId: 18
|
||||
};
|
||||
|
||||
let query = `
|
||||
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, [
|
||||
stmt = new ParameterizedSQL('CALL vn.ticketCreateWithUser(?, ?, ?, ?, ?, ?, ?, ?, ?, @newTicketId)', [
|
||||
params.clientFk,
|
||||
params.shipped,
|
||||
params.warehouseFk,
|
||||
|
@ -77,10 +83,19 @@ describe('ticket ticketCreateWithUser()', () => {
|
|||
params.landed,
|
||||
params.userId
|
||||
]);
|
||||
stmts.push(stmt);
|
||||
|
||||
let firstTicketObservation = result[3][0];
|
||||
let secondTicketObservation = result[3][1];
|
||||
let thirdTicketObservation = result[3][2];
|
||||
let ticketObsevationsIndex = stmts.push(`SELECT * FROM vn.ticketObservation WHERE ticketFk = @newTicketId`) - 1;
|
||||
|
||||
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.description).toEqual('under the floor');
|
||||
|
@ -90,7 +105,12 @@ describe('ticket ticketCreateWithUser()', () => {
|
|||
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 = {
|
||||
clientFk: 101,
|
||||
shipped: today,
|
||||
|
@ -105,17 +125,12 @@ describe('ticket ticketCreateWithUser()', () => {
|
|||
|
||||
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 = ?;`;
|
||||
|
||||
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, [
|
||||
stmt = new ParameterizedSQL(`UPDATE province p, client c SET p.name ='SANTA CRUZ DE TENERIFE' WHERE p.id = c.provinceFk AND c.id = ?`, [
|
||||
params.clientFk,
|
||||
]);
|
||||
stmts.push(stmt);
|
||||
|
||||
stmt = new ParameterizedSQL(`CALL vn.ticketCreateWithUser(?, ?, ?, ?, ?, ?, ?, ?, ?, @newTicketId)`, [
|
||||
params.clientFk,
|
||||
params.shipped,
|
||||
params.warehouseFk,
|
||||
|
@ -126,13 +141,26 @@ describe('ticket ticketCreateWithUser()', () => {
|
|||
params.landed,
|
||||
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);
|
||||
});
|
||||
|
||||
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 = {
|
||||
clientFk: 101,
|
||||
shipped: today,
|
||||
|
@ -145,14 +173,7 @@ describe('ticket ticketCreateWithUser()', () => {
|
|||
userId: 18
|
||||
};
|
||||
|
||||
let query = `
|
||||
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, [
|
||||
stmt = new ParameterizedSQL(`CALL vn.ticketCreateWithUser(?, ?, ?, ?, ?, ?, ?, ?, ?, @newTicketId)`, [
|
||||
params.clientFk,
|
||||
params.shipped,
|
||||
params.warehouseFk,
|
||||
|
@ -161,17 +182,34 @@ describe('ticket ticketCreateWithUser()', () => {
|
|||
params.agencyModeFk,
|
||||
params.routeFk,
|
||||
params.landed,
|
||||
params.userId,
|
||||
params.clientFk
|
||||
params.userId
|
||||
]);
|
||||
stmts.push(stmt);
|
||||
|
||||
let ticket = result[2][0];
|
||||
let clientDefaultAddress = result[3][0];
|
||||
let ticketAddressIndex = stmts.push(`SELECT addressFk FROM vn.ticket WHERE id = @newTicketId`) - 1;
|
||||
|
||||
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 = {
|
||||
clientFk: 101,
|
||||
shipped: today,
|
||||
|
@ -184,17 +222,12 @@ describe('ticket ticketCreateWithUser()', () => {
|
|||
userId: 18
|
||||
};
|
||||
|
||||
let setAsIsDelivered = `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, [
|
||||
stmt = new ParameterizedSQL(`UPDATE vn.client SET isCreatedAsServed = 1 WHERE id = ?`, [
|
||||
params.clientFk,
|
||||
]);
|
||||
stmts.push(stmt);
|
||||
|
||||
stmt = new ParameterizedSQL(`CALL vn.ticketCreateWithUser(?, ?, ?, ?, ?, ?, ?, ?, ?, @newTicketId)`, [
|
||||
params.clientFk,
|
||||
params.shipped,
|
||||
params.warehouseFk,
|
||||
|
@ -203,12 +236,19 @@ describe('ticket ticketCreateWithUser()', () => {
|
|||
params.agencyModeFk,
|
||||
params.routeFk,
|
||||
params.landed,
|
||||
params.userId,
|
||||
params.clientFk
|
||||
params.userId
|
||||
]);
|
||||
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