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

VATEAM-90733: Normalize OMB info fields #2252

Merged
merged 3 commits into from
Sep 12, 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
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@ module.exports = `
entityLabel
fieldVaFormNumber
fieldOmbNumber
fieldRespondentBurden
fieldExpirationDate {
value
}
fieldChapters {
entity {
entityId
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,15 @@ describe('digitalForm fragment', () => {
expect(digitalForm).to.have.string('nid');
expect(digitalForm).to.have.string('entityLabel');
expect(digitalForm).to.have.string('fieldVaFormNumber');
expect(digitalForm).to.have.string('fieldOmbNumber');
expect(digitalForm).to.have.string('fieldChapters');
});

it('include OMB info', () => {
expect(digitalForm).to.have.string('fieldOmbNumber');
expect(digitalForm).to.have.string('fieldRespondentBurden');
expect(digitalForm).to.have.string('fieldExpirationDate');
});

describe('chapter fragments', () => {
it('imports the nameAndDateOfBirth fragment', () => {
expect(digitalForm).to.have.string('fragment nameAndDateOfBirth');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,12 @@ const extractAdditionalFields = entity => {
};
const extractForms = resultObject => resultObject?.data?.nodeQuery?.entities;

const formatDate = dateString => {
const removeLeadingZero = s => s.replace(/^0+/, '');
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will remove multiple leading zeroes, should they be present, which I think is noteworthy but also should be N/A. In fact, if it somehow were the case that a string came over with multiple leading zeroes, I think we would want them all removed, so this is great. Makes me wonder if removeLeadingZeroes is a better name, but that feels pedantic and possibly confusing given the context.

Nicely done!

const [year, month, day] = dateString.split('-');
return `${removeLeadingZero(month)}/${removeLeadingZero(day)}/${year}`;
};

const normalizeChapter = ({ entity }) => {
return {
id: parseInt(entity.entityId, 10),
Expand All @@ -27,7 +33,11 @@ const normalizeForm = (form, logger = logDrupal) => {
cmsId: form.nid,
formId: form.fieldVaFormNumber,
title: form.entityLabel,
ombNumber: form.fieldOmbNumber,
ombInfo: {
expDate: formatDate(form.fieldExpirationDate.value),
ombNumber: form.fieldOmbNumber,
resBurden: form.fieldRespondentBurden,
},
chapters: form.fieldChapters.map(normalizeChapter),
};
} catch (error) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,67 +6,78 @@ import sinon from 'sinon';
const { postProcessDigitalForm } = require('./postProcessDigitalForm');

describe('postProcessDigitalForm', () => {
const oneStepEntity = {
nid: 71002,
entityLabel: 'Form with One Step',
fieldVaFormNumber: '11111',
fieldOmbNumber: '1111-1111',
fieldRespondentBurden: 48,
fieldExpirationDate: {
value: '2025-06-11',
},
fieldChapters: [
{
entity: {
entityId: '157904',
type: {
entity: {
entityId: 'digital_form_name_and_date_of_bi',
entityLabel: 'Name and Date of Birth',
},
},
fieldTitle: 'The Only Step',
fieldIncludeDateOfBirth: true,
},
},
],
};

context('with a well-formed query result', () => {
const expDate = '2027-01-29';

const twoStepEntity = {
nid: 71004,
entityLabel: 'Form with Two Steps',
fieldVaFormNumber: '222222',
fieldOmbNumber: '1212-1212',
fieldRespondentBurden: 30,
fieldExpirationDate: {
value: expDate,
},
fieldChapters: [
{
entity: {
entityId: '157906',
type: {
entity: {
entityId: 'digital_form_name_and_date_of_bi',
entityLabel: 'Name and Date of Birth',
},
},
fieldTitle: 'First Step',
fieldIncludeDateOfBirth: true,
},
},
{
entity: {
entityId: '157907',
type: {
entity: {
entityId: 'digital_form_name_and_date_of_bi',
entityLabel: 'Name and Date of Birth',
},
},
fieldTitle: 'Second Step',
fieldIncludeDateOfBirth: false,
},
},
],
};

const queryResult = {
data: {
nodeQuery: {
entities: [
{
nid: 71002,
entityLabel: 'Form with One Step',
fieldVaFormNumber: '11111',
fieldOmbNumber: '1111-1111',
fieldChapters: [
{
entity: {
entityId: '157904',
type: {
entity: {
entityId: 'digital_form_name_and_date_of_bi',
entityLabel: 'Name and Date of Birth',
},
},
fieldTitle: 'The Only Step',
fieldIncludeDateOfBirth: true,
},
},
],
},
{
nid: 71004,
entityLabel: 'Form with Two Steps',
fieldVaFormNumber: '222222',
fieldOmbNumber: '1212-1212',
fieldChapters: [
{
entity: {
entityId: '157906',
type: {
entity: {
entityId: 'digital_form_name_and_date_of_bi',
entityLabel: 'Name and Date of Birth',
},
},
fieldTitle: 'First Step',
fieldIncludeDateOfBirth: true,
},
},
{
entity: {
entityId: '157907',
type: {
entity: {
entityId: 'digital_form_name_and_date_of_bi',
entityLabel: 'Name and Date of Birth',
},
},
fieldTitle: 'Second Step',
fieldIncludeDateOfBirth: false,
},
},
],
},
],
entities: [oneStepEntity, twoStepEntity],
},
},
};
Expand All @@ -84,7 +95,6 @@ describe('postProcessDigitalForm', () => {
expect(testForm.cmsId).to.eq(71004);
expect(testForm.formId).to.eq('222222');
expect(testForm.title).to.eq('Form with Two Steps');
expect(testForm.ombNumber).to.eq('1212-1212');
expect(testForm.chapters.length).to.eq(2);
expect(testChapter.id).to.eq(157907);
expect(testChapter.chapterTitle).to.eq('Second Step');
Expand All @@ -93,6 +103,16 @@ describe('postProcessDigitalForm', () => {
expect(Object.keys(testChapter.additionalFields).length).to.eq(1);
});

it('includes an OMB info object', () => {
const { ombInfo } = processedResult[1];
// expDate is 2027-01-29
const formattedDate = '1/29/2027';

expect(ombInfo.ombNumber).to.eq(twoStepEntity.fieldOmbNumber);
expect(ombInfo.expDate).to.eq(formattedDate);
expect(ombInfo.resBurden).to.eq(twoStepEntity.fieldRespondentBurden);
});

context('with a Name and Date of Birth step', () => {
it('includes the appropriate fields', () => {
const { additionalFields } = processedResult[1].chapters[1];
Expand Down Expand Up @@ -134,27 +154,7 @@ describe('postProcessDigitalForm', () => {
data: {
nodeQuery: {
entities: [
{
nid: 71002,
entityLabel: 'Form with One Step',
fieldVaFormNumber: '11111',
fieldOmbNumber: '1111-1111',
fieldChapters: [
{
entity: {
entityId: '157904',
type: {
entity: {
entityId: 'digital_form_name_and_date_of_bi',
entityLabel: 'Name and Date of Birth',
},
},
fieldTitle: 'The Only Step',
fieldIncludeDateOfBirth: true,
},
},
],
},
oneStepEntity,
{
nid: '71004',
entityLabel: 'This form has problems',
Expand Down
Loading