Skip to content

Commit

Permalink
fix convention integrations tests
Browse files Browse the repository at this point in the history
  • Loading branch information
JeromeBu committed Nov 21, 2024
1 parent a4f76e6 commit 8d34ad3
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 35 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -974,6 +974,7 @@ describe("Pg implementation of ConventionQueries", () => {
signedAt: new Date().toISOString(),
})
.withDateStart(conventionStartDate)
.withDateEnd(addDays(new Date(conventionStartDate), 5).toISOString())
.build();

const agency = AgencyDtoBuilder.create()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { addDays, subDays } from "date-fns";
import { Pool } from "pg";
import {
AgencyDtoBuilder,
AppellationAndRomeDto,
BeneficiaryCurrentEmployer,
BeneficiaryRepresentative,
ConventionDto,
Expand All @@ -22,17 +23,27 @@ import { toAgencyWithRights } from "../../../utils/agency";
import { PgAgencyRepository } from "../../agency/adapters/PgAgencyRepository";
import { PgConventionRepository } from "./PgConventionRepository";

const beneficiaryRepresentative: BeneficiaryRepresentative = {
role: "beneficiary-representative",
email: "[email protected]",
firstName: "The",
lastName: "Representative",
phone: "+33112233445",
};
describe("PgConventionRepository", () => {
const beneficiaryRepresentative: BeneficiaryRepresentative = {
role: "beneficiary-representative",
email: "[email protected]",
firstName: "The",
lastName: "Representative",
phone: "+33112233445",
};

const userPeExternalId = "749dd14f-c82a-48b1-b1bb-fffc5467e4d4";
const userPeExternalId = "749dd14f-c82a-48b1-b1bb-fffc5467e4d4";

const styliste: AppellationAndRomeDto = {
romeCode: "B1805",
romeLabel: "Stylisme",
appellationCode: "19540",
appellationLabel: "Styliste",
};

const conventionStylisteBuilder =
new ConventionDtoBuilder().withImmersionAppellation(styliste);

describe("PgConventionRepository", () => {
let pool: Pool;
let conventionRepository: PgConventionRepository;
let db: KyselyDb;
Expand Down Expand Up @@ -60,7 +71,7 @@ describe("PgConventionRepository", () => {
});

it("Adds a new convention", async () => {
const convention = new ConventionDtoBuilder()
const convention = conventionStylisteBuilder
.withId("aaaaac99-9c0b-1bbb-bb6d-6bb9bd38aaaa")
.withEstablishmentNumberOfEmployeesRange("20-49")
.build();
Expand Down Expand Up @@ -93,7 +104,7 @@ describe("PgConventionRepository", () => {
});

it("Adds/Update a new CCI convention", async () => {
const convention = new ConventionDtoBuilder()
const convention = conventionStylisteBuilder
.withInternshipKind("mini-stage-cci")
.withId("aaaaac99-9c0b-1bbb-bb6d-6bb9bd38aaaa")
.withDateStart(new Date("2023-01-02").toISOString())
Expand All @@ -120,7 +131,7 @@ describe("PgConventionRepository", () => {
});

it("Adds a new convention with field workConditions undefined and no signatories", async () => {
const convention = new ConventionDtoBuilder()
const convention = conventionStylisteBuilder
.withoutWorkCondition()
.notSigned()
.build();
Expand All @@ -138,6 +149,7 @@ describe("PgConventionRepository", () => {
};

const convention = new ConventionDtoBuilder()
.withImmersionAppellation(styliste)
.withoutWorkCondition()
.withAcquisition(withAcquisition)
.notSigned()
Expand All @@ -159,15 +171,15 @@ describe("PgConventionRepository", () => {
});

it("Adds a convention renewed from another one", async () => {
const existingConvention = new ConventionDtoBuilder()
const existingConvention = conventionStylisteBuilder
.withStatus("ACCEPTED_BY_VALIDATOR")
.withId("11111111-1111-4111-1111-111111111111")
.withEstablishmentNumberOfEmployeesRange("20-49")
.build();

await conventionRepository.save(existingConvention);

const renewedConvention = new ConventionDtoBuilder()
const renewedConvention = conventionStylisteBuilder
.withId("22222222-2222-4222-2222-222222222222")
.withStatus("READY_TO_SIGN")
.withRenewed({
Expand Down Expand Up @@ -572,20 +584,21 @@ describe("PgConventionRepository", () => {

it("Update convention with validator", async () => {
const conventionId: ConventionId = "aaaaac99-9c0b-1aaa-aa6d-6bb9bd38aaaa";
const convention = new ConventionDtoBuilder()
const convention = conventionStylisteBuilder
.withId(conventionId)
.withStatus("ACCEPTED_BY_COUNSELLOR")
.build();
await conventionRepository.save(convention);

const updatedConvention = new ConventionDtoBuilder()
const updatedConvention = conventionStylisteBuilder
.withId(conventionId)
.withStatus("ACCEPTED_BY_COUNSELLOR")
.withValidator({ firstname: "John", lastname: "Doe" })
.withCounsellor({ firstname: "Billy", lastname: "Idol" })
.withBeneficiaryEmail("[email protected]")
.withStatusJustification("some justification")
.withDateEnd(new Date("2021-01-20").toISOString())
.withDateStart(new Date("2024-10-20").toISOString())
.withDateEnd(new Date("2024-10-24").toISOString())
.build();

await conventionRepository.update(updatedConvention);
Expand All @@ -597,17 +610,18 @@ describe("PgConventionRepository", () => {

it("update convention with dateApproval", async () => {
const conventionId: ConventionId = "aaaaac99-9c0b-1aaa-aa6d-6bb9bd38aaaa";
const convention = new ConventionDtoBuilder()
const convention = conventionStylisteBuilder
.withId(conventionId)
.withStatus("IN_REVIEW")
.build();
await conventionRepository.save(convention);

const updatedConvention = new ConventionDtoBuilder()
const updatedConvention = conventionStylisteBuilder
.withId(conventionId)
.withStatus("ACCEPTED_BY_COUNSELLOR")
.withDateApproval(new Date("2021-01-05").toISOString())
.withDateEnd(new Date("2021-01-20").toISOString())
.withDateStart(new Date("2024-10-20").toISOString())
.withDateEnd(new Date("2024-10-24").toISOString())
.withDateApproval(new Date("2024-10-15").toISOString())
.build();

await conventionRepository.update(updatedConvention);
Expand All @@ -619,7 +633,7 @@ describe("PgConventionRepository", () => {

it("Retrieves federated identity if exists", async () => {
const peConnectId: PeConnectToken = "bbbbac99-9c0b-bbbb-bb6d-6bb9bd38bbbb";
const convention = new ConventionDtoBuilder()
const convention = conventionStylisteBuilder
.withFederatedIdentity({
provider: "peConnect",
token: peConnectId,
Expand Down Expand Up @@ -656,19 +670,20 @@ describe("PgConventionRepository", () => {

it("Updates an already saved immersion", async () => {
const idA: ConventionId = "aaaaac99-9c0b-1aaa-aa6d-6bb9bd38aaaa";
const convention = new ConventionDtoBuilder()
const convention = conventionStylisteBuilder
.withId(idA)
.withStatus("ACCEPTED_BY_VALIDATOR")
.withEstablishmentNumberOfEmployeesRange("20-49")
.build();
await conventionRepository.save(convention);

const updatedConvention = new ConventionDtoBuilder()
const updatedConvention = conventionStylisteBuilder
.withId(idA)
.withStatus("CANCELLED")
.withBeneficiaryEmail("[email protected]")
.withStatusJustification("some justification")
.withDateEnd(new Date("2021-01-20").toISOString())
.withDateStart(new Date("2024-10-20").toISOString())
.withDateEnd(new Date("2024-10-24").toISOString())
.withEstablishmentNumberOfEmployeesRange("200-249")
.build();

Expand All @@ -678,7 +693,7 @@ describe("PgConventionRepository", () => {
});

it("Adds a new convention with a beneficiary representative", async () => {
const convention = new ConventionDtoBuilder()
const convention = conventionStylisteBuilder
.withId("aaaaac99-9c0b-1bbb-bb6d-6bb9bd38aaaa")
.withBeneficiaryRepresentative(beneficiaryRepresentative)
.build();
Expand All @@ -692,13 +707,13 @@ describe("PgConventionRepository", () => {

it("Updates an already saved immersion with a beneficiary representative", async () => {
const idA: ConventionId = "aaaaac99-9c0b-1aaa-aa6d-6bb9bd38aaaa";
const convention = new ConventionDtoBuilder()
const convention = conventionStylisteBuilder
.withId(idA)
.withBeneficiaryRepresentative(beneficiaryRepresentative)
.build();
await conventionRepository.save(convention);

const updatedConvention = new ConventionDtoBuilder()
const updatedConvention = conventionStylisteBuilder
.withId(idA)
.withStatus("ACCEPTED_BY_VALIDATOR")
.withBeneficiaryEmail("[email protected]")
Expand All @@ -709,7 +724,8 @@ describe("PgConventionRepository", () => {
.signedByBeneficiary(new Date().toISOString())
.signedByEstablishmentRepresentative(new Date().toISOString())
.signedByBeneficiaryRepresentative(new Date().toISOString())
.withDateEnd(new Date("2021-01-20").toISOString())
.withDateStart(new Date("2024-10-20").toISOString())
.withDateEnd(new Date("2024-10-24").toISOString())
.build();

await conventionRepository.update(updatedConvention);
Expand All @@ -719,13 +735,13 @@ describe("PgConventionRepository", () => {

it("Updates an already saved immersion if the beneficiary representative is removed", async () => {
const idA: ConventionId = "aaaaac99-9c0b-1aaa-aa6d-6bb9bd38aaaa";
const convention = new ConventionDtoBuilder()
const convention = conventionStylisteBuilder
.withId(idA)
.withBeneficiaryRepresentative(beneficiaryRepresentative)
.build();
await conventionRepository.save(convention);

const updatedConvention = new ConventionDtoBuilder()
const updatedConvention = conventionStylisteBuilder
.withId(idA)
.withBeneficiaryRepresentative(undefined)
.build();
Expand All @@ -737,10 +753,10 @@ describe("PgConventionRepository", () => {

it("Updates an already saved immersion without beneficiary representative with a beneficiary representative", async () => {
const idA: ConventionId = "aaaaac99-9c0b-1aaa-aa6d-6bb9bd38aaaa";
const convention = new ConventionDtoBuilder().withId(idA).build();
const convention = conventionStylisteBuilder.withId(idA).build();
await conventionRepository.save(convention);

const updatedConvention = new ConventionDtoBuilder()
const updatedConvention = conventionStylisteBuilder
.withId(idA)
.withBeneficiaryRepresentative(beneficiaryRepresentative)
.build();
Expand All @@ -754,7 +770,7 @@ describe("PgConventionRepository", () => {
it("changes status of convention with date end before given date to deprecated with justification", async () => {
const dateSince = new Date("2023-08-30");

const conventionBuilderWithDateInRange = new ConventionDtoBuilder()
const conventionBuilderWithDateInRange = conventionStylisteBuilder
.withDateStart(subDays(dateSince, 3).toISOString())
.withDateEnd(subDays(dateSince, 1).toISOString())
.withSchedule(reasonableSchedule);
Expand All @@ -764,7 +780,7 @@ describe("PgConventionRepository", () => {
.withStatus("PARTIALLY_SIGNED")
.build();

const convention2ToKeepAsIs = new ConventionDtoBuilder()
const convention2ToKeepAsIs = conventionStylisteBuilder
.withId("22221111-1111-4111-1111-111111112222")
.withDateStart(subDays(dateSince, 2).toISOString())
.withDateEnd(addDays(dateSince, 1).toISOString())
Expand Down

0 comments on commit 8d34ad3

Please sign in to comment.