Skip to content

Commit

Permalink
fix test
Browse files Browse the repository at this point in the history
  • Loading branch information
achorein committed Oct 4, 2024
1 parent aaa0f7d commit 46899c2
Show file tree
Hide file tree
Showing 8 changed files with 34 additions and 16 deletions.
2 changes: 1 addition & 1 deletion api/src/__tests__/fixtures/application.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ function getNewApplicationFixture(): Partial<ApplicationType> {
tutorName: faker.person.firstName(),
priority: "1",
status: "WAITING_VALIDATION",
cohortId: "1",
cohortId: new ObjectId().toString(),
};
}

Expand Down
4 changes: 3 additions & 1 deletion api/src/__tests__/fixtures/bus.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
import { fakerFR as faker } from "@faker-js/faker";
import { Types } from "mongoose";
const { ObjectId } = Types;
import { BusType } from "../../models/bus";

function getNewBusFixture(): Partial<BusType> {
return {
idExcel: faker.lorem.words(),
capacity: faker.number.int({ min: 11, max: 20 }),
placesLeft: faker.number.int({ min: 1, max: 10 }),
cohortId: "1",
cohortId: new ObjectId().toString(),
};
}

Expand Down
4 changes: 3 additions & 1 deletion api/src/__tests__/fixtures/classe.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import { ClasseType } from "snu-lib";
import { Types } from "mongoose";
const { ObjectId } = Types;

export function createFixtureClasse(fields: Partial<ClasseType> = {}): Partial<ClasseType> {
const classe: Partial<ClasseType> = {
Expand All @@ -23,7 +25,7 @@ export function createFixtureClasse(fields: Partial<ClasseType> = {}): Partial<C
type: "FULL",
estimatedSeats: 20,
trimester: "T1",
cohortId: "1",
cohortId: new ObjectId().toString(),
...fields,
};
return classe;
Expand Down
4 changes: 3 additions & 1 deletion api/src/__tests__/fixtures/inscriptionGoal.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
import { fakerFR as faker } from "@faker-js/faker";
import { Types } from "mongoose";
const { ObjectId } = Types;
import { InscriptionGoalType } from "../../models";

export default function getNewInscriptionGoalFixture(object: Partial<InscriptionGoalType> = {}): Partial<InscriptionGoalType> {
return {
region: faker.lorem.words(),
department: faker.number.int({ min: 11, max: 123 }).toString(),
max: faker.number.int({ min: 11, max: 123 }),
cohortId: "1",
cohortId: new ObjectId().toString(),
...object,
};
}
2 changes: 1 addition & 1 deletion api/src/__tests__/fixtures/meetingPoint.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ function getNewMeetingPointFixture(): Partial<MeetingPointType> {
departureAtString: faker.lorem.words(),
returnAt: faker.date.past(),
returnAtString: faker.lorem.words(),
cohortId: "1",
cohortId: new ObjectId().toString(),
};
}

Expand Down
4 changes: 3 additions & 1 deletion api/src/__tests__/fixtures/sessionPhase1.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { Types } from "mongoose";
const { ObjectId } = Types;
import { SessionPhase1Type } from "snu-lib";

function getNewSessionPhase1Fixture(object: Partial<SessionPhase1Type> = {}): Partial<SessionPhase1Type> {
Expand All @@ -8,7 +10,7 @@ function getNewSessionPhase1Fixture(object: Partial<SessionPhase1Type> = {}): Pa
placesTotal: placesLeft,
placesLeft: placesLeft,
status: "VALIDATED",
cohortId: "1",
cohortId: new ObjectId().toString(),
...object,
};
}
Expand Down
6 changes: 4 additions & 2 deletions api/src/__tests__/fixtures/young.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import { fakerFR as faker } from "@faker-js/faker";
import { Types } from "mongoose";
const { ObjectId } = Types;
import { departmentList, regionList, YoungType } from "snu-lib";

function randomDepartment() {
Expand Down Expand Up @@ -204,8 +206,8 @@ export default function getNewYoungFixture(fields: Partial<YoungType> = {}): Par
sportInterest: faker.lorem.sentences(),
environmentInterest: faker.lorem.sentences(),
citizenshipInterest: faker.lorem.sentences(),
cohortId: "1",
originalCohortId: "1",
cohortId: new ObjectId().toString(),
originalCohortId: new ObjectId().toString(),
...fields,
};
}
24 changes: 16 additions & 8 deletions api/src/__tests__/referent.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { fakerFR as faker } from "@faker-js/faker";
import request from "supertest";

import { ROLES, SENDINBLUE_TEMPLATES, YOUNG_STATUS, STATUS_CLASSE, FUNCTIONAL_ERRORS, YoungDto, YoungType } from "snu-lib";
import { ROLES, SENDINBLUE_TEMPLATES, YOUNG_STATUS, STATUS_CLASSE, FUNCTIONAL_ERRORS, YoungType } from "snu-lib";

import { CohortModel, YoungModel } from "../models";
import { getInscriptionGoalStats } from "../services/inscription-goal";
Expand Down Expand Up @@ -98,6 +98,7 @@ describe("Referent", () => {
}
it("should not update young if goal not defined", async () => {
const testName = "Juillet 2023";
const cohort = await createCohortHelper(getNewCohortFixture({ name: testName }));
// ajout d'un objectif non définie
const res = await request(getAppHelper())
.post(`/inscription-goal/${testName}`)
Expand All @@ -110,7 +111,7 @@ describe("Referent", () => {
{
status: YOUNG_STATUS.VALIDATED,
},
{ region: testName, department: testName, cohort: testName },
{ region: testName, department: testName, cohort: cohort.name, cohortId: cohort.id },
{ keepYoung: true },
);
expect(response.statusCode).not.toEqual(200);
Expand Down Expand Up @@ -146,7 +147,7 @@ describe("Referent", () => {
{
status: YOUNG_STATUS.VALIDATED,
},
{ region: testName, department: testName, schoolDepartment: testName },
{ region: testName, department: testName, schoolDepartment: testName, cohortId: cohort._id },
)
).response;
expect(response.statusCode).not.toEqual(200);
Expand All @@ -158,7 +159,7 @@ describe("Referent", () => {
{
status: YOUNG_STATUS.VALIDATED,
},
{ region: testName, department: testName, schoolDepartment: testName },
{ region: testName, department: testName, schoolDepartment: testName, cohortId: cohort._id },
)
).response;
expect(response.statusCode).not.toEqual(200);
Expand All @@ -169,7 +170,7 @@ describe("Referent", () => {
{
status: YOUNG_STATUS.VALIDATED,
},
{ region: testName, department: testName },
{ region: testName, department: testName, cohortId: cohort._id },
)
).response;
expect(response.statusCode).not.toEqual(200);
Expand All @@ -192,12 +193,14 @@ describe("Referent", () => {
expect(res.statusCode).toEqual(404);
});
it("should update young name", async () => {
const cohort = await createCohortHelper(getNewCohortFixture());
// @ts-ignore: FIXME: young.name does not exist
const { young, modifiedYoung, response } = await createYoungThenUpdate({ name: faker.company.name() });
const { young, modifiedYoung, response } = await createYoungThenUpdate({ name: faker.company.name() }, { cohortId: cohort._id });
expect(response.statusCode).toEqual(200);
expectYoungToEqual(young, modifiedYoung);
});
it("should cascade young statuses when sending status WITHDRAWN", async () => {
const cohort = await createCohortHelper(getNewCohortFixture());
const { young, response } = await createYoungThenUpdate(
{
status: "WITHDRAWN",
Expand All @@ -206,6 +209,7 @@ describe("Referent", () => {
statusPhase1: "AFFECTED",
statusPhase2: "WAITING_REALISATION",
statusPhase3: "WAITING_REALISATION",
cohortId: cohort._id,
},
);
expect(response.statusCode).toEqual(200);
Expand All @@ -215,6 +219,7 @@ describe("Referent", () => {
expect(young?.statusPhase3).toEqual("WAITING_REALISATION");
});
it("should not cascade status to WITHDRAWN if validated", async () => {
const cohort = await createCohortHelper(getNewCohortFixture());
const { young, response } = await createYoungThenUpdate(
{
status: "WITHDRAWN",
Expand All @@ -223,6 +228,7 @@ describe("Referent", () => {
statusPhase1: "DONE",
statusPhase2: "WAITING_REALISATION",
statusPhase3: "VALIDATED",
cohortId: cohort._id,
},
);
expect(response.statusCode).toEqual(200);
Expand All @@ -232,13 +238,15 @@ describe("Referent", () => {
expect(young?.statusPhase3).toEqual("VALIDATED");
});
it("should update young statuses when sending cohection stay presence true", async () => {
const { young, response } = await createYoungThenUpdate({ cohesionStayPresence: "true" }, { cohesionStayPresence: undefined });
const cohort = await createCohortHelper(getNewCohortFixture());
const { young, response } = await createYoungThenUpdate({ cohesionStayPresence: "true" }, { cohesionStayPresence: undefined, cohortId: cohort._id });
expect(response.statusCode).toEqual(200);
expect(young?.statusPhase1).toEqual("DONE");
expect(young?.cohesionStayPresence).toEqual("true");
});
it("should update young statuses when sending cohection stay presence false", async () => {
const { young, response } = await createYoungThenUpdate({ cohesionStayPresence: "false" });
const cohort = await createCohortHelper(getNewCohortFixture());
const { young, response } = await createYoungThenUpdate({ cohesionStayPresence: "false" }, { cohortId: cohort._id });
expect(response.statusCode).toEqual(200);
expect(young?.statusPhase1).toEqual("NOT_DONE");
expect(young?.cohesionStayPresence).toEqual("false");
Expand Down

0 comments on commit 46899c2

Please sign in to comment.