Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Grant details close date explanation, step 2 #2651

Merged
merged 3 commits into from
Feb 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading