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

Commit

Permalink
Merge branch 'main' into small-fix
Browse files Browse the repository at this point in the history
  • Loading branch information
carolineBda committed May 10, 2022
2 parents 76de899 + 5476733 commit 1976cd2
Show file tree
Hide file tree
Showing 21 changed files with 268 additions and 209 deletions.
1 change: 1 addition & 0 deletions .env.production
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,4 @@ MAIL_TLS=true

MAIL_ENABLED=true
SUPPORT_MAIL=monpsysante@fabrique.social.gouv.fr
API_ADRESSE_URL=https://api-adresse.data.gouv.fr/search
1 change: 1 addition & 0 deletions .env.staging
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,4 @@ MAIL_TLS=true

MAIL_ENABLED=true
SUPPORT_MAIL=monpsysante@fabrique.social.gouv.fr
API_ADRESSE_URL=https://api-adresse.data.gouv.fr/search
1 change: 1 addition & 0 deletions .env.test
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,4 @@ MAIL_ENABLED=false
SUPPORT_MAIL=monpsysante@fabrique.social.gouv.fr

NEXTAUTH_URL=http://localhost:3000
API_ADRESSE_URL=https://httpbin.org/apiAdresse
2 changes: 1 addition & 1 deletion .kube-workflow/preprod/templates/importData.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,6 @@ spec:
- yarn
- run
- cron:launch
- importData
- importFromDS
restartPolicy: Never
concurrencyPolicy: Forbid
28 changes: 0 additions & 28 deletions .kube-workflow/preprod/templates/importState.yaml

This file was deleted.

2 changes: 1 addition & 1 deletion .kube-workflow/prod/templates/importData.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,6 @@ spec:
- yarn
- run
- cron:launch
- importData
- importFromDS
restartPolicy: Never
concurrencyPolicy: Forbid
28 changes: 0 additions & 28 deletions .kube-workflow/prod/templates/importState.yaml

This file was deleted.

7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
# [1.32.0](https://github.com/SocialGouv/mon-psy-sante/compare/v1.31.1...v1.32.0) (2022-05-10)


### Features

