Skip to content

Commit

Permalink
feat(lba-2125): filtrage des offre partenaires (#1740)
Browse files Browse the repository at this point in the history
* feat: embryon

* feat: openapi

* feat: limitation du filtrage aux vrais partners

* feat: tests ok

* feat: inutile
  • Loading branch information
alanlr authored and remy-auricoste committed Jan 20, 2025
1 parent f0912b5 commit d7519c0
Show file tree
Hide file tree
Showing 5 changed files with 118 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import { clichyFixture, generateReferentielCommuneFixtures, levalloisFixture, ma
import { generateReferentielRome } from "shared/fixtures/rome.fixture"
import { generateUserWithAccountFixture } from "shared/fixtures/userWithAccount.fixture"
import { ILbaCompany, IRecruiter, IReferentielRome, JOB_STATUS, JOB_STATUS_ENGLISH } from "shared/models"
import { IJobsPartnersOfferPrivate, INiveauDiplomeEuropeen } from "shared/models/jobsPartners.model"
import { FILTER_JOBPARTNERS_LABEL, IJobsPartnersOfferPrivate, INiveauDiplomeEuropeen, JOBPARTNERS_LABEL } from "shared/models/jobsPartners.model"
import { zJobOfferApiWriteV3, zJobSearchApiV3Response, type IJobOfferApiWriteV3, type IJobOfferApiWriteV3Input } from "shared/routes/v3/jobs/jobs.routes.v3.model"
import { afterEach, beforeAll, beforeEach, describe, expect, it, vi } from "vitest"

Expand Down Expand Up @@ -1421,6 +1421,91 @@ describe("findJobsOpportunities", () => {
expect(results.jobs.map((j) => j.offer.target_diploma)).toEqual([null, { european: "3", label: "CAP, BEP, autres formations niveau (CAP)" }])
})
})

describe("when filtered by partner_label", () => {
beforeEach(async () => {
await getDbCollection("jobs_partners").insertMany([
generateJobsPartnersOfferPrivate({
offer_rome_codes: ["D1104"],
workplace_geopoint: parisFixture.centre,
partner_label: JOBPARTNERS_LABEL.OFFRES_EMPLOI_LBA,
partner_job_id: "job-id-filter-1",
}),
generateJobsPartnersOfferPrivate({
offer_rome_codes: ["D1104"],
workplace_geopoint: parisFixture.centre,
partner_label: JOBPARTNERS_LABEL.HELLOWORK,
partner_job_id: "job-id-filter-2",
}),
generateJobsPartnersOfferPrivate({
offer_rome_codes: ["D1104"],
workplace_geopoint: parisFixture.centre,
partner_label: JOBPARTNERS_LABEL.HELLOWORK,
partner_job_id: "job-id-filter-3",
}),
generateJobsPartnersOfferPrivate({
offer_rome_codes: ["D1104"],
workplace_geopoint: parisFixture.centre,
partner_label: JOBPARTNERS_LABEL.RH_ALTERNANCE,
partner_job_id: "job-id-filter-4",
}),
])
await getDbCollection("recruiters").deleteMany({})
})

it("should only return jobs without the excluded partner_labels", async () => {
let results = await findJobsOpportunities(
{
longitude: parisFixture.centre.coordinates[0],
latitude: parisFixture.centre.coordinates[1],
radius: 30,
romes: ["D1104"],
rncp: null,
partners_to_exclude: [FILTER_JOBPARTNERS_LABEL.HELLOWORK],
},
new JobOpportunityRequestContext({ path: "/api/route" }, "api-alternance")
)

const parseResult = zJobSearchApiV3Response.safeParse(results)
expect.soft(parseResult.success).toBeTruthy()
expect(parseResult.error).toBeUndefined()
expect.soft(results.jobs).toHaveLength(2)
expect.soft(results.jobs[0].identifier.partner_label).toEqual(JOBPARTNERS_LABEL.OFFRES_EMPLOI_LBA)
expect.soft(results.jobs[1].identifier.partner_label).toEqual(JOBPARTNERS_LABEL.RH_ALTERNANCE)

results = await findJobsOpportunities(
{
longitude: parisFixture.centre.coordinates[0],
latitude: parisFixture.centre.coordinates[1],
radius: 30,
romes: ["D1104"],
rncp: null,
partners_to_exclude: [FILTER_JOBPARTNERS_LABEL.RH_ALTERNANCE],
},
new JobOpportunityRequestContext({ path: "/api/route" }, "api-alternance")
)

expect.soft(results.jobs).toHaveLength(3)
expect.soft(results.jobs[0].identifier.partner_label).toEqual(JOBPARTNERS_LABEL.OFFRES_EMPLOI_LBA)
expect.soft(results.jobs[1].identifier.partner_label).toEqual(JOBPARTNERS_LABEL.HELLOWORK)
expect.soft(results.jobs[2].identifier.partner_label).toEqual(JOBPARTNERS_LABEL.HELLOWORK)

results = await findJobsOpportunities(
{
longitude: parisFixture.centre.coordinates[0],
latitude: parisFixture.centre.coordinates[1],
radius: 30,
romes: ["D1104"],
rncp: null,
partners_to_exclude: [FILTER_JOBPARTNERS_LABEL.RH_ALTERNANCE, FILTER_JOBPARTNERS_LABEL.HELLOWORK],
},
new JobOpportunityRequestContext({ path: "/api/route" }, "api-alternance")
)

expect.soft(results.jobs).toHaveLength(1)
expect.soft(results.jobs[0].identifier.partner_label).toEqual(JOBPARTNERS_LABEL.OFFRES_EMPLOI_LBA)
})
})
})

