-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into feat/hackaton-divers
- Loading branch information
Showing
33 changed files
with
576 additions
and
198 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,7 +4,7 @@ import { useServer } from "@tests/utils/server.test.utils" | |
import { ObjectId } from "mongodb" | ||
import nock from "nock" | ||
import { generateJobsPartnersOfferPrivate } from "shared/fixtures/jobPartners.fixture" | ||
import { generateLbaConpanyFixture } from "shared/fixtures/recruteurLba.fixture" | ||
import { generateLbaCompanyFixture } from "shared/fixtures/recruteurLba.fixture" | ||
import { clichyFixture, generateReferentielCommuneFixtures, levalloisFixture, marseilleFixture, parisFixture } from "shared/fixtures/referentiel/commune.fixture" | ||
import { IGeoPoint } from "shared/models" | ||
import { IJobsPartnersOfferPrivate, IJobsPartnersWritableApiInput } from "shared/models/jobsPartners.model" | ||
|
@@ -39,7 +39,7 @@ const porteDeClichy: IGeoPoint = { | |
} | ||
const romesQuery = rome.join(",") | ||
const [longitude, latitude] = porteDeClichy.coordinates | ||
const recruteurLba = generateLbaConpanyFixture({ rome_codes: rome, geopoint: clichyFixture.centre, siret: "58006820882692", email: "[email protected]", website: "http://site.fr" }) | ||
const recruteurLba = generateLbaCompanyFixture({ rome_codes: rome, geopoint: clichyFixture.centre, siret: "58006820882692", email: "[email protected]", website: "http://site.fr" }) | ||
const jobPartnerOffer: IJobsPartnersOfferPrivate = generateJobsPartnersOfferPrivate({ | ||
offer_rome_codes: ["D1214"], | ||
workplace_geopoint: parisFixture.centre, | ||
|
@@ -164,8 +164,8 @@ describe("GET /jobs/search", () => { | |
"offer_target_diploma", | ||
"offer_title", | ||
"offer_to_be_acquired_skills", | ||
"partner", | ||
"partner_job_id", | ||
"partner_label", | ||
"workplace_address", | ||
"workplace_brand", | ||
"workplace_description", | ||
|
@@ -284,35 +284,15 @@ describe("POST /jobs", async () => { | |
const inSept = new Date("2024-09-01T00:00:00.000Z") | ||
|
||
const data: IJobsPartnersWritableApiInput = { | ||
partner_job_id: null, | ||
|
||
contract_start: inSept.toJSON(), | ||
contract_duration: null, | ||
contract_type: null, | ||
contract_remote: null, | ||
|
||
offer_title: "Apprentis en développement web", | ||
offer_rome_codes: ["M1602"], | ||
offer_desired_skills: [], | ||
offer_to_be_acquired_skills: [], | ||
offer_access_conditions: [], | ||
offer_creation: null, | ||
offer_expiration: null, | ||
offer_opening_count: 1, | ||
offer_origin: null, | ||
offer_multicast: true, | ||
offer_description: "Envie de devenir développeur web ? Rejoignez-nous !", | ||
offer_diploma_level_european: null, | ||
|
||
apply_url: null, | ||
apply_email: "[email protected]", | ||
apply_phone: null, | ||
|
||
workplace_siret: apiEntrepriseEtablissementFixture.dinum.data.siret, | ||
workplace_address_label: null, | ||
workplace_description: null, | ||
workplace_website: null, | ||
workplace_name: null, | ||
} | ||
|
||
beforeEach(async () => { | ||
|
@@ -385,7 +365,7 @@ describe("POST /jobs", async () => { | |
const doc = await getDbCollection("jobs_partners").findOne({ _id: new ObjectId(responseJson.id as string) }) | ||
|
||
// Ensure that the job offer is associated to the correct permission | ||
expect(doc?.partner).toBe("Un super Partenaire") | ||
expect(doc?.partner_label).toBe("Un super Partenaire") | ||
}) | ||
|
||
it("should apply method be defined", async () => { | ||
|
@@ -431,38 +411,18 @@ describe("PUT /jobs/:id", async () => { | |
const now = new Date("2024-06-18T00:00:00.000Z") | ||
const inSept = new Date("2024-09-01T00:00:00.000Z") | ||
|
||
const originalJob = generateJobsPartnersOfferPrivate({ _id: id, offer_title: "Old title", partner: "Un super Partenaire" }) | ||
const originalJob = generateJobsPartnersOfferPrivate({ _id: id, offer_title: "Old title", partner_label: "Un super Partenaire" }) | ||
|
||
const data: IJobsPartnersWritableApiInput = { | ||
partner_job_id: null, | ||
|
||
contract_start: inSept.toJSON(), | ||
contract_duration: null, | ||
contract_type: null, | ||
contract_remote: null, | ||
|
||
offer_title: "Apprentis en développement web", | ||
offer_rome_codes: ["M1602"], | ||
offer_desired_skills: [], | ||
offer_to_be_acquired_skills: [], | ||
offer_access_conditions: [], | ||
offer_creation: null, | ||
offer_expiration: null, | ||
offer_opening_count: 1, | ||
offer_origin: null, | ||
offer_multicast: true, | ||
offer_description: "Envie de devenir développeur web ? Rejoignez-nous !", | ||
offer_diploma_level_european: null, | ||
|
||
apply_url: null, | ||
apply_email: "[email protected]", | ||
apply_phone: null, | ||
|
||
workplace_siret: apiEntrepriseEtablissementFixture.dinum.data.siret, | ||
workplace_address_label: null, | ||
workplace_description: null, | ||
workplace_website: null, | ||
workplace_name: null, | ||
} | ||
|
||
beforeEach(async () => { | ||
|
@@ -551,7 +511,7 @@ describe("PUT /jobs/:id", async () => { | |
expect(response.json()).toEqual({ error: "Forbidden", message: "Unauthorized", statusCode: 403 }) | ||
}) | ||
|
||
it("should return 403 if user is trying to edit other partner job", async () => { | ||
it("should return 403 if user is trying to edit other partner_label job", async () => { | ||
const restrictedToken = getApiApprentissageTestingToken({ email: "[email protected]", organisation: "Un autre", habilitations: { "jobs:write": true } }) | ||
|
||
const response = await httpClient().inject({ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
56 changes: 56 additions & 0 deletions
56
server/src/jobs/offrePartenaire/cancelRemovedJobsPartners.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
import { createComputedJobPartner, createJobPartner } from "@tests/utils/jobsPartners.test.utils" | ||
import { useMongo } from "@tests/utils/mongo.test.utils" | ||
import { JOB_STATUS_ENGLISH } from "shared/models" | ||
import { beforeEach, describe, expect, it } from "vitest" | ||
|
||
import { getDbCollection } from "@/common/utils/mongodbUtils" | ||
|
||
import { cancelRemovedJobsPartners } from "./cancelRemovedJobsPartners" | ||
|
||
useMongo() | ||
|
||
describe("Canceling jobs_partners that have been removed from computed_jobs_partners", () => { | ||
beforeEach(async () => { | ||
// créations de plusieurs éléments existants dans jobs partners | ||
// création de plusieurs éléments dans computed jobs partners . certains avec validated true, d'autres false | ||
// certains éléments validated de computed sont déjà présents dans jobs partners | ||
// certains éléments dans jobs partners ne sont pas dans computed | ||
await createJobPartner({ partner_job_id: "existing_1", partner_label: "ft", offer_status: JOB_STATUS_ENGLISH.ACTIVE }) | ||
await createJobPartner({ partner_job_id: "existing_2", partner_label: "ft", offer_status: JOB_STATUS_ENGLISH.ACTIVE }) | ||
await createJobPartner({ partner_job_id: "existing_3", partner_label: "hw", offer_status: JOB_STATUS_ENGLISH.ACTIVE }) | ||
await createJobPartner({ partner_job_id: "existing_4", partner_label: "hw", offer_status: JOB_STATUS_ENGLISH.ACTIVE }) | ||
await createJobPartner({ partner_job_id: "existing_5", partner_label: "hw", offer_status: JOB_STATUS_ENGLISH.ACTIVE }) | ||
await createComputedJobPartner({ partner_job_id: "existing_1", partner_label: "notft", validated: true }) | ||
await createComputedJobPartner({ partner_job_id: "computed_1", partner_label: "ft", validated: true }) | ||
await createComputedJobPartner({ partner_job_id: "computed_2", partner_label: "ft", validated: false }) | ||
await createComputedJobPartner({ partner_job_id: "existing_3", partner_label: "hw", validated: true }) | ||
await createComputedJobPartner({ partner_job_id: "existing_4", partner_label: "hw", validated: true }) | ||
await createComputedJobPartner({ partner_job_id: "existing_5", partner_label: "hw", validated: false }) | ||
|
||
return async () => { | ||
await getDbCollection("computed_jobs_partners").deleteMany({}) | ||
await getDbCollection("jobs_partners").deleteMany({}) | ||
} | ||
}) | ||
|
||
it("L'annulation dans jobs_partners fonctionne comme attendue : \n- les éléments de jobs_partners qui ne sont plus dans computed doivent être taggés Annulé\n- les éléments de jobs_partners qui sont également dans computed sont toujours présents\n- aucun éléments de jobs_partners n'a été retiré de la collection", async () => { | ||
await cancelRemovedJobsPartners() | ||
|
||
// les éléments de jobs_partners qui ne sont plus dans computed doivent être taggés Annulé | ||
const countCanceledJobsPartners = await getDbCollection("jobs_partners").countDocuments({ | ||
partner_job_id: { $in: ["existing_1", "existing_2"] }, | ||
offer_status: JOB_STATUS_ENGLISH.ANNULEE, | ||
}) | ||
expect.soft(countCanceledJobsPartners).toEqual(2) | ||
|
||
// les éléments de jobs_partners qui sont également dans computed sont toujours présents | ||
const countRemainingJobsPartners = await getDbCollection("jobs_partners").countDocuments({ | ||
partner_job_id: { $in: ["existing_3", "existing_4", "existing_5"] }, | ||
}) | ||
expect.soft(countRemainingJobsPartners).toEqual(3) | ||
|
||
// aucun éléments de jobs_partners n'a été retiré de la collection | ||
const countJobsPartners = await getDbCollection("jobs_partners").countDocuments({}) | ||
expect.soft(countJobsPartners).toEqual(5) | ||
}) | ||
}) |
45 changes: 45 additions & 0 deletions
45
server/src/jobs/offrePartenaire/cancelRemovedJobsPartners.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
import { JOB_STATUS_ENGLISH } from "shared/models" | ||
|
||
import { getDbCollection } from "@/common/utils/mongodbUtils" | ||
|
||
export const cancelRemovedJobsPartners = async () => { | ||
const pipeline = [ | ||
{ | ||
$lookup: { | ||
from: "computed_jobs_partners", | ||
let: { partnerLabel: "$partner_label", partnerJobId: "$partner_job_id" }, | ||
pipeline: [ | ||
{ | ||
$match: { | ||
$expr: { | ||
$and: [{ $eq: ["$partner_label", "$$partnerLabel"] }, { $eq: ["$partner_job_id", "$$partnerJobId"] }], | ||
}, | ||
}, | ||
}, | ||
], | ||
as: "matched", | ||
}, | ||
}, | ||
{ | ||
$match: { | ||
matched: { $size: 0 }, | ||
}, | ||
}, | ||
{ | ||
$set: { offer_status: JOB_STATUS_ENGLISH.ANNULEE }, | ||
}, | ||
{ | ||
$unset: "matched", | ||
}, | ||
{ | ||
$merge: { | ||
into: "jobs_partners", | ||
on: ["partner_job_id", "partner_label"], | ||
whenMatched: "merge", | ||
whenNotMatched: "discard", | ||
}, | ||
}, | ||
] | ||
|
||
await getDbCollection("jobs_partners").aggregate(pipeline).toArray() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.