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

43 lines
1.3 KiB
JavaScript
Raw Normal View History

2018-12-21 11:50:28 +00:00
const app = require(`${serviceRoot}/server/server`);
const ParameterizedSQL = require('loopback-connector').ParameterizedSQL;
describe('logAddWithUser()', () => {
2018-11-21 10:50:30 +00:00
it('should log any action taken by the user in a table ending in Log', async () => {
let stmts = [];
let stmt;
stmts.push('START TRANSACTION');
let params = {
ticketFk: 1,
userId: 9,
actionCode: 'update',
targetEntity: 'ticket',
description: 'we are testing stuff'
};
stmt = new ParameterizedSQL('CALL vn.logAddWithUser(?, ?, ?, ?, ?)', [
params.ticketFk,
params.userId,
params.actionCode,
params.targetEntity,
params.description
]);
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);
savedDescription = result[ticketLogIndex][0].description;
expect(savedDescription).toEqual(params.description);
});
});