salix/services/db/tests/vn/ticketCalculateClon.spec.js

67 lines
2.2 KiB
JavaScript

const app = require(`../../../ticket/server/server`);
describe('ticket ticketCalculateClon()', () => {
const today = new Date();
it('should add the ticket to the order containing the original ticket', async() => {
let query = `
START TRANSACTION;
CALL vn.ticketCreateWithUser(?, ?, ?, ?, ?, ?, ?, ?, ?, @result);
CALL vn.ticketCalculateClon(@result, ?);
SELECT * FROM vn.orderTicket WHERE ticketFk = @result;
SELECT * FROM tmp.agencyHourGetShipped;
ROLLBACK;`;
let result = await app.models.Ticket.rawSql(query, [
101,
today,
1,
442,
121,
23,
1,
today,
21,
11
]);
let expectedOrder = 11;
let newestTicketIdInFixtures = 21;
expect(result[3][0].orderFk).toEqual(expectedOrder);
expect(result[3][0].ticketFk).toBeGreaterThan(newestTicketIdInFixtures);
expect(result[4][0].warehouseFk).toEqual(1);
expect(result[4][0].shipped).toBeDefined();
expect(result[4][0].landed).toBeDefined();
});
it('should add the ticket to the order containing the original ticket and generate landed value if it was null', async() => {
let query = `
START TRANSACTION;
CALL vn.ticketCreateWithUser(?, ?, ?, ?, ?, ?, ?, ?, ?, @result);
CALL vn.ticketCalculateClon(@result, ?);
SELECT * FROM vn.orderTicket WHERE ticketFk = @result;
SELECT * FROM tmp.agencyHourGetShipped;
ROLLBACK;`;
let result = await app.models.Ticket.rawSql(query, [
101,
today,
1,
442,
121,
23,
1,
null,
21,
11
]);
let expectedOrder = 11;
let newestTicketIdInFixtures = 21;
expect(result[3][0].orderFk).toEqual(expectedOrder);
expect(result[3][0].ticketFk).toBeGreaterThan(newestTicketIdInFixtures);
expect(result[4][0].warehouseFk).toEqual(1);
expect(result[4][0].shipped).toBeDefined();
expect(result[4][0].landed).toBeDefined();
});
});