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

DNM: Integration form engine 2 #2273

Draft
wants to merge 21 commits into
base: main
Choose a base branch
from
Draft
Changes from 1 commit
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
01edd06
VATEAM-87714: Add KISS configuration for Digital Forms (#2213)
derekhouck Aug 6, 2024
fd22547
VATEAM-88634: Create a normalization layer for Digital Forms (#2215)
derekhouck Aug 10, 2024
49ce1af
Add OMB info to Digital Form GraphQL query
derekhouck Aug 29, 2024
0cec642
Normalize OMB info
derekhouck Aug 29, 2024
4d7dc20
Remove Date object from formatDate
derekhouck Sep 6, 2024
52edb57
VATEAM-90733: Normalize OMB info fields (#2252)
derekhouck Sep 12, 2024
b64c733
Add Identification Information fragment
derekhouck Sep 16, 2024
62fdaab
Import identificationInformation fragment into digitalForm fragment
derekhouck Sep 16, 2024
ee1a69f
Extract Identification Information fields
derekhouck Sep 16, 2024
9a6014e
Fix imports
derekhouck Sep 16, 2024
66f5048
VATEAM-87714: Add KISS configuration for Digital Forms (#2213)
derekhouck Aug 6, 2024
e3d84e6
VATEAM-88634: Create a normalization layer for Digital Forms (#2215)
derekhouck Aug 10, 2024
a314931
Merge branch 'main' into integration-form-engine-2
derekhouck Oct 2, 2024
3633329
Merge branch '90733-normalize-omb-info-section' into integration-form…
derekhouck Oct 2, 2024
628f6cb
Merge branch '91741-normalize-identification-information' into integr…
derekhouck Oct 2, 2024
0166a12
VATEAM-92265: Normalize Address Digital Form pattern output (#2301)
derekhouck Oct 4, 2024
02d5d12
VATEAM-94290: Remove "Digital Form:" from content-build output (#2304)
derekhouck Oct 9, 2024
1d80dde
Merge branch 'main' into integration-form-engine-2
derekhouck Oct 16, 2024
a0310be
VATEAM-93401: Normalize Phone and Email Digital Form pattern output (…
derekhouck Oct 16, 2024
00433c4
VATEAM-94709: Normalize Your Personal Information chapter (#2338)
derekhouck Nov 4, 2024
56aee27
VATEAM-93614: Normalize List and Loop pattern output (#2350)
derekhouck Nov 12, 2024
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
Prev Previous commit
Next Next commit
VATEAM-88634: Create a normalization layer for Digital Forms (#2215)
* Add normalizeForms step to postProcessDigitalForm

* Add subtitle to normalized form

* Add OMB Number to normalized form

* Normalize chapters for each form

* Add additional fields for Name and Date of Birth step

* Fix import spec

* Remove redundant JSON parsing

* Remove JSON conversion from returned value

* Add formID and rename id to cmsId

* Remove subTitle

* Refactor normalizeForms method

* Refactor normalizeChapters

* Defend against malformed query responses

* Remove unused import
  • Loading branch information
derekhouck authored and ryguyk committed Sep 12, 2024
commit fd225479c646aeb2d04abaa8bf15bcd90e78f265
Original file line number Diff line number Diff line change
@@ -16,7 +16,37 @@ describe('digitalForm', () => {

describe('postProcess', () => {
it('imports postProcessDigitalForm', () => {
expect(() => postProcess('test result')).to.not.throw();
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
@@ -1,3 +1,52 @@
const postProcessDigitalForm = queryResult => queryResult;
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 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,
ombNumber: form.fieldOmbNumber,
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;
Original file line number Diff line number Diff line change
@@ -1,12 +1,180 @@
/* eslint-disable @department-of-veterans-affairs/axe-check-required */
Copy link
Collaborator

Choose a reason for hiding this comment

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

ESLint disabled here


import { expect } from 'chai';
import sinon from 'sinon';

const { postProcessDigitalForm } = require('./postProcessDigitalForm');

describe('postProcessDigitalForm', () => {
it('returns queryResult with no changes', () => {
const queryResult = { data: { form: {} } };
expect(postProcessDigitalForm(queryResult)).to.eq(queryResult);
context('with a well-formed query result', () => {
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,
},
},
],
},
],
},
},
};
let processedResult;

beforeEach(() => {
processedResult = postProcessDigitalForm(queryResult);
});

it('returns a normalized JSON object', () => {
const testForm = processedResult[1];
const testChapter = testForm.chapters[1];

expect(processedResult.length).to.eq(2);
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');
expect(testChapter.type).to.eq('digital_form_name_and_date_of_bi');
expect(testChapter.pageTitle).to.eq('Name and Date of Birth');
expect(Object.keys(testChapter.additionalFields).length).to.eq(1);
});

context('with a Name and Date of Birth step', () => {
it('includes the appropriate fields', () => {
const { additionalFields } = processedResult[1].chapters[1];

expect(additionalFields.includeDateOfBirth).to.eq(false);
});
});
});

context('with a malformed query result', () => {
let queryResult;
let processedResult;
let logger;

beforeEach(() => {
logger = sinon.spy();
});

context('when the entire query is bad', () => {
beforeEach(() => {
queryResult = {
wrongKey: 'oops! bad data!',
};
processedResult = postProcessDigitalForm(queryResult, logger);
});

it('logs the error', () => {
expect(logger.calledOnce).to.eq(true);
});

it('returns an empty array', () => {
expect(processedResult.length).to.eq(0);
});
});

context('when only one form is malformed', () => {
beforeEach(() => {
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: 'This form has problems',
fieldVaFormNumber: 222222,
fieldChapters: 'no chapters',
},
],
},
},
};
processedResult = postProcessDigitalForm(queryResult, logger);
});

it('logs the error', () => {
expect(logger.calledOnce).to.eq(true);
});

it('returns the other forms', () => {
expect(processedResult[0].cmsId).to.eq(71002);
});
});
});
});
Loading