diff --git a/targets/frontend/src/modules/agreements/__tests__/mapAgreementToDocument.test.ts b/targets/frontend/src/modules/agreements/__tests__/mapAgreementToDocument.test.ts new file mode 100644 index 000000000..0c690e3e4 --- /dev/null +++ b/targets/frontend/src/modules/agreements/__tests__/mapAgreementToDocument.test.ts @@ -0,0 +1,40 @@ +import { mapAgreementToDocument } from "../mapAgreementToDocument"; +import { Agreement } from "../type"; + +jest.mock("../../common/getGlossaryContent.ts", () => { + return { + getGlossaryContent: jest.fn(() => "mocked-glossary-content"), + }; +}); + +describe("mapAgreementToDocument", () => { + const agreement: Agreement = { + id: "1234", + isSupported: false, + name: "Ma nouvelle CC du 03 Octobre 2024", + shortName: "Ma nouvelle CC", + synonyms: [], + updatedAt: "3/10/2024", + }; + + it("crée un nouveau document si pas de doc", async () => { + const result = await mapAgreementToDocument(agreement); + expect(result).toEqual({ + cdtn_id: "6f8c4cc14e", + document: { + num: 1234, + shortTitle: "Ma nouvelle CC", + synonymes: [], + }, + initial_id: "1234", + is_available: true, + is_published: false, + is_searchable: false, + meta_description: "IDCC 1234: Ma nouvelle CC du 03 Octobre 2024", + slug: "1234-ma-nouvelle-cc", + source: "conventions_collectives", + text: "IDCC 1234: Ma nouvelle CC du 03 Octobre 2024 Ma nouvelle CC", + title: "Ma nouvelle CC du 03 Octobre 2024", + }); + }); +}); diff --git a/targets/frontend/src/modules/agreements/mapAgreementToDocument.ts b/targets/frontend/src/modules/agreements/mapAgreementToDocument.ts index cea02632c..02e4291df 100644 --- a/targets/frontend/src/modules/agreements/mapAgreementToDocument.ts +++ b/targets/frontend/src/modules/agreements/mapAgreementToDocument.ts @@ -15,7 +15,7 @@ export const mapAgreementToDocument = ( meta_description: `IDCC ${data.id}: ${data.name}`, title: data.name, text: `IDCC ${data.id}: ${data.name} ${data.shortName}`, - slug: document?.slug ?? slugify(data.shortName), + slug: document?.slug ?? `${data.id}-${slugify(data.shortName)}`, is_searchable: document ? document.is_searchable : data.kali_id !== undefined, diff --git a/targets/hasura/migrations/default/1727965175418_update_cc_clug/down.sql b/targets/hasura/migrations/default/1727965175418_update_cc_clug/down.sql new file mode 100644 index 000000000..e69de29bb diff --git a/targets/hasura/migrations/default/1727965175418_update_cc_clug/up.sql b/targets/hasura/migrations/default/1727965175418_update_cc_clug/up.sql new file mode 100644 index 000000000..55706da15 --- /dev/null +++ b/targets/hasura/migrations/default/1727965175418_update_cc_clug/up.sql @@ -0,0 +1,7 @@ +UPDATE public.documents +SET slug = '2707-batiment-etam-ile-de-france-hors-seine-et-marne' +WHERE slug = 'batiment-etam-ile-de-france-hors-seine-et-marne'; + +UPDATE public.documents +SET slug = '3251-bijouterie-joaillerie-orfevrerie-horlogerie-bjoh' +WHERE slug = 'bijouterie-joaillerie-orfevrerie-horlogerie-bjoh';