Skip to content

Commit

Permalink
fix: suppression du controle de date sur le statut apprenti (#3902)
Browse files Browse the repository at this point in the history
  • Loading branch information
Pomarom authored Jan 20, 2025
1 parent 9c8eaa0 commit e82cea4
Show file tree
Hide file tree
Showing 4 changed files with 69 additions and 3 deletions.
9 changes: 6 additions & 3 deletions server/src/common/actions/effectifs.statut.actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -178,11 +178,14 @@ function determineStatutsByContrats(
contracts.forEach((contract, index) => {
const { dateDebut, dateRupture } = contract;

if (dateDebut <= effectiveDateFin) {
statuts.push({ valeur: STATUT_APPRENANT.APPRENTI, date: dateDebut });
if (dateDebut) {
if (!dateRupture || (dateRupture && dateDebut <= dateRupture)) {
// Gestion des rutptures avant démarrage
statuts.push({ valeur: STATUT_APPRENANT.APPRENTI, date: dateDebut });
}
}

if (dateRupture && dateRupture <= effectiveDateFin) {
if (dateRupture && dateDebut <= dateRupture) {
const nextContract = contracts[index + 1];
if (!nextContract) {
latestRuptureDate = dateRupture;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { addJob } from "job-processor";

export const up = async () => {
await addJob({
name: "hydrate:effectifs:update_all_computed_statut",
queued: true,
});
};
5 changes: 5 additions & 0 deletions server/src/jobs/jobs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,11 @@ export async function setupJobProcessor() {
return hydrateDecaRaw();
},
},
"hydrate:effectifs:update_all_computed_statut": {
handler: async () => {
return hydrateEffectifsComputedTypes();
},
},
"hydrate:effectifs:update_computed_statut": {
handler: async (job, signal) => {
const organismeId = (job.payload?.id as string) ? new ObjectId(job.payload?.id as string) : null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,9 +93,59 @@ describe("hydrateEffectifsComputedTypes", () => {

expect(updatedEffectif?._computed?.statut?.en_cours).toEqual(STATUT_APPRENANT.APPRENTI);
});

it("doit avoir le statut apprenti même si le contrat commence dans le futur", async () => {
const customDateDeDebutDeContrat = new Date();
customDateDeDebutDeContrat.setDate(customDateDeDebutDeContrat.getDate() + 7);

const effectif = await createSampleEffectif({
organisme: sampleOrganisme,
contrats: [
{
date_debut: customDateDeDebutDeContrat,
date_fin: formation.date_fin,
},
],
formation,
});

const { insertedId } = await effectifsDb().insertOne(effectif as IEffectif);
await hydrateEffectifsComputedTypes();

const updatedEffectif = await effectifsDb().findOne({ _id: insertedId });

expect(updatedEffectif?._computed?.statut?.en_cours).toEqual(STATUT_APPRENANT.APPRENTI);
});
});

describe("apprenent en formation avec rupture de contrat", () => {
it("ne doit pas avoir le statut d'apprenti si rupture de contrat avant le début du contrat", async () => {
const ruptureDate = new Date(formation.date_entree.getTime());
ruptureDate.setDate(formation.date_entree.getDate() - 10);

const customEvalutationDate = new Date(formation.date_entree.getTime() + 10);
const effectif = await createSampleEffectif({
organisme: sampleOrganisme,
contrats: [
{
date_debut: formation.date_entree,
date_fin: formation.date_fin,
date_rupture: ruptureDate,
},
],
formation,
});

const { insertedId } = await effectifsDb().insertOne(effectif as IEffectif);
await hydrateEffectifsComputedTypes({ evaluationDate: customEvalutationDate });

const updatedEffectif = await effectifsDb().findOne({ _id: insertedId });

expect(updatedEffectif?._computed?.statut?.parcours).toEqual([
{ valeur: STATUT_APPRENANT.INSCRIT, date: formation.date_entree },
]);
});

it("doit avoir le statut rupturant si rupture de moins de 180 jours", async () => {
const ruptureDate = new Date(evaluationDate.getTime());
ruptureDate.setDate(ruptureDate.getDate() - 179);
Expand Down

0 comments on commit e82cea4

Please sign in to comment.