-
Notifications
You must be signed in to change notification settings - Fork 9
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
DNM: Integration form engine 2 #2273
base: main
Are you sure you want to change the base?
Changes from 3 commits
01edd06
fd22547
49ce1af
0cec642
4d7dc20
52edb57
b64c733
62fdaab
ee1a69f
9a6014e
66f5048
e3d84e6
a314931
3633329
628f6cb
0166a12
02d5d12
1d80dde
a0310be
00433c4
56aee27
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
/* eslint-disable @department-of-veterans-affairs/axe-check-required */ | ||
|
||
import { expect } from 'chai'; | ||
import { DATA_FILES } from './config'; | ||
|
||
describe('config', () => { | ||
describe('DATA_FILES', () => { | ||
it('includes Digital Forms', () => { | ||
expect( | ||
DATA_FILES.filter(dataFile => dataFile.description === 'Digital Forms') | ||
.length, | ||
).to.eq(1); | ||
}); | ||
}); | ||
}); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
const nameAndDateOfBirth = require('./nameAndDateOfBirth.graphql'); | ||
|
||
/* | ||
* | ||
* The "Digital Form" Content Type in the VA.gov CMS | ||
* | ||
*/ | ||
module.exports = ` | ||
${nameAndDateOfBirth} | ||
|
||
fragment digitalForm on NodeDigitalForm { | ||
nid | ||
entityLabel | ||
fieldVaFormNumber | ||
fieldOmbNumber | ||
fieldRespondentBurden | ||
fieldExpirationDate { | ||
value | ||
} | ||
fieldChapters { | ||
entity { | ||
entityId | ||
type { | ||
entity { | ||
entityId | ||
entityLabel | ||
} | ||
} | ||
...nameAndDateOfBirth | ||
} | ||
} | ||
} | ||
`; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
/* eslint-disable @department-of-veterans-affairs/axe-check-required */ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ESLint disabled here |
||
|
||
import { expect } from 'chai'; | ||
import digitalForm from './digitalForm.graphql'; | ||
|
||
describe('digitalForm fragment', () => { | ||
it('includes form fields', () => { | ||
expect(digitalForm).to.have.string('nid'); | ||
expect(digitalForm).to.have.string('entityLabel'); | ||
expect(digitalForm).to.have.string('fieldVaFormNumber'); | ||
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'); | ||
expect(digitalForm).to.have.string('...nameAndDateOfBirth'); | ||
}); | ||
}); | ||
}); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
/* | ||
* | ||
* The "Name and Date of Birth" Digital Form pattern. | ||
* | ||
* Pattern documentation: | ||
* https://design.va.gov/patterns/ask-users-for/names | ||
* | ||
*/ | ||
module.exports = ` | ||
fragment nameAndDateOfBirth on ParagraphDigitalFormNameAndDateOfBi { | ||
fieldTitle | ||
fieldIncludeDateOfBirth | ||
} | ||
`; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
/* eslint-disable @department-of-veterans-affairs/axe-check-required */ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ESLint disabled here |
||
|
||
import { expect } from 'chai'; | ||
import nameAndDateOfBirth from './nameAndDateOfBirth.graphql'; | ||
|
||
describe('nameAndDateOfBirth fragment', () => { | ||
it('includes fieldTitle', () => { | ||
expect(nameAndDateOfBirth).to.have.string('fieldTitle'); | ||
}); | ||
|
||
it('includes fieldIncludeDateOfBirth', () => { | ||
expect(nameAndDateOfBirth).to.have.string('fieldIncludeDateOfBirth'); | ||
}); | ||
}); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
const digitalForm = require('./fragments/digitalForm.graphql'); | ||
const { postProcessDigitalForm } = require('./postProcessDigitalForm'); | ||
|
||
const query = ` | ||
${digitalForm} | ||
|
||
query ($onlyPublishedContent: Boolean!) { | ||
nodeQuery( | ||
filter: { | ||
conditions: [ | ||
{ field: "status", value: "1", enabled: $onlyPublishedContent }, | ||
{ field: "type", value: "digital_form" } | ||
] | ||
} | ||
) { | ||
entities { | ||
... digitalForm | ||
} | ||
} | ||
} | ||
`; | ||
|
||
module.exports = { | ||
query, | ||
postProcess: postProcessDigitalForm, | ||
}; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
/* eslint-disable @department-of-veterans-affairs/axe-check-required */ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ESLint disabled here |
||
|
||
import { expect } from 'chai'; | ||
import { query, postProcess } from './index'; | ||
|
||
describe('digitalForm', () => { | ||
describe('query', () => { | ||
it('returns digital_form entities', () => { | ||
expect(query).to.have.string('digital_form'); | ||
}); | ||
it('imports the digitalForm fragment', () => { | ||
expect(query).to.have.string('fragment digitalForm'); | ||
expect(query).to.have.string('... digitalForm'); | ||
}); | ||
}); | ||
|
||
describe('postProcess', () => { | ||
it('imports postProcessDigitalForm', () => { | ||
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, | ||
}, | ||
}, | ||
], | ||
}, | ||
], | ||
}, | ||
}, | ||
}; | ||
|
||
expect(() => postProcess(queryResult)).to.not.throw(); | ||
}); | ||
}); | ||
}); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
const { logDrupal } = require('../../utilities-drupal'); | ||
|
||
const extractAdditionalFields = entity => { | ||
const additionalFields = {}; | ||
|
||
if (entity.type.entity.entityId === 'digital_form_name_and_date_of_bi') { | ||
additionalFields.includeDateOfBirth = entity.fieldIncludeDateOfBirth; | ||
} | ||
|
||
return additionalFields; | ||
}; | ||
const extractForms = resultObject => resultObject?.data?.nodeQuery?.entities; | ||
|
||
const formatDate = dateString => { | ||
const removeLeadingZero = s => s.replace(/^0+/, ''); | ||
const [year, month, day] = dateString.split('-'); | ||
return `${removeLeadingZero(month)}/${removeLeadingZero(day)}/${year}`; | ||
}; | ||
|
||
const normalizeChapter = ({ entity }) => { | ||
return { | ||
id: parseInt(entity.entityId, 10), | ||
chapterTitle: entity.fieldTitle, | ||
type: entity.type.entity.entityId, | ||
pageTitle: entity.type.entity.entityLabel, | ||
additionalFields: extractAdditionalFields(entity), | ||
}; | ||
}; | ||
|
||
const normalizeForm = (form, logger = logDrupal) => { | ||
try { | ||
return { | ||
cmsId: form.nid, | ||
formId: form.fieldVaFormNumber, | ||
title: form.entityLabel, | ||
ombInfo: { | ||
expDate: formatDate(form.fieldExpirationDate.value), | ||
ombNumber: form.fieldOmbNumber, | ||
resBurden: form.fieldRespondentBurden, | ||
}, | ||
chapters: form.fieldChapters.map(normalizeChapter), | ||
}; | ||
} catch (error) { | ||
logger(`There was an error with this form: ${error}`); | ||
return {}; | ||
} | ||
}; | ||
|
||
const postProcessDigitalForm = (queryResult, logger = logDrupal) => { | ||
// queryResult was already parsed by graphQLApiClient | ||
const forms = extractForms(queryResult); | ||
|
||
// will be turned into JSON by writeProcessedDataFilesToCache | ||
if (forms) { | ||
return forms.map(form => normalizeForm(form, logger)); | ||
} | ||
|
||
logger(`Malformed result query: ${queryResult}`); | ||
return []; | ||
}; | ||
|
||
module.exports.postProcessDigitalForm = postProcessDigitalForm; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ESLint disabled here