-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Loading status checks…
feat(page CC): affichage seulement des liens vers les contribs sur le…
…s pages CC (#1404)
1 parent
305cb46
commit 10a11e9
Showing
9 changed files
with
437 additions
and
124 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
273 changes: 273 additions & 0 deletions
273
targets/export-elasticsearch/src/ingester/__fixtures__/data.ts
Large diffs are not rendered by default.
Oops, something went wrong.
47 changes: 47 additions & 0 deletions
47
targets/export-elasticsearch/src/ingester/agreements/__tests__/generate.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
import { generateAgreements } from "../index"; | ||
import { CCN, contribs } from "../../__fixtures__/data"; | ||
|
||
jest.mock("@shared/utils"); | ||
jest.mock("../getAgreementsArticlesByTheme"); | ||
|
||
describe("generateAgreements", () => { | ||
it("should map and group contributions", async () => { | ||
// @ts-ignore | ||
const pagesCCs = await generateAgreements(CCN, contribs); | ||
|
||
expect(pagesCCs.length).toEqual(2); | ||
expect(pagesCCs[0].slug).toEqual( | ||
"1875-veterinaires-personnel-salarie-des-cabinets-et-cliniques-veterinaires" | ||
); | ||
expect(pagesCCs[0].answers.length).toEqual(0); | ||
|
||
expect(pagesCCs[1].slug).toEqual( | ||
"5571-convention-dentreprise-fondation-dauteuil" | ||
); | ||
expect(pagesCCs[1].answers).toEqual([ | ||
{ | ||
answers: [ | ||
{ | ||
questionIndex: 44, | ||
slug: "1486-quelle-est-la-duree-du-conge-de-maternite", | ||
theme: "Congés et repos", | ||
question: "Quelle est la durée du congé de maternité ?", | ||
}, | ||
], | ||
theme: "Congés et repos", | ||
}, | ||
{ | ||
answers: [ | ||
{ | ||
questionIndex: 47, | ||
slug: "1351-en-cas-de-maladie-le-salarie-a-t-il-droit-a-une-garantie-demploi", | ||
theme: "Santé, sécurité et conditions de travail", | ||
question: | ||
"En cas de maladie, le salarié a-t-il droit à une garantie d’emploi ?", | ||
}, | ||
], | ||
theme: "Santé, sécurité et conditions de travail", | ||
}, | ||
]); | ||
}); | ||
}); |
67 changes: 0 additions & 67 deletions
67
targets/export-elasticsearch/src/ingester/agreements/__tests__/getInfoMessage.test.ts
This file was deleted.
Oops, something went wrong.
63 changes: 63 additions & 0 deletions
63
targets/export-elasticsearch/src/ingester/agreements/__tests__/groupByTheme.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
import { groupByTheme } from "../groupByTheme"; | ||
import { ExportAnswer } from "@socialgouv/cdtn-types"; | ||
|
||
describe("contributionsByTheme", () => { | ||
it("should throw if a contrib has no theme", () => { | ||
expect(() => { | ||
groupByTheme([ | ||
{ slug: "hello", questionIndex: 1, question: "contrib" }, | ||
]); | ||
}).toThrow("Contribution [1] - hello has no theme."); | ||
}); | ||
|
||
it("returns the first breadcrumb label", () => { | ||
const data: ExportAnswer[] = [ | ||
{ slug: "contrib-1", questionIndex: 1, theme: "A", question: "contrib" }, | ||
{ slug: "contrib-1", questionIndex: 1, theme: "C", question: "contrib" }, | ||
{ slug: "contrib-1", questionIndex: 1, theme: "B", question: "contrib" }, | ||
{ slug: "contrib-2", questionIndex: 2, theme: "A", question: "contrib" }, | ||
]; | ||
|
||
expect(groupByTheme(data)).toEqual([ | ||
{ | ||
"answers": [ | ||
{ | ||
"questionIndex": 1, | ||
"slug": "contrib-1", | ||
"theme": "A", | ||
"question": "contrib" | ||
}, | ||
{ | ||
"questionIndex": 2, | ||
"slug": "contrib-2", | ||
"theme": "A", | ||
"question": "contrib" | ||
} | ||
], | ||
"theme": "A" | ||
}, | ||
{ | ||
"answers": [ | ||
{ | ||
"questionIndex": 1, | ||
"slug": "contrib-1", | ||
"theme": "B", | ||
"question": "contrib" | ||
} | ||
], | ||
"theme": "B" | ||
}, | ||
{ | ||
"answers": [ | ||
{ | ||
"questionIndex": 1, | ||
"slug": "contrib-1", | ||
"theme": "C", | ||
"question": "contrib" | ||
} | ||
], | ||
"theme": "C" | ||
} | ||
]); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
27 changes: 0 additions & 27 deletions
27
targets/export-elasticsearch/src/ingester/agreements/getInfoMessage.ts
This file was deleted.
Oops, something went wrong.
30 changes: 30 additions & 0 deletions
30
targets/export-elasticsearch/src/ingester/agreements/groupByTheme.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import { AnswerByTheme, ExportAnswer } from "@socialgouv/cdtn-types"; | ||
|
||
export function groupByTheme( | ||
contributions: (Omit<ExportAnswer, "theme"> & { theme?: string })[] | ||
): AnswerByTheme[] { | ||
return contributions | ||
.reduce((grouped: AnswerByTheme[], answer): AnswerByTheme[] => { | ||
if (!answer.theme) { | ||
throw new Error( | ||
`Contribution [${answer.questionIndex}] - ${answer.slug} has no theme.` | ||
); | ||
} | ||
const group = grouped.find((g) => g.theme === answer.theme); | ||
if (group) { | ||
group.answers.push(answer as ExportAnswer); | ||
} else { | ||
grouped.push({ theme: answer.theme, answers: [answer as ExportAnswer] }); | ||
} | ||
return grouped; | ||
}, []) | ||
.map((group) => { | ||
group.answers = group.answers.sort( | ||
(a, b) => a.questionIndex - b.questionIndex | ||
); | ||
return group; | ||
}) | ||
.sort((a, b) => { | ||
return a.theme.localeCompare(b.theme); | ||
}); | ||
} |