Skip to content
This repository has been archived by the owner on Jan 19, 2024. It is now read-only.

Commit

Permalink
feat(cron): traitement errone (#258)
Browse files Browse the repository at this point in the history
* feat(cron): traitement errone

* chore: up

* chore: up

* chore: up

* fix: up

* fix: up

* fix: add cron
  • Loading branch information
rap2hpoutre authored Oct 4, 2022
1 parent 70325e8 commit 4ab79b9
Show file tree
Hide file tree
Showing 5 changed files with 427 additions and 2 deletions.
28 changes: 28 additions & 0 deletions .kube-workflow/prod/templates/reportingTraitementErrone.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
apiVersion: batch/v1beta1
kind: CronJob
metadata:
namespace: mon-psy-sante
name: reporting-traitement-errone
labels:
app: mon-psy
spec:
schedule: "0 11 * * 2"
jobTemplate:
spec:
template:
spec:
containers:
- name: mon-psy
image: ghcr.io/socialgouv/mon-psy-sante/app:{{ .Values.global.imageTag }}
envFrom:
- secretRef:
name: app-sealed-secret
- secretRef:
name: pg-user
command:
- yarn
- run
- cron:launch
- reportingTraitementErrone
restartPolicy: Never
concurrencyPolicy: Forbid
233 changes: 233 additions & 0 deletions src/__tests__/cron/reportingTraitementErrone.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,233 @@
import {
cpamOnly,
notificationSelectionNotChecked,
withoutInstructeurFB,
} from "../../cron/reportingTraitementErrone";
import { request } from "../../services/demarchesSimplifiees/request";
import { DSPsychologist } from "../../types/psychologist";

const INSTRUCTEUR_FB = "SW5zdHJ1Y3RldXItNjQzNjI=";
const DOSSIER_ELIGIBLE = "Q2hhbXAtMTg0NDM5NQ==";
const NOTIFICATION_SELECTION = "Q2hhbXAtMjMyMzA2Mg==";

jest.mock("../../services/demarchesSimplifiees/request");

describe("Cron import from DS", () => {
function mockDSCall(psychologistsInDS: Partial<DSPsychologist>[]) {
const mockRequest = <jest.Mock>request;
mockRequest.mockImplementationOnce(() =>
Promise.resolve({
demarche: { dossiers: { nodes: psychologistsInDS, pageInfo: {} } },
})
);
}

describe("`cpamOnly()`: dossiers en construction with only CPAM instructeurs", () => {
it("should filter out dossiers with no instructeurs", async () => {
mockDSCall([
{
id: "1",
instructeurs: [],
},
]);
expect(await cpamOnly()).toHaveLength(0);
});

it("should filter out dossiers with internal instructeurs and no CPAM instructeurs", async () => {
mockDSCall([
{
id: "1",
instructeurs: [
{ id: "SW5zdHJ1Y3RldXItNjExNTM=", email: "x@example.org" },
{ id: "SW5zdHJ1Y3RldXItNDk3NDI=", email: "y@example.org" },
],
},
]);
expect(await cpamOnly()).toHaveLength(0);
});

it("should filter out dossiers with internal instructeurs and CPAM instructeurs", async () => {
mockDSCall([
{
id: "1",
instructeurs: [
{ id: "SW5zdHJ1Y3RldXItNjExNTM=", email: "x@example.org" },
{ id: "xxxxxxx", email: "cpam@example.org" },
],
},
]);
expect(await cpamOnly()).toHaveLength(0);
});

it("should include dossiers with no internal instructeurs and one CPAM instructeurs", async () => {
mockDSCall([
{
id: "1",
instructeurs: [{ id: "xxxxxxx", email: "cpam@example.org" }],
},
]);
expect(await cpamOnly()).toHaveLength(1);
});
it("should include dossiers with no internal instructeurs and some CPAM instructeurs", async () => {
mockDSCall([
{
id: "1",
instructeurs: [
{ id: "xxxxxxx", email: "cpam@example.org" },
{ id: "yyyyyyy", email: "cpam2@example.org" },
],
},
]);
expect(await cpamOnly()).toHaveLength(1);
});
});

describe("`notificationSelectionNotChecked()`: dossiers with no notification selection", () => {
it("should filter out dossiers with notification selection checked", async () => {
mockDSCall([
{
id: "1",
annotations: [
{
id: NOTIFICATION_SELECTION,
label: "Notification Sélection",
stringValue: "oui",
},
],
},
]);
expect(await notificationSelectionNotChecked()).toHaveLength(0);
});
it("should filter out dossiers where dossier elligible is not OUI or NON", async () => {
mockDSCall([
{ id: "0", annotations: [] },
{
id: "1",
annotations: [
{
id: DOSSIER_ELIGIBLE,
label: "Dossier elligible",
stringValue: "peut-être",
},
],
},
{
id: "2",
annotations: [
{
id: NOTIFICATION_SELECTION,
label: "Notification Sélection",
stringValue: "",
},
{
id: DOSSIER_ELIGIBLE,
label: "Dossier elligible",
stringValue: "peut-être",
},
],
},
]);
expect(await notificationSelectionNotChecked()).toHaveLength(0);
});
it("should include dossiers with notification selection not checked and dossier elligible OUI or NON", async () => {
mockDSCall([
{
id: "1",
annotations: [
{
id: DOSSIER_ELIGIBLE,
label: "Dossier elligible",
stringValue: "OUI",
},
{
id: NOTIFICATION_SELECTION,
label: "Notification Sélection",
stringValue: "",
},
],
},
{
id: "2",
annotations: [
{
id: NOTIFICATION_SELECTION,
label: "Notification Sélection",
stringValue: "",
},
{
id: DOSSIER_ELIGIBLE,
label: "Dossier elligible",
stringValue: "NON",
},
],
},
]);
expect(await notificationSelectionNotChecked()).toHaveLength(2);
});
});

describe("`withoutInstructeurFB()`: dossiers en instruction elligible without FB as an inscructor", () => {
it("should filter out dossiers where dossier elligible is not OUI or NON", async () => {
mockDSCall([
{ id: "0", annotations: [] },
{
id: "1",
annotations: [
{
id: DOSSIER_ELIGIBLE,
label: "Dossier elligible",
stringValue: "peut-être",
},
],
},
]);
expect(await withoutInstructeurFB()).toHaveLength(0);
});
it("should filter out dossiers where dossier elligible is OUI or NON and FB is an instructeur", async () => {
mockDSCall([
{
id: "1",
annotations: [
{
id: DOSSIER_ELIGIBLE,
label: "Dossier elligible",
stringValue: "OUI",
},
],
instructeurs: [{ id: INSTRUCTEUR_FB, email: "x@example.org" }],
},
{
id: "2",
annotations: [
{
id: DOSSIER_ELIGIBLE,
label: "Dossier elligible",
stringValue: "NON",
},
],
instructeurs: [
{ id: INSTRUCTEUR_FB, email: "x@example.org" },
{ id: "yyyyyyy", email: "y@example.org" },
],
},
]);
expect(await withoutInstructeurFB()).toHaveLength(0);
});
it("should include dossiers where dossier elligible is OUI or NON and FB is not an instructeur", async () => {
mockDSCall([
{
id: "1",
annotations: [
{
id: DOSSIER_ELIGIBLE,
label: "Dossier elligible",
stringValue: "OUI",
},
],
instructeurs: [{ id: "yyyyyyy", email: "y@example.org" }],
},
]);
expect(await withoutInstructeurFB()).toHaveLength(1);
});
});
});
2 changes: 2 additions & 0 deletions src/cron/launch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { reportingDossierEligible } from "./reportingDossierEligible";
import { reportingDossierRefuse } from "./reportingDossierRefuse";
import { reportingExpertWeekly } from "./reportingExpertWeekly";
import { reportingStatsByDepartment } from "./reportingStatsByDepartment";
import { reportingTraitementErrone } from "./reportingTraitementErrone";

const runJob = async (job): Promise<void> => {
const SENTRY_DSN = process.env.NEXT_PUBLIC_SENTRY_DSN;
Expand Down Expand Up @@ -33,6 +34,7 @@ const cronJobs = {
reportingExpertWeekly,
reportingDossierEligible,
reportingDossierRefuse,
reportingTraitementErrone,
};

const jobName = process.argv[2];
Expand Down
Loading

0 comments on commit 4ab79b9

Please sign in to comment.