* **cron:** fetch data from DS in one cron, and using the latest updated dossier date ([#159](https://github.com/SocialGouv/mon-psy-sante/issues/159)) ([1ab0a23](https://github.com/SocialGouv/mon-psy-sante/commit/1ab0a239c79b447f03b375bdcefe69906b9d0839))

## [1.31.1](https://github.com/SocialGouv/mon-psy-sante/compare/v1.31.0...v1.31.1) (2022-05-06)


Expand Down
25 changes: 25 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,3 +56,28 @@ To re-run the migration from 0
## To update sealed secret

https://socialgouv.github.io/sre-tools/


## How to connect app to db on bastion

- open ssh tunnel :

```
ssh -l localhost:54320:<server>.postgres.database.azure.com:5432 <USER>@fabrique-bastion
```

- dans la connection Sequelize, deactivate ssl :

```
dialectOptions: {
ssl: {
rejectUnauthorized: false,
},
},
```

- set la var d'env DATABASE_URL pour pointer vers localhost et le protocole est `postgre`:

```
DATABASE_URL=postgres://<USER_NAME>:<PASSWORD>@localhost:54320/prod
```
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "monpsy",
"version": "1.31.1",
"version": "1.32.0",
"commitlint": {
"extends": [
"@commitlint/config-conventional"
Expand Down
165 changes: 119 additions & 46 deletions src/__tests__/cron/import-state.spec.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,19 @@
import { importState } from "../../cron/demarchesSimplifiees";
import axios from "axios";

import {
importArchived,
importData,
importFromDS,
} from "../../cron/demarchesSimplifiees";
import { models } from "../../db/models";
import { getOnePsychologist } from "../../db/seeds/psychologist";
import { request } from "../../services/demarchesSimplifiees/request";
import { Psychologist } from "../../types/psychologist";

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

jest.mock("axios");

function formatForDS(psy: Psychologist) {
return Object.assign(
{
Expand Down Expand Up @@ -44,9 +52,9 @@ function formatForDS(psy: Psychologist) {
}

const states = ["accepte", "en_instruction", "refuse"];
const archiveds = [true, false];
const archived = [true, false];

const psychologistsInDB = archiveds.flatMap((archived) =>
const psychologistsInDB = archived.flatMap((archived) =>
states.flatMap((state) =>
getOnePsychologist({
archived,
Expand All @@ -66,62 +74,127 @@ const psychologistsInDS = psychologistsInDB.map((psy) => {
return formatForDS(psy);
});

const newPsy = formatForDS(
getOnePsychologist({
state: "accepte",
address: "newPsy",
instructorId: "psyInDB",
})
);
psychologistsInDS.push(newPsy);
const updatedPsy = formatForDS(psyHasChanged);
updatedPsy.state = "refuse";
psychologistsInDS.push(updatedPsy);

describe("Cron import State", () => {
beforeEach(async () => {
await models.Psychologist.destroy({ where: {} });

//@ts-ignore
await models.Psychologist.bulkCreate(psychologistsInDB);

describe("Cron import from DS", () => {
function mockDSCall(psychologistsInDS) {
// @ts-ignore
request.mockImplementationOnce(() =>
Promise.resolve({
demarche: { dossiers: { nodes: psychologistsInDS, pageInfo: {} } },
})
);
}

//@ts-ignore
request.mockImplementationOnce(() =>
Promise.resolve({ dossier: updatedPsy })
);
//@ts-ignore
request.mockImplementationOnce(() => Promise.resolve({ dossier: newPsy }));
});

it("Should add missing psy", async () => {
beforeEach(() => {
// @ts-ignore
const psyBefore: Psychologist = await models.Psychologist.findOne({
where: { id: psyHasChanged.id },
raw: true,
axios.get.mockImplementation(() => Promise.resolve({ data: {} }));
});
describe("With no data in DB", () => {
beforeEach(async () => {
await models.Psychologist.destroy({ where: {} });
mockDSCall(psychologistsInDS);
mockDSCall([]);
});
expect(psyBefore.state).toEqual("accepte");

await importState();
it("Should import all psy", async () => {
// @ts-ignore
let psychologists: Psychologist[] = await models.Psychologist.findAll({
raw: true,
});
expect(psychologists.length).toBe(0);

// @ts-ignore
const psychologists: Psychologist[] = await models.Psychologist.findAll({
where: { instructorId: "psyInDB" },
raw: true,
await importFromDS();

// @ts-ignore
psychologists = await models.Psychologist.findAll({ raw: true });

expect(psychologists.length).toEqual(7);
const psychologist = psychologists.find(
(psy) => psy.address === "psyHasChanged"
);
expect(psychologist.state).toEqual("accepte");
expect(psychologist.archived).toEqual(false);
});
});

describe("With data in DB", () => {
const updatedPsy = formatForDS(psyHasChanged);
updatedPsy.state = "sans_suite";
updatedPsy.archived = true;

expect(psychologists.length).toEqual(8);
expect(psychologists.find((psy) => psy.address === "newPsy").state).toEqual(
"accepte"
const newPsy = formatForDS(
getOnePsychologist({
state: "accepte",
address: "newPsy",
instructorId: "psyInDB",
})
);
expect(
psychologists.find((psy) => psy.address === "psyHasChanged").state
).toEqual("refuse");

beforeEach(async () => {
await models.Psychologist.destroy({ where: {} });

//@ts-ignore
await models.Psychologist.bulkCreate(psychologistsInDB);

// @ts-ignore
request.mockImplementationOnce(() =>
Promise.resolve({
demarche: { dossiers: { nodes: [newPsy], pageInfo: {} } },
})
);

// @ts-ignore
request.mockImplementationOnce(() =>
Promise.resolve({
demarche: { dossiers: { nodes: [updatedPsy], pageInfo: {} } },
})
);
});

it("Should add new psy", async () => {
// @ts-ignore
const psyBefore: Psychologist = await models.Psychologist.findOne({
where: { address: newPsy.address },
raw: true,
});
expect(psyBefore).toEqual(null);

await importData();
// @ts-ignore
const psychologists: Psychologist[] = await models.Psychologist.findAll({
where: { instructorId: "psyInDB" },
raw: true,
});

expect(psychologists.length).toEqual(8);
const psychologist = psychologists.find(
(psy) => psy.address === newPsy.address
);
expect(psychologist.state).toEqual("accepte");
expect(psychologist.archived).toEqual(false);
});

it("Should update psy state", async () => {
// @ts-ignore
const psyBefore: Psychologist = await models.Psychologist.findOne({
where: { id: updatedPsy.id },
raw: true,
});
expect(psyBefore.state).toEqual("accepte");

await importArchived();

// @ts-ignore
const psychologists: Psychologist[] = await models.Psychologist.findAll({
where: { instructorId: "psyInDB" },
raw: true,
});

expect(psychologists.length).toEqual(7);
const psychologist = psychologists.find(
(psy) => psy.id === updatedPsy.id
);
expect(psychologist.state).toEqual("sans_suite");
expect(psychologist.archived).toEqual(true);
});
});
});
Loading

0 comments on commit 1976cd2

Please sign in to comment.