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

EAR-2352 - Piping into the introduction page #213

Merged
merged 7 commits into from
May 22, 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
13 changes: 5 additions & 8 deletions src/eq_schema/builders/valueSource/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,17 +34,14 @@ const getValueSource = (ctx, sourceId) => {
};
};

const getSupplementaryValueSource = (ctx, sourceId) => {
const suplementaryField = find(
flatMap(ctx.questionnaireJson.supplementaryData.data, "schemaFields"),
{ id: sourceId }
);
const getSupplementaryValueSource = (supplementaryField) => {
const source = {
source: "supplementary_data",
identifier: suplementaryField.identifier,
identifier: supplementaryField.identifier,
};
if (suplementaryField.selector) {
source.selectors = [suplementaryField.selector];

if (supplementaryField.selector) {
source.selectors = [supplementaryField.selector];
}

return source;
Expand Down
4 changes: 0 additions & 4 deletions src/eq_schema/schema/Questionnaire/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -104,10 +104,6 @@ class Questionnaire {
...this.sections,
];

if (ctx.questionnaireJson.sections[0].repeatingSection) {
newSections[0].repeat = newSections[1].repeat;
}

this.sections = newSections;
}

Expand Down
37 changes: 36 additions & 1 deletion src/utils/convertPipes/PlaceholderObjectBuilder.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ const {
getValueSource,
getSupplementaryValueSource,
} = require("../../eq_schema/builders/valueSource");
const { flatMap, find } = require("lodash");

const DATE_FORMAT_MAP = {
"dd/mm/yyyy": "d MMMM yyyy",
Expand Down Expand Up @@ -74,7 +75,41 @@ const placeholderObjectBuilder = (
}

if (source === "supplementary") {
valueSource = getSupplementaryValueSource(ctx, identifier);
const supplementaryField = find(
flatMap(ctx.questionnaireJson.supplementaryData.data, "schemaFields"),
{ id: identifier }
);

let isListSupplementaryData = false;
ctx.questionnaireJson.supplementaryData.data.forEach((dataObj) => {
if (
dataObj.listName !== "" &&
dataObj.listName === supplementaryField.identifier
) {
isListSupplementaryData = true;
}
});

if (isListSupplementaryData) {
return {
placeholder: removeDash(placeholderName),
transforms: [
{
transform: "concatenate_list",
arguments: {
list_to_concatenate: {
identifier: supplementaryField.identifier,
source: "supplementary_data",
selectors: [supplementaryField.selector],
},
delimiter: ", ",
},
},
],
};
} else {
valueSource = getSupplementaryValueSource(supplementaryField);
}
}

if (conditionalTradAs && placeholderName === "trad_as") {
Expand Down
126 changes: 125 additions & 1 deletion src/utils/convertPipes/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,20 @@ const createPlaceholders = ({ placeholder, identifier, source }, extra) => ({
...extra,
});

const createSupplementaryPlaceholders = ({
placeholder,
identifier,
source,
selectors,
}) => ({
placeholder,
value: {
identifier: identifier,
source,
selectors: selectors,
},
});

const createTransformation = (
{ placeholder, identifier, source, argument, transform },
extra
Expand Down Expand Up @@ -49,6 +63,53 @@ const createWrapper = (text, ...args) => ({
placeholders: [...args],
});

const supplementaryData = {
surveyId: "221",
data: [
{
schemaFields: [
{
identifier: "employer_paye",
description:
"The tax office employer reference. This will be between 1 and 10 characters, which can be letters and numbers.",
type: "string",
example: "AB456",
selector: "reference",
id: "c5f64732-3bb2-40ba-8b0d-fc3b7e22c834",
},
],
id: "f0d7091a-44be-4c88-9d78-a807aa7509ec",
listName: "",
},
{
schemaFields: [
{
identifier: "local-units",
description: "Name of the local unit",
type: "string",
example: "STUBBS BUILDING PRODUCTS LTD",
selector: "name",
id: "673a30af-5197-4d2a-be0c-e5795a998491",
},
{
identifier: "local-units",
description: "The “trading as” name for the local unit",
type: "string",
example: "STUBBS PRODUCTS",
selector: "trading_name",
id: "af2ff1a6-fc5d-419f-9538-0d052a5e6728",
},
],
id: "6e901afa-473a-4704-8bbd-de054569379c",
listName: "local-units",
},
],
sdsDateCreated: "2023-12-15T11:21:34Z",
sdsGuid: "621c954b-5523-4eda-a3eb-f18bebd20b8d",
sdsVersion: "1",
id: "b6c84aee-ea11-41e6-8be8-5715b066d297",
};

const createContext = (metadata = []) => ({
questionnaireJson: {
metadata,
Expand Down Expand Up @@ -112,13 +173,14 @@ const createContext = (metadata = []) => ({
id: "calc1",
pageType: "CalculatedSummaryPage",
type: "Number",
totalTitle:"blockcalc1"
totalTitle: "blockcalc1",
},
],
},
],
},
],
supplementaryData: supplementaryData,
},
});

Expand Down Expand Up @@ -423,5 +485,67 @@ describe("convertPipes", () => {
);
});
});

describe("format supplementary data piping", () => {
it("should format piping supplementary data of simple type", () => {
const html = createPipe({
id: "c5f64732-3bb2-40ba-8b0d-fc3b7e22c834",
pipeType: "supplementary",
});
const supplementaryData = [
{
id: "c5f64732-3bb2-40ba-8b0d-fc3b7e22c834",
key: "supplementary",
type: "string",
},
];

expect(convertPipes(createContext(supplementaryData))(html)).toEqual(
createWrapper(
"{employerpaye_reference}",
createSupplementaryPlaceholders({
placeholder: "employerpaye_reference",
identifier: "employer_paye",
source: "supplementary_data",
selectors: ["reference"],
})
)
);
});

it("should format piping supplementary data of list type", () => {
const html = createPipe({
id: "673a30af-5197-4d2a-be0c-e5795a998491",
pipeType: "supplementary",
});
const supplementaryData = [
{
id: "673a30af-5197-4d2a-be0c-e5795a998491",
key: "supplementary",
type: "string",
},
];

expect(convertPipes(createContext(supplementaryData))(html)).toEqual(
createWrapper(
"{localunits_name}",
createAlternateTransformation(
{
placeholder: "localunits_name",
transform: "concatenate_list",
},
{
list_to_concatenate: {
identifier: "local-units",
source: "supplementary_data",
selectors: ["name"],
},
delimiter: ", ",
}
)
)
);
});
});
});
});
Loading