Skip to content

Commit

Permalink
tests
Browse files Browse the repository at this point in the history
  • Loading branch information
masimons committed Sep 30, 2024
1 parent e0b63ab commit 88ba9d1
Show file tree
Hide file tree
Showing 3 changed files with 112 additions and 5 deletions.
64 changes: 64 additions & 0 deletions packages/server/__tests__/db/db.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -362,6 +362,16 @@ describe('db', () => {
const result = await db.getSingleGrantDetails({ grantId, tenantId: fixtures.users.staffUser.tenant_id });
expect(result).to.be.null;
});
it('shows forecasted grants', async () => {
grantId = '444819'
const result = await db.getSingleGrantDetails({ grantId, tenantId: fixtures.users.staffUser.tenant_id, showForecastedGrants: true });
expect(result.grant_id).to.eq('444819');
});
it('hides forecasted grants', async () => {
grantId = '444819'
const result = await db.getSingleGrantDetails({ grantId, tenantId: fixtures.users.staffUser.tenant_id, showForecastedGrants: false });
expect(result).to.be.null;
});
});

context('getGrantsAssignedAgency', () => {
Expand All @@ -378,6 +388,59 @@ describe('db', () => {
});
});

// context('getGrants', () => {
// it('gets forecasted grants', async () => {
// const result = await db.getGrants({
// showForecastedGrants: true,
// });
// const forecastedGrant = result.data.filter((grant) => grant.opportunity_status === 'forecasted');
// expect(forecastedGrant.length).to.equal(1);
// });
// });

context('getGrant', () => {
it('gets forecasted grant', async () => {
const result = await db.getGrant({ grantId: fixtures.grants.forecastedGrant.grant_id, showForecastedGrants: true });
expect(result.grant_id).to.equal(fixtures.grants.forecastedGrant.grant_id);
});

it('hides forecasted grant', async () => {
const result = await db.getGrant({ grantId: fixtures.grants.forecastedGrant.grant_id, showForecastedGrants: false });
console.log('marissasss');
console.log(result);
expect(result).to.be.null;
});
});

context('getGrantsNew', () => {
it('gets forecasted grants', async () => {
const result = await db.getGrantsNew(
{},
{ currentPage: 1, perPage: 10, isLengthAware: true },
{ orderBy: 'open_date', orderDesc: 'true' },
fixtures.tenants.SBA.id,
fixtures.agencies.accountancy.id,
false,
true,
);
const forecastedGrant = result.data.filter((grant) => grant.opportunity_status === 'forecasted');
expect(forecastedGrant.length).to.equal(1);
});
it('hides forecasted grants', async () => {
const result = await db.getGrantsNew(
{ bill: 'Infrastructure Investment and Jobs Act' },
{ currentPage: 1, perPage: 10, isLengthAware: true },
{ orderBy: 'open_date', orderDesc: 'true' },
fixtures.tenants.SBA.id,
fixtures.agencies.accountancy.id,
false,
false,
);
const forecastedGrant = result.data.filter((grant) => grant.opportunity_status === 'forecasted');
expect(forecastedGrant.length).to.equal(0);
});
});

context('getGrants with various filters', () => {
/*
filters: {
Expand Down Expand Up @@ -765,6 +828,7 @@ describe('db', () => {
expect(result.length).to.equal(1);
});
it('does not return forecasted grants', async () => {
// marissa
const newGrant = fixtures.grants.healthAide;
newGrant.grant_id = '444817';
newGrant.open_date = new Date('2022-06-21');
Expand Down
42 changes: 42 additions & 0 deletions packages/server/__tests__/db/seeds/fixtures.js
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,48 @@ const agencyEligibilityCodes = {
};

const grants = {
forecastedGrant: {
status: 'inbox',
grant_id: '444819',
grant_number: '29-468',
agency_code: 'NSF',
award_ceiling: '6500',
cost_sharing: 'No',
title: 'Forecasted Grant',
cfda_list: '47.050',
open_date: '2100-06-21',
close_date: '2200-11-03',
notes: 'auto-inserted by script',
search_terms: '[in title/desc]+',
reviewer_name: 'none',
opportunity_category: 'Discretionary',
description: 'Grant that is forecasted',
eligibility_codes: '25',
opportunity_status: 'forecasted',
raw_body_json: {
opportunity: {
id: '444819',
number: '29-468',
title: 'Forecasted Grant',
description: 'Grant that is forecasted',
category: { name: 'Discretionary' },
milestones: { post_date: '2100-06-21', close: { date: '2200-11-03' } },
},
agency: { code: 'NSF' },
cost_sharing_or_matching_requirement: false,
cfda_numbers: ['47.050'],
eligible_applicants: [{ code: '25' }],
funding_activity: { categories: [{ code: 'ISS', name: 'Income Security and Social Services' }] },
award: { ceiling: '6500' },
bill: 'Infrastructure Investment and Jobs Act (IIJA)',
funding_instrument_types: [{ code: 'CA' }, { code: 'G' }, { code: 'PC' }],
},
funding_instrument_codes: 'CA G PC',
bill: 'Infrastructure Investment and Jobs Act (IIJA)',
funding_activity_category_codes: 'ISS',
created_at: '2024-08-11 11:30:38.89828-07',
updated_at: '2024-08-11 12:30:39.531-07',
},
earFellowship: {
status: 'inbox',
grant_id: '335255',
Expand Down
11 changes: 6 additions & 5 deletions packages/server/src/db/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -350,6 +350,7 @@ async function getNewGrantsForAgency(agency) {
.modify(helpers.whereAgencyCriteriaMatch, agencyCriteria)
.modify((qb) => {
qb.where({ open_date: moment().subtract(1, 'day').format('YYYY-MM-DD') })
.whereNot({ opportunity_status: 'forecasted' });
})
.limit(3);

Expand Down Expand Up @@ -713,7 +714,7 @@ function addCsvData(qb) {
tenantId: number
agencyId: number
*/
async function getGrantsNew(filters, paginationParams, orderingParams, tenantId, agencyId, toCsv, showForecastedGrants=false) {
async function getGrantsNew(filters, paginationParams, orderingParams, tenantId, agencyId, toCsv, showForecastedGrants = false) {
const errors = validateSearchFilters(filters);
if (errors.length > 0) {
throw new Error(`Invalid filters: ${errors.join(', ')}`);
Expand Down Expand Up @@ -847,7 +848,7 @@ async function enhanceGrantData(tenantId, data) {
}

async function getGrants({
currentPage, perPage, tenantId, filters, orderBy, searchTerm, orderDesc, showForecastedGrants
currentPage, perPage, tenantId, filters, orderBy, searchTerm, orderDesc, showForecastedGrants,
} = {}) {
const data = await knex(TABLES.grants)
.modify((queryBuilder) => {
Expand Down Expand Up @@ -1019,8 +1020,8 @@ async function getGrant({ grantId, showForecastedGrants }) {
if (!showForecastedGrants) {
queryBuilder.whereNot({ opportunity_status: 'forecasted' });
}
})
return results[0];
});
return results.length ? results[0] : null;
}

async function getSingleGrantDetails({ grantId, tenantId, showForecastedGrants }) {
Expand All @@ -1031,7 +1032,7 @@ async function getSingleGrantDetails({ grantId, tenantId, showForecastedGrants }
if (!showForecastedGrants) {
queryBuilder.whereNot({ opportunity_status: 'forecasted' });
}
})
});
const enhancedResults = await enhanceGrantData(tenantId, results);
return enhancedResults.length ? enhancedResults[0] : null;
}
Expand Down

0 comments on commit 88ba9d1

Please sign in to comment.