1 /*jshint trailing:true, white:true, indent:2, strict:true, curly:true,
2 immed:true, eqeqeq:true, forin:true, latedef:true,
3 newcap:true, noarg:true, undef:true */
4 /*global XT:true, describe:true, it:true, require:true, __dirname:true, before:true */
6 var _ = require("underscore"),
7 assert = require('chai').assert,
8 path = require('path');
13 describe('The financialReport function', function () {
15 var loginData = require(path.join(__dirname, "../lib/login_data.js")).data,
16 datasource = require('../../../xtuple/node-datasource/lib/ext/datasource').dataSource,
17 config = require(path.join(__dirname, "../../node-datasource/config.js")),
18 creds = _.extend({}, config.databaseServer, {database: loginData.org}),
19 oldval = -98.76, // makes it easy to spot in test failures
21 freSql = "select financialreport(flhead_id, period_id, 'M', -1) as fr"
22 + " from flhead, period"
23 + " where flhead_name = 'Basic Balance Sheet'"
24 + " and current_date between period_start and period_end;",
25 valueSql = " select cast(sum(flrpt_ending) as text) as value"
27 + " join accnt on flrpt_accnt_id = accnt_id"
28 + " where accnt_descrip = 'Cash at eBank'"
31 this.timeout(10*1000); // the fre ain't speedy
33 it("should generate financial report data", function (done) {
34 datasource.query(freSql, creds, function (err, res) {
35 assert.equal(res.rowCount, 1);
36 assert.isTrue(res.rows[0].fr);
41 it("should get the starting net asset value", function (done) {
42 datasource.query(valueSql, creds, function (err, res) {
43 assert.equal(res.rowCount, 1);
44 oldval = Number(res.rows[0].value);
49 it("should insert a gl transaction", function (done) {
50 var sql = "select insertgltransaction('G/L', 'ST', 'FREtest',"
51 + " 'testing financialreport()', cr.accnt_id, dr.accnt_id,"
52 + " -1, " + changeval + ", period_end) AS result"
53 + " from accnt cr, accnt dr, period"
54 + " where cr.accnt_descrip = 'Cash at eBank'"
55 + " and dr.accnt_descrip = 'Deferred Revenue'"
56 + " and current_date between period_start and period_end;"
58 datasource.query(sql, creds, function (err, res) {
59 assert.equal(res.rowCount, 1);
60 assert.isTrue(res.rows[0].result > 0);
65 it("should regenerate financial report data", function (done) {
66 datasource.query(freSql, creds, function (err, res) {
67 assert.equal(res.rowCount, 1);
68 assert.isTrue(res.rows[0].fr);
73 it("should show a net asset value change", function (done) {
74 datasource.query(valueSql, creds, function (err, res) {
75 assert.equal(res.rowCount, 1);
76 var newval = Number(res.rows[0].value);
77 assert.closeTo(oldval - newval, changeval, 0.001);
82 after(function (done) {
83 done(); // is there anything to clean up?