Skip to content

Commit

Permalink
fix(data): add a check ensure service-public content (#2956)
Browse files Browse the repository at this point in the history
ensure content referenced in contribution are not missing
closes #2042
  • Loading branch information
lionelB authored Sep 17, 2020
1 parent f4d39d8 commit f6e9b6c
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 7 deletions.
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
const uniqBy = require("lodash.uniqby");

const filter = fiches => {
const filteredFiches = fiches.filter(fiche => {
const filter = (fiches) => {
const filteredFiches = fiches.filter((fiche) => {
const arianeIDs = fiche.children[0].children
.find(el => el.name === "FilDAriane")
.find((el) => el.name === "FilDAriane")
.children.reduce((ids, el) => {
if (el.name === "Niveau") ids.push(el.attributes.ID);
return ids;
}, []);

const matchFilDAriane = id => arianeIDs.includes(id);
const matchFilDAriane = (id) => arianeIDs.includes(id);

if (excludeFicheId.some(matchFilDAriane)) {
return false;
Expand All @@ -29,7 +29,7 @@ const filter = fiches => {
// Par défaut, on exclue
return false;
});
return uniqBy(filteredFiches, fiche => fiche.children[0].attributes.ID);
return uniqBy(filteredFiches, (fiche) => fiche.children[0].attributes.ID);
};

// Liste fournie par @jrduscher
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ const fullFiches = [].concat(
)
);

const getFichesSP = () =>
filter(fullFiches)
const getFichesSP = () => {
const fiches = filter(fullFiches)
.map(format)
.filter(Boolean)
.map(
Expand Down Expand Up @@ -71,4 +71,15 @@ const getFichesSP = () =>
}
);

contribFicheId.forEach((idFiche) => {
if (fiches.find(({ id }) => idFiche === id) === undefined) {
throw Error(
`[FICHE-SP] The ${idFiche} from service-public is embeded in a contribution and was not found`
);
}
});

return fiches;
};

module.exports = { getFichesSP };

0 comments on commit f6e9b6c

Please sign in to comment.