Skip to content

Commit

Permalink
Grant details close date explanation, step 2 (#2651)
Browse files Browse the repository at this point in the history
* Step 2: Update close_date_explanation when receiving ingest messages

* Add grants-ingest tests
  • Loading branch information
jeffsmohan authored Feb 25, 2024
1 parent d881051 commit a23e935
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 18 deletions.
74 changes: 56 additions & 18 deletions packages/server/__tests__/lib/grants-ingest.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,31 @@ describe('processMessages', async () => {
let knexStub;
let sqsStub;

const createBaseGrantEvent = () => ({
opportunity: {
id: '1',
number: 'for-some-reason-not-a-number',
title: 'Great opportunity',
description: 'Here is a description of this cool grant',
milestones: {
post_date: '2023-06-05',
close: {
date: '2024-01-02',
explanation: 'Test explanation',
},
},
category: { code: 'O', name: 'Other' },
},
agency: { code: 'ABC-ZYX-QMWN' },
award: { ceiling: '98765', floor: '12345' },
cost_sharing_or_matching_requirement: true,
cfda_numbers: ['12.345'],
eligible_applicants: [
{ code: '00' }, { code: '01' }, { code: '02' }, { code: '03' },
],
revision: { id: 'a1' },
});

const serlializeGrantEvent = (newData = {}, prevData = {}) => {
const eventData = { detail: { versions: { new: newData, previous: prevData } } };
const newDataJSON = JSON.stringify(newData);
Expand Down Expand Up @@ -47,24 +72,7 @@ describe('processMessages', async () => {
it('should process messages successfully', async () => {
const messages = [
{
Body: serlializeGrantEvent({
opportunity: {
id: '1',
number: 'for-some-reason-not-a-number',
title: 'Great opportunity',
description: 'Here is a description of this cool grant',
milestones: { post_date: '2023-06-05', close: { date: '2024-01-02' } },
category: { code: 'O', name: 'Other' },
},
agency: { code: 'ABC-ZYX-QMWN' },
award: { ceiling: '98765', floor: '12345' },
cost_sharing_or_matching_requirement: true,
cfda_numbers: ['12.345'],
eligible_applicants: [
{ code: '00' }, { code: '01' }, { code: '02' }, { code: '03' },
],
revision: { id: 'a1' },
}),
Body: serlializeGrantEvent(createBaseGrantEvent()),
ReceiptHandle: 'receipt-handle-2',
},
{
Expand Down Expand Up @@ -213,6 +221,36 @@ describe('processMessages', async () => {
}));
});

it('should extract close_date_explanation when present', async () => {
const grantEvent = createBaseGrantEvent();
grantEvent.opportunity.milestones.close.explanation = 'Test explanation';
const messages = [{
Body: serlializeGrantEvent(grantEvent),
ReceiptHandle: 'receipt-handle-2',
}];

await processMessages(knexStub, sqsStub, queueUrl, messages);

sinon.assert.calledWith(knexQuery.insert, sinon.match({
close_date_explanation: 'Test explanation',
}));
});

it('should skip when close_date_explanation is missing', async () => {
const grantEvent = createBaseGrantEvent();
delete grantEvent.opportunity.milestones.close.explanation;
const messages = [{
Body: serlializeGrantEvent(grantEvent),
ReceiptHandle: 'receipt-handle-2',
}];

await processMessages(knexStub, sqsStub, queueUrl, messages);

sinon.assert.calledWith(knexQuery.insert, sinon.match({
close_date_explanation: undefined,
}));
});

it('should skip processing message when error parsing json', async () => {
const messages = [
{
Expand Down
1 change: 1 addition & 0 deletions packages/server/src/lib/grants-ingest.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ function mapSourceDataToGrant(source) {
grant.open_date = milestones.post_date;
grant.close_date = milestones.close && milestones.close.date
? milestones.close.date : '2100-01-01';
grant.close_date_explanation = milestones?.close?.explanation ?? undefined;
grant.archive_date = milestones.archive_date;
const today = moment().startOf('day');
if (milestones.archive_date && today.isSameOrAfter(moment(milestones.archive_date), 'date')) {
Expand Down

0 comments on commit a23e935

Please sign in to comment.