describe("france travail jobs", () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -252,13 +252,17 @@ export const getJobsQuery = async (
return result
}

export const getJobsPartnersFromDB = async ({ romes, geo, target_diploma_level }: IJobSearchApiV3QueryResolved): Promise<IJobsPartnersOfferPrivate[]> => {
export const getJobsPartnersFromDB = async ({ romes, geo, target_diploma_level, partners_to_exclude }: IJobSearchApiV3QueryResolved): Promise<IJobsPartnersOfferPrivate[]> => {
const query: Filter<IJobsPartnersOfferPrivate> = {
offer_multicast: true,
offer_status: JOB_STATUS_ENGLISH.ACTIVE,
offer_expiration: { $gt: new Date() },
}

if (partners_to_exclude?.length) {
query.partner_label = { $not: { $in: partners_to_exclude } }
}

if (romes) {
query.offer_rome_codes = { $in: romes }
}
Expand Down Expand Up @@ -338,8 +342,8 @@ export const getJobsPartnersFromDBForUI = async ({ romes, geo, target_diploma_le
.toArray()
}

export const getJobsPartnersForApi = async ({ romes, geo, target_diploma_level }: IJobSearchApiV3QueryResolved): Promise<IJobOfferApiReadV3[]> => {
const jobsPartners = await getJobsPartnersFromDB({ romes, geo, target_diploma_level })
export const getJobsPartnersForApi = async ({ romes, geo, target_diploma_level, partners_to_exclude }: IJobSearchApiV3QueryResolved): Promise<IJobOfferApiReadV3[]> => {
const jobsPartners = await getJobsPartnersFromDB({ romes, geo, target_diploma_level, partners_to_exclude })

return jobsPartners.map((j) =>
jobsRouteApiv3Converters.convertToJobOfferApiReadV3({
Expand Down
18 changes: 18 additions & 0 deletions shared/helpers/openapi/__snapshots__/generateOpenapi.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -10130,6 +10130,24 @@ Limite : 5 appel(s) / 1 seconde(s)
],
},
},
{
"in": "query",
"name": "partners_to_exclude",
"required": false,
"schema": {
"items": {
"enum": [
"Hello work",
"RH Alternance",
],
"type": "string",
},
"type": [
"array",
"null",
],
},
},
],
"responses": {
"200": {
Expand Down
5 changes: 5 additions & 0 deletions shared/models/jobsPartners.model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,11 @@ export enum JOBPARTNERS_LABEL {
RH_ALTERNANCE = "RH Alternance",
}

export enum FILTER_JOBPARTNERS_LABEL {
HELLOWORK = JOBPARTNERS_LABEL.HELLOWORK,
RH_ALTERNANCE = JOBPARTNERS_LABEL.RH_ALTERNANCE,
}

export const ZJobsPartnersRecruiterApi = z.object({
_id: zObjectId,
workplace_siret: extensions.siret.nullable().describe("Siret de l'entreprise"),
Expand Down
2 changes: 2 additions & 0 deletions shared/routes/v3/jobs/jobs.routes.v3.model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { TRAINING_CONTRACT_TYPE } from "../../../constants"
import { extensions } from "../../../helpers/zodHelpers/zodPrimitives"
import { JOB_STATUS_ENGLISH } from "../../../models"
import {
FILTER_JOBPARTNERS_LABEL,
zDiplomaEuropeanLevel,
ZJobsPartnersOfferApi,
ZJobsPartnersOfferPrivate,
Expand Down Expand Up @@ -97,6 +98,7 @@ export const zJobSearchApiV3Query = z
target_diploma_level: zDiplomaEuropeanLevel.optional(),
romes: extensions.romeCodeArray().nullable().default(null),
rncp: extensions.rncpCode().nullable().default(null),
partners_to_exclude: z.array(extensions.buildEnum(FILTER_JOBPARTNERS_LABEL)).nullish(),
})
.superRefine((data, ctx) => {
if (data.longitude == null && data.latitude != null) {
Expand Down

0 comments on commit d7519c0

Please sign in to comment.