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

fix(adeli): fix adeli number sanitizing #169

Merged
merged 3 commits into from
May 3, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 8 additions & 5 deletions src/cron/demarchesSimplifiees.ts
Original file line number Diff line number Diff line change
Expand Up @@ -129,8 +129,10 @@ const verifyDossier = async (dossier: Psychologist): Promise<void> => {
: `Validation auto erreur : ${validationDate}\n`.concat(
...errors.map((error) => `- ${error} \n`)
);

await addVerificationMessage(dossier.demarcheSimplifieesId, validationText);
return await addVerificationMessage(
dossier.demarcheSimplifieesId,
validationText
);
};

export const verifFolders = async (): Promise<void> => {
Expand All @@ -142,10 +144,11 @@ export const verifFolders = async (): Promise<void> => {
filterDossiersToVerif(dossiersInConstruction)
);

console.log(`Verifying ${dossiersToVerify.length} dossiers`);
await Promise.all(
dossiersToVerify.map(async (dossier) => {
limit(() => verifyDossier(dossier));
})
dossiersToVerify.map(async (dossier) =>
limit(() => verifyDossier(dossier))
)
);

console.log("verifFolders done");
Expand Down
2 changes: 2 additions & 0 deletions src/services/__tests__/adeli-resquest.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { requestAdeli } from "../adeli/request";
jest.mock("axios");
describe("requestAdeli", () => {
beforeEach(() => {
(axios.get as jest.Mock).mockReset();
// @ts-ignore
axios.get.mockImplementation(() => Promise.resolve({ data: { rows: [] } }));
});
Expand All @@ -23,6 +24,7 @@ describe("requestAdeli", () => {
${"123"}
${"1 2 3"}
${"1.2...3"}
${"00/00/01/23"}
`("should call api endpoint if adeli is $input", async ({ input }) => {
const result = await requestAdeli(input);
expect(axios.get).toHaveBeenCalledWith(
Expand Down
8 changes: 6 additions & 2 deletions src/services/adeli/request.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,12 @@ import { AdeliData, AdeliRawResponse } from "../../types/adeli";
import { zip } from "../../utils/array";
import config from "../config";

const formatRequestedAdeli = (adeliId: string) =>
adeliId.replace(".", "").replace(" ", "").replace("/", "").padStart(10, "0");
const formatRequestedAdeli = (adeliId: string): string =>
adeliId
.replace(/\./g, "")
.replace(/ /g, "")
.replace(/\//g, "")
.padStart(10, "0");

const rowColumnsToObject = <Column>(row: string[], columns: Column[]) =>
Object.fromEntries(zip(columns, row));
Expand Down