Skip to content

Commit

Permalink
test(cashflow): implement integration tests
Browse files Browse the repository at this point in the history
This commit implements integration tests for the cashflow by services
report route.  In doing so, it caught a bug that would throw an SQL
error if there were not values to select.  This has been rectified.

Closes #165.
  • Loading branch information
Jonathan Niles authored and sfount committed Feb 1, 2017
1 parent 78620a9 commit 6d9cb88
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ CashflowByServiceConfigController.$inject = [
* CashflowByService
*
* @description
* This controller is responsible of Aged Debtors report, that report include
* all incomes minus all depenses
* This controller is responsible for setting up the Cashflow by Service report
* in the standard report controller.
*/
function CashflowByServiceConfigController($state, $http, ModalInstance, Notify, Languages, reportDetails) {
var vm = this;
Expand Down
16 changes: 14 additions & 2 deletions server/controllers/finance/reports/cashflow/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -599,6 +599,7 @@ function reportByService(req, res, next) {
}

const data = {};
let emptyCashValues = false;

// get the cash flow data
const cashflowByServiceSql = `
Expand Down Expand Up @@ -637,6 +638,12 @@ function reportByService(req, res, next) {
.then(rows => {
data.rows = rows;

// return an empty array if no rows
if (!rows.length) {
emptyCashValues = true;
return [];
}

// get a list of unique service ids
let serviceIds = rows
.map(row => row.service_id)
Expand All @@ -647,6 +654,11 @@ function reportByService(req, res, next) {
})
.then(services => {

// if nothing matches the selection criteria, continue with nothing
if (emptyCashValues) {
return [];
}

let rows = data.rows;
let uuids = rows.map(row => db.bid(row.uuid));
delete data.rows;
Expand All @@ -656,10 +668,10 @@ function reportByService(req, res, next) {

let xAxis = data.services.length;

// file the matrix with nulls except the correct columns
// fill the matrix with nulls except the correct columns
let matrix = rows.map(row => {

// fill with each service + two lines for cash payment identifier and patient name
// fill line with each service + two lines for cash payment identifier and patient name
let line = _.fill(Array(xAxis + 2), null);

// each line has the cash payment reference and then the patient name
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@
</td>
{{/each}}
</tr>
{{else}}
{{> emptyTable columns=2}}
{{/each}}
</tbody>

Expand Down
4 changes: 4 additions & 0 deletions test/integration/reports/finance/cashflowByService.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
const RenderingTests = require('../rendering');
const target = '/reports/finance/cashflow/services';
const params = { dateFrom : new Date('2010-01-01'), dateTo: new Date() };
describe(`(${target}) CashFlow By Service Report`, RenderingTests(target, null, params));
2 changes: 0 additions & 2 deletions test/integration/services.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,6 @@ describe('(/services) The Service API', function () {
.catch(helpers.handler);
});


it('PUT /services/:id updates the newly added services', function () {
var updateInfo = {name : 'other'};
return agent.put('/services/'+ newService.id)
Expand All @@ -97,7 +96,6 @@ describe('(/services) The Service API', function () {
.catch(helpers.handler);
});


it('PUT /services/:id refuses to update a service with a string as profit_center_id', function () {
return agent.put('/services/' + newService.id)
.send(wrongUpdateService)
Expand Down

0 comments on commit 6d9cb88

Please sign in to comment.