2019-02-13 07:34:40 +00:00
|
|
|
const app = require('vn-loopback/server/server');
|
2018-12-21 19:22:13 +00:00
|
|
|
const ParameterizedSQL = require('loopback-connector').ParameterizedSQL;
|
2018-09-28 11:55:21 +00:00
|
|
|
|
|
|
|
describe('logAddWithUser()', () => {
|
2019-01-02 12:33:30 +00:00
|
|
|
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);
|
|
|
|
});
|
|
|
|
});
|