diff --git a/packages/server/__tests__/db/db.test.js b/packages/server/__tests__/db/db.test.js index 8835e3a44..360f30866 100644 --- a/packages/server/__tests__/db/db.test.js +++ b/packages/server/__tests__/db/db.test.js @@ -691,6 +691,22 @@ describe('db', () => { }); }); + context('getTotalInterestedGrantsByAgencies', () => { + it('returns total interested grants by agencies', async () => { + const agencyId = fixtures.users.staffUser.agency_id; + const result = await db.getTotalInterestedGrantsByAgencies(agencyId); + const agencyResult = result[0]; + expect(agencyResult.agency_id).to.equal(fixtures.agencies.accountancy.id); + expect(agencyResult.interested).to.equal('1'); + expect(agencyResult.rejections).to.equal('2'); + + expect(agencyResult.count).to.equal('4'); + expect(agencyResult.total_grant_money).to.equal('1506500'); + expect(agencyResult.total_interested_grant_money).to.equal('500000'); + expect(agencyResult.total_rejected_grant_money).to.equal('506500'); + }); + }); + context('createUser', () => { it('sets default email unsubuscribe when new users are created', async () => { const response = await db.createUser( diff --git a/packages/server/src/db/index.js b/packages/server/src/db/index.js index cd50450a3..e748547f1 100755 --- a/packages/server/src/db/index.js +++ b/packages/server/src/db/index.js @@ -1043,8 +1043,8 @@ async function getTotalInterestedGrantsByAgencies(agencyId) { knex.raw(`SUM(CASE WHEN status_code = 'Rejected' THEN 1 ELSE 0 END) rejections`), knex.raw(`SUM(CASE WHEN status_code = 'Interested' THEN 1 ELSE 0 END) interested`), knex.raw('SUM(award_ceiling::numeric) total_grant_money'), - knex.raw(`SUM(CASE WHEN status_code = 'Rejected' THEN award_ceiling::numeric ELSE 0 END) total_interested_grant_money`), - knex.raw(`SUM(CASE WHEN status_code = 'Interested' THEN award_ceiling::numeric ELSE 0 END) total_rejected_grant_money`)) + knex.raw(`SUM(CASE WHEN status_code = 'Interested' THEN award_ceiling::numeric ELSE 0 END) total_interested_grant_money`), + knex.raw(`SUM(CASE WHEN status_code = 'Rejected' THEN award_ceiling::numeric ELSE 0 END) total_rejected_grant_money`)) .join(TABLES.agencies, `${TABLES.grants_interested}.agency_id`, `${TABLES.agencies}.id`) .join(TABLES.interested_codes, `${TABLES.grants_interested}.interested_code_id`, `${TABLES.interested_codes}.id`) .join(TABLES.grants, `${TABLES.grants_interested}.grant_id`, `${TABLES.grants}.grant_id`)