Skip to content

Commit

Permalink
implement message block no cdt
Browse files Browse the repository at this point in the history
  • Loading branch information
Victor committed May 16, 2024
1 parent e26df23 commit 7e943ce
Show file tree
Hide file tree
Showing 8 changed files with 59 additions and 8 deletions.
2 changes: 2 additions & 0 deletions shared/types/src/hasura/contributions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -135,8 +135,10 @@ export type ContributionMessageBlock = {
id: string;
label: string;
contentAgreement: string;
contentAgreementWithoutLegal: string;
contentLegal: string;
contentNotHandled: string;
contentNotHandledWithoutLegal: string;
};

export type ContributionAgreementMessage = {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,17 @@
import { ContributionContentType } from "@socialgouv/cdtn-types";
import {
ContributionContentType,
ContributionDocumentJson,
DocumentElasticWithSource,
} from "@socialgouv/cdtn-types";
import { fetchMessageBlock } from "../fetchMessageBlock";
import { fetchAgreementMessage } from "../fetchAgreementMessage";
import { generateMessageBlock } from "../generateMessageBlock";

jest.mock("../fetchMessageBlock");
jest.mock("../fetchAgreementMessage");

const contributions: DocumentElasticWithSource<ContributionDocumentJson>[] = [];

describe("generateMessageBlock", () => {
const mockContribution: any = {
questionId: "123",
Expand Down Expand Up @@ -36,6 +42,7 @@ describe("generateMessageBlock", () => {

mockContribution.contentType = contentType as ContributionContentType;
const result: string | undefined = await generateMessageBlock(
contributions,
mockContribution
);

Expand Down Expand Up @@ -63,6 +70,7 @@ describe("generateMessageBlock", () => {
mockContribution.contentType = contentType as ContributionContentType;
mockContribution.idcc = "0000";
const result: string | undefined = await generateMessageBlock(
contributions,
mockContribution
);

Expand All @@ -75,24 +83,25 @@ describe("generateMessageBlock", () => {
mockContribution.contentType = "UNKNOWN_TYPE";
mockContribution.idcc = "1234";

await expect(generateMessageBlock(mockContribution)).rejects.toThrowError(
"Unknown content type"
);
await expect(
generateMessageBlock(contributions, mockContribution)
).rejects.toThrowError("Unknown content type");
});

it("should throw an error for unknown content type", async () => {
mockContribution.contentType = null;
mockContribution.idcc = "1234";

await expect(generateMessageBlock(mockContribution)).rejects.toThrowError(
"Unknown content type"
);
await expect(
generateMessageBlock(contributions, mockContribution)
).rejects.toThrowError("Unknown content type");
});

it("should return undefined if no message block setup for the question", async () => {
(fetchMessageBlock as jest.Mock).mockResolvedValue(undefined);

const result: string | undefined = await generateMessageBlock(
contributions,
mockContribution
);

Expand All @@ -107,6 +116,7 @@ describe("generateMessageBlock", () => {
);

const result: string | undefined = await generateMessageBlock(
contributions,
mockContribution
);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ query get_question($id: uuid!) {
contentAgreement
contentLegal
contentNotHandled
contentAgreementWithoutLegal
contentNotHandledWithoutLegal
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ export async function generateContributions(

const content = await generateContent(contributions, contrib);

const messageBlock = await generateMessageBlock(contrib);
const messageBlock = await generateMessageBlock(contributions, contrib);

const references = generateReferences(contributions, contrib);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,17 @@ import { fetchMessageBlock } from "./fetchMessageBlock";
import { fetchAgreementMessage } from "./fetchAgreementMessage";

export const generateMessageBlock = async (
contributions: DocumentElasticWithSource<ContributionDocumentJson>[],
contrib: DocumentElasticWithSource<ContributionDocumentJson>
): Promise<string | undefined> => {
const agreementMessage = await fetchAgreementMessage(contrib.idcc);
if (agreementMessage) {
return agreementMessage;
}
const messageBlock = await fetchMessageBlock(contrib.questionId);
const contribGeneric = contributions.find(
(c) => c.questionId === contrib.questionId && c.idcc === "0000"
);
if (!messageBlock) {
return undefined;
} else if (
Expand All @@ -21,12 +25,24 @@ export const generateMessageBlock = async (
) {
return messageBlock.contentLegal;
} else if (contrib.contentType === "ANSWER" || contrib.contentType === "SP") {
if (
contribGeneric?.contentType === "GENERIC_NO_CDT" &&
messageBlock.contentAgreementWithoutLegal
) {
return messageBlock.contentAgreementWithoutLegal;
}
return messageBlock.contentAgreement;
} else if (
contrib.contentType === "NOTHING" ||
contrib.contentType === "CDT" ||
contrib.contentType === "UNFAVOURABLE"
) {
if (
contribGeneric?.contentType === "GENERIC_NO_CDT" &&
messageBlock.contentNotHandledWithoutLegal
) {
return messageBlock.contentNotHandledWithoutLegal;
}
return messageBlock.contentNotHandled;
}
throw new Error("Unknown content type");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,20 @@ configuration:
column_config:
content_agreement:
custom_name: contentAgreement
content_agreement_without_legal:
custom_name: contentAgreementWithoutLegal
content_legal:
custom_name: contentLegal
content_not_handled:
custom_name: contentNotHandled
content_not_handled_without_legal:
custom_name: contentNotHandledWithoutLegal
custom_column_names:
content_agreement: contentAgreement
content_agreement_without_legal: contentAgreementWithoutLegal
content_legal: contentLegal
content_not_handled: contentNotHandled
content_not_handled_without_legal: contentNotHandledWithoutLegal
custom_root_fields: {}
select_permissions:
- role: super
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
alter table "contribution"."question_messages" drop column "content_not_handled_without_legal";
alter table "contribution"."question_messages" drop column "content_agreement_without_legal";
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
alter table "contribution"."question_messages" add column "content_agreement_without_legal" text
null;
alter table "contribution"."question_messages" add column "content_not_handled_without_legal" text
null;

update contribution.question_messages
set content_not_handled_without_legal = '<p>Ces informations sont issues de l’analyse de votre convention collective de branche étendue.</p><p>D’autres textes ou votre contrat de travail peuvent également prévoir des règles spécifiques sur ce sujet. Plusieurs cas de figure peuvent se présenter :</p><ul><li>Si un accord d’entreprise (ou de groupe ou d’établissement) traite de ce sujet : c’est ce texte qui s’appliquera ;</li><li>Dans tous les cas, si le contrat de travail prévoit des règles plus favorables : il s’appliquera.</li></ul><p> Attention, d’autres règles non étendues peuvent potentiellement vous être applicables.</p>',
content_agreement_without_legal = '<p>Ces informations sont issues de l’analyse des règles prévues par votre convention collective de branche étendue. Si une convention ou un accord d’entreprise (ou de groupe, ou d’établissement) existe dans votre entreprise, il s’appliquera, qu’il soit plus ou moins favorable. Toutefois, si votre contrat de travail contient des règles plus favorables, ce sont celles-ci qui s’appliqueront.</p><p>Attention, d’autres règles non étendues peuvent potentiellement vous être applicables.</p>'
where label = 'Message Bloc 3';
update contribution.question_messages
set content_not_handled_without_legal = '<p>Ces informations sont issues de l’analyse de votre convention collective de branche étendue.</p><p>D’autres textes ou votre contrat de travail peuvent également prévoir des règles spécifiques sur ce sujet. </p><p>Plusieurs cas de figure peuvent se présenter :</p><ul><li>Si un accord d’entreprise (ou de groupe ou d’établissement) traite de ce sujet : c’est ce texte qui s’appliquera ;</li><li>Dans tous les cas, si le contrat de travail prévoit des règles plus favorables : il s’appliquera.</li></ul><p> Attention, d’autres règles non étendues peuvent potentiellement vous être applicables.</p>',
content_agreement_without_legal = '<p>Ces informations sont issues de l’analyse des règles prévues par votre convention collective de branche étendue. Si une convention ou un accord d’entreprise (ou de groupe, ou d’établissement) existant dans votre entreprise prévoit des garanties au moins équivalentes sur le même sujet, elles s’appliqueront, sauf si votre contrat de travail contient des règles plus favorables.</p><p>Attention, d’autres règles non étendues peuvent potentiellement vous être applicables.</p>'
where label = 'Message Bloc 2';

0 comments on commit 7e943ce

Please sign in to comment.