2018-09-28 11:55:21 +00:00
|
|
|
const app = require(`../../../ticket/server/server`);
|
2018-10-14 15:09:05 +00:00
|
|
|
const server = require(`../../../loopback/server/server`);
|
|
|
|
const ParameterizedSQL = server.loopbackConnector.ParameterizedSQL;
|
2018-09-28 11:55:21 +00:00
|
|
|
|
|
|
|
describe('logAddWithUser()', () => {
|
|
|
|
it('should log any action taken by the user in a table ending in Log', async() => {
|
2018-10-14 15:09:05 +00:00
|
|
|
let stmts = [];
|
|
|
|
let stmt;
|
|
|
|
|
|
|
|
stmts.push('START TRANSACTION');
|
|
|
|
|
2018-09-28 11:55:21 +00:00
|
|
|
let params = {
|
|
|
|
ticketFk: 1,
|
|
|
|
userId: 9,
|
|
|
|
actionCode: 'update',
|
|
|
|
targetEntity: 'ticket',
|
|
|
|
description: 'we are testing stuff'
|
|
|
|
};
|
|
|
|
|
2018-10-14 15:09:05 +00:00
|
|
|
stmt = new ParameterizedSQL('CALL vn.logAddWithUser(?, ?, ?, ?, ?)', [
|
2018-09-28 11:55:21 +00:00
|
|
|
params.ticketFk,
|
|
|
|
params.userId,
|
|
|
|
params.actionCode,
|
|
|
|
params.targetEntity,
|
|
|
|
params.description
|
|
|
|
]);
|
2018-10-14 15:09:05 +00:00
|
|
|
stmts.push(stmt);
|
|
|
|
|
|
|
|
stmt = new ParameterizedSQL('SELECT * FROM vn.ticketLog WHERE description = ?', [
|
|
|
|
params.description
|
|
|
|
]);
|
|
|
|
let ticketLogIndex = stmts.push(stmt) - 1;
|
|
|
|
|
|
|
|
stmts.push('ROLLBACK');
|
|
|
|
|
|
|
|
let sql = ParameterizedSQL.join(stmts, ';');
|
|
|
|
let result = await app.models.Ticket.rawStmt(sql);
|
2018-09-28 11:55:21 +00:00
|
|
|
|
2018-10-14 15:09:05 +00:00
|
|
|
savedDescription = result[ticketLogIndex][0].description;
|
2018-09-28 11:55:21 +00:00
|
|
|
|
|
|
|
expect(savedDescription).toEqual(params.description);
|
|
|
|
});
|
|
|
|
});
|