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

Commit

Permalink
fix(ds): import Psy state (#86)
Browse files Browse the repository at this point in the history
  • Loading branch information
desoindx authored Mar 8, 2022
1 parent 85a992f commit 69220bb
Show file tree
Hide file tree
Showing 10 changed files with 77 additions and 23 deletions.
2 changes: 1 addition & 1 deletion .socialgouv/environments/preprod/yaml/importState.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,5 @@ spec:
- yarn
- run
- cron:launch
- importData
- importState
restartPolicy: Never
13 changes: 13 additions & 0 deletions src/db/migrations/20220301190442-state.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
'use strict';

module.exports = {
async up (queryInterface, Sequelize) {
await queryInterface.addColumn("psychologist", "state", {
type: Sequelize.STRING,
})
},

async down (queryInterface, Sequelize) {
await queryInterface.removeColumn("psychologist", "state")
}
};
1 change: 1 addition & 0 deletions src/db/models/psychologist.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ export default (sequelize) => {
lastName: DataTypes.STRING,
phone: DataTypes.STRING,
public: DataTypes.STRING,
state: DataTypes.STRING,
teleconsultation: DataTypes.BOOLEAN,
visible: DataTypes.BOOLEAN,
website: DataTypes.STRING,
Expand Down
1 change: 1 addition & 0 deletions src/db/seeds/psychologist.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ export const getOnePsychologist = (
lastName: faker.name.lastName(),
phone: faker.phone.phoneNumber("0# ## ## ## ##"),
public: faker.random.arrayElement(allPublics),
state: "accepte",
teleconsultation: faker.datatype.boolean(),
visible: true,
website: faker.helpers.randomize([
Expand Down
1 change: 1 addition & 0 deletions src/services/demarchesSimplifiees/buildRequest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ export const requestPsychologistsState = async (
}
nodes {
archived
state
number
}
}
Expand Down
1 change: 1 addition & 0 deletions src/services/demarchesSimplifiees/import.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,5 +64,6 @@ export const getPsychologistState = async (): Promise<
return list.psychologists.map((dossier) => ({
archived: dossier.archived,
id: dossier.number,
state: dossier.state,
}));
};
1 change: 1 addition & 0 deletions src/services/demarchesSimplifiees/parsePsychologists.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ const parseDossierMetadata = async (
id: dossier.number,
instructorId: dossier.groupeInstructeur.id,
lastName: dossier.demandeur.nom,
state: dossier.state,
};

JSON.parse(config.demarchesSimplifiees.champs).forEach(([id, field]) => {
Expand Down
70 changes: 51 additions & 19 deletions src/services/psychologists.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,24 +19,28 @@ import {
describe("Service psychologists", () => {
beforeEach(async () => {
await models.Psychologist.destroy({ where: {} });
const states = ["accepte", "en_instruction", "refuse"];
const archiveds = [true, false];
const visibles = [true, false];
const teleconsultations = [true, false];
const instructorIds = ["1", "2", "3"];

// 2 x 2 x 2 x 3 x 3 = 72 psys
const psychologists = archiveds.flatMap((archived) =>
visibles.flatMap((visible) =>
teleconsultations.flatMap((teleconsultation) =>
instructorIds.flatMap((instructorId) =>
allPublics.map((p) =>
getOnePsychologist({
archived,
instructorId,
public: p,
teleconsultation,
visible,
})
states.flatMap((state) =>
visibles.flatMap((visible) =>
teleconsultations.flatMap((teleconsultation) =>
instructorIds.flatMap((instructorId) =>
allPublics.map((p) =>
getOnePsychologist({
archived,
instructorId,
public: p,
state,
teleconsultation,
visible,
})
)
)
)
)
Expand Down Expand Up @@ -242,21 +246,41 @@ describe("Service psychologists", () => {

beforeEach(async () => {
const psychologists = [
getOnePsychologist({ archived: true, id: 1, instructorId }),
getOnePsychologist({ archived: false, id: 2, instructorId }),
getOnePsychologist({ archived: true, id: 3, instructorId }),
getOnePsychologist({ archived: false, id: 4, instructorId }),
getOnePsychologist({
archived: true,
id: 1,
instructorId,
state: "initial",
}),
getOnePsychologist({
archived: false,
id: 2,
instructorId,
state: "initial",
}),
getOnePsychologist({
archived: true,
id: 3,
instructorId,
state: "initial",
}),
getOnePsychologist({
archived: false,
id: 4,
instructorId,
state: "initial",
}),
];

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

it("Should only update archived value", async () => {
it("Should only update state & archived value", async () => {
await updateState([
{ archived: true, id: 0 },
{ archived: false, id: 1 },
{ archived: true, id: 2 },
{ archived: true, id: 0, state: "final" },
{ archived: false, id: 1, state: "final" },
{ archived: true, id: 2, state: "final" },
]);

// @ts-ignore
Expand All @@ -266,9 +290,17 @@ describe("Service psychologists", () => {

expect(psychologists.find((psy) => psy.id === 0)).toEqual(undefined);
expect(psychologists.find((psy) => psy.id === 1).archived).toEqual(false);
expect(psychologists.find((psy) => psy.id === 1).state).toEqual("final");
expect(psychologists.find((psy) => psy.id === 2).archived).toEqual(true);
expect(psychologists.find((psy) => psy.id === 2).state).toEqual("final");
expect(psychologists.find((psy) => psy.id === 3).archived).toEqual(true);
expect(psychologists.find((psy) => psy.id === 3).state).toEqual(
"initial"
);
expect(psychologists.find((psy) => psy.id === 4).archived).toEqual(false);
expect(psychologists.find((psy) => psy.id === 4).state).toEqual(
"initial"
);
});
});
});
9 changes: 6 additions & 3 deletions src/services/psychologists.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,14 @@ export const getByInstructor = async (
// @ts-ignore
return models.Psychologist.findAll({
raw: true,
where: { archived: false, instructorId: group },
where: { archived: false, instructorId: group, state: "accepte" },
});
};

export const countAll = async () =>
models.Psychologist.count({ where: { archived: false, visible: true } });
models.Psychologist.count({
where: { archived: false, state: "accepte", visible: true },
});

const DEFAULT_PAGE_SIZE = 50;
export const getAll = async (filters: {
Expand All @@ -36,7 +38,7 @@ export const getAll = async (filters: {
? parseInt(filters[FILTER.PAGE_SIZE] as string, 10)
: DEFAULT_PAGE_SIZE;

const where: any = { archived: false, visible: true };
const where: any = { archived: false, state: "accepte", visible: true };
const query: Sequelize.FindOptions<any> = {
limit: pageSize,
offset: parseInt(filters[FILTER.PAGE_INDEX] as string, 10) * pageSize,
Expand Down Expand Up @@ -123,6 +125,7 @@ export const updateState = async (newStates: Partial<Psychologist>[]) => {
models.Psychologist.update(
{
archived: newState.archived,
state: newState.state,
},
{ where: { id: newState.id } }
)
Expand Down
1 change: 1 addition & 0 deletions src/types/psychologist.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ export interface Psychologist {
website: string;
coordinates: { type: string; coordinates: [number, number] };
instructorId: string;
state: string;
}

export interface DSPsychologist {
Expand Down

0 comments on commit 69220bb

Please sign in to comment.