Skip to content

Commit

Permalink
Merge pull request #113 from mbayopanda/update_debtor_group
Browse files Browse the repository at this point in the history
Update debtor group for getting also the is_convention attribute
  • Loading branch information
jniles committed Feb 18, 2016
2 parents 0abaf0b + b7ffd84 commit 3f6a46c
Show file tree
Hide file tree
Showing 2 changed files with 141 additions and 10 deletions.
24 changes: 15 additions & 9 deletions server/controllers/finance/debtorGroups.js
Original file line number Diff line number Diff line change
Expand Up @@ -110,21 +110,27 @@ function getDetail(req, res, next) {
}

/**
* GET /debtor_groups/ => all debtor groups
* GET /debtor_groups/?locked={1|0} => only locked or not locked debtor groups
* GET /debtor_groups
* @param is_convention {boolean} (0 | 1) filter debtor groups in the convention column
* @param locked {boolean} (0 | 1) filters locked debtor groups
*
* @function getList
*
* @desc This function is responsible for retrieving details of a debtor group
* @description This function is responsible for retrieving list of debtor groups
*/
function getList(req, res, next) {
var query;
var query, criteria, conditions = [];

query = 'SELECT uuid, name, locked, account_id, is_convention FROM debitor_group ';

/** build the where clause criteria */
criteria = Object.keys(req.query).map(function (item) {
conditions = conditions.concat(item, req.query[item]);
return '?? = ?';
}).join(' AND ');

query = 'SELECT uuid, name, locked, account_id FROM debitor_group ';
query += (req.query.locked === '1') ? 'WHERE locked = 1' :
(req.query.locked === '0') ? 'WHERE locked = 0' : '';
query += (req.query.locked || req.query.is_convention) ? 'WHERE ' + criteria : '';

db.exec(query)
db.exec(query, conditions)
.then(function (rows) {
res.status(200).json(rows);
})
Expand Down
127 changes: 126 additions & 1 deletion server/test/api/debtorGroups.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,42 @@ describe('The /debtor_groups HTTP API ENDPOINT', function () {
apply_subsidies : 0
};

var conventionGroup = {
enterprise_id : 1,
uuid : uuid(),
name : 'Convention Debtor Group (Test)',
account_id : 3638,
location_id : '03a329b2-03fe-4f73-b40f-56a2870cc7e6',
phone : '0811838662',
email : '[email protected]',
note : 'Nouveau debtor group de test',
locked : 0,
max_credit : null,
is_convention : 1,
price_list_uuid : null,
apply_discounts : 0,
apply_billing_services : 0,
apply_subsidies : 0
};

var lockedConventionGroup = {
enterprise_id : 1,
uuid : uuid(),
name : 'Locked Convention Debtor Group (Test)',
account_id : 3638,
location_id : '03a329b2-03fe-4f73-b40f-56a2870cc7e6',
phone : '0811838662',
email : '[email protected]',
note : 'Nouveau debtor group de test',
locked : 1,
max_credit : null,
is_convention : 1,
price_list_uuid : null,
apply_discounts : 0,
apply_billing_services : 0,
apply_subsidies : 0
};

var invalidGroup = {
enterprise_id : 1,
name : 'Invalid Debtor Group (Test)',
Expand Down Expand Up @@ -83,6 +119,28 @@ describe('The /debtor_groups HTTP API ENDPOINT', function () {
.catch(helpers.handler);
});

it('POST /debtor_groups/ create a new debtor group (convention)', function () {
return agent.post('/debtor_groups/')
.send(conventionGroup)
.then(function (res) {
expect(res).to.have.status(201);
expect(res.body.id).to.exist;
expect(res.body.id).to.be.equal(conventionGroup.uuid);
})
.catch(helpers.handler);
});

it('POST /debtor_groups/ create a new debtor group (locked convention)', function () {
return agent.post('/debtor_groups/')
.send(lockedConventionGroup)
.then(function (res) {
expect(res).to.have.status(201);
expect(res.body.id).to.exist;
expect(res.body.id).to.be.equal(lockedConventionGroup.uuid);
})
.catch(helpers.handler);
});

it('POST /debtor_groups/ dont create when with missing data', function () {
return agent.post('/debtor_groups/')
.send(invalidGroup)
Expand All @@ -107,7 +165,7 @@ describe('The /debtor_groups HTTP API ENDPOINT', function () {
it('GET /debtor_groups/:uuid returns all details for a valid debtor group', function () {
return agent.get('/debtor_groups/' + debtorGroup.uuid)
.then(function (res) {
var expectedKeySubset = ['uuid', 'account_id', 'name', 'location_id'];
var expectedKeySubset = ['uuid', 'account_id', 'name', 'location_id', 'is_convention'];
expect(res).to.have.status(200);
expect(res.body).to.contain.all.keys(expectedKeySubset);
})
Expand All @@ -134,12 +192,79 @@ describe('The /debtor_groups HTTP API ENDPOINT', function () {
expect(res).to.have.status(200);
expect(res.body).to.not.be.empty;
expect(res.body).to.have.length(totalLockedGroup);
expect(res.body[0].locked).to.exist;
expect(res.body[0].locked).to.be.equal(1);
return agent.get('/debtor_groups/?locked=0');
})
.then(function (res) {
expect(res).to.have.status(200);
expect(res.body).to.not.be.empty;
expect(res.body).to.have.length(totalUnlockedGroup);
expect(res.body[0].locked).to.exist;
expect(res.body[0].locked).to.be.equal(0);
})
.catch(helpers.handler);
});

it('GET /debtor_groups/?is_convention={1|0} returns only conventions or not conventions debtor groups', function () {
var totalConvention = getTotal(allDebtorGroups, 'is_convention', 1);
var totalNotConvention = getTotal(allDebtorGroups, 'is_convention', 0);

return agent.get('/debtor_groups/?is_convention=1')
.then(function (res) {
expect(res).to.have.status(200);
expect(res.body).to.not.be.empty;
expect(res.body).to.have.length(totalConvention);
expect(res.body[0].is_convention).to.exist;
expect(res.body[0].is_convention).to.be.equal(1);
return agent.get('/debtor_groups/?is_convention=0');
})
.then(function (res) {
expect(res).to.have.status(200);
expect(res.body).to.not.be.empty;
expect(res.body).to.have.length(totalNotConvention);
expect(res.body[0].is_convention).to.exist;
expect(res.body[0].is_convention).to.be.equal(0);
})
.catch(helpers.handler);
});

it('GET /debtor_groups/?locked={1|0}&is_convention={1|0} returns either locked or convention debtor groups', function () {
return agent.get('/debtor_groups/?locked=1&is_convention=1')
.then(function (res) {
expect(res).to.have.status(200);
expect(res.body).to.not.be.empty;
expect(res.body[0].locked).to.exist;
expect(res.body[0].locked).to.be.equal(1);
expect(res.body[0].is_convention).to.exist;
expect(res.body[0].is_convention).to.be.equal(1);
return agent.get('/debtor_groups/?locked=1&is_convention=0');
})
.then(function (res) {
expect(res).to.have.status(200);
expect(res.body).to.not.be.empty;
expect(res.body[0].locked).to.exist;
expect(res.body[0].locked).to.be.equal(1);
expect(res.body[0].is_convention).to.exist;
expect(res.body[0].is_convention).to.be.equal(0);
return agent.get('/debtor_groups/?locked=0&is_convention=1');
})
.then(function (res) {
expect(res).to.have.status(200);
expect(res.body).to.not.be.empty;
expect(res.body[0].locked).to.exist;
expect(res.body[0].locked).to.be.equal(0);
expect(res.body[0].is_convention).to.exist;
expect(res.body[0].is_convention).to.be.equal(1);
return agent.get('/debtor_groups/?locked=0&is_convention=0');
})
.then(function (res) {
expect(res).to.have.status(200);
expect(res.body).to.not.be.empty;
expect(res.body[0].locked).to.exist;
expect(res.body[0].locked).to.be.equal(0);
expect(res.body[0].is_convention).to.exist;
expect(res.body[0].is_convention).to.be.equal(0);
})
.catch(helpers.handler);
});
Expand Down

0 comments on commit 3f6a46c

Please sign in to comment.