-
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.
feat: lbac 2220: ajout du rome aux computed job partners (#1636)
* feat: ajout du rome aux computed job partners * fix: update fillFieldsForPartnersFactory documentation * fix: typing * fix: tests * fix: review Kevin * fix: tests * fix: talisman
- Loading branch information
1 parent
13f2290
commit 7269665
Showing
17 changed files
with
304 additions
and
144 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
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 |
---|---|---|
@@ -1,9 +1,11 @@ | ||
import { fillOpcoInfosForPartners } from "./fillOpcoInfosForPartners" | ||
import { fillRomeForPartners } from "./fillRomeForPartners" | ||
import { fillSiretInfosForPartners } from "./fillSiretInfosForPartners" | ||
import { validateComputedJobPartners } from "./validateComputedJobPartners" | ||
|
||
export const fillComputedJobsPartners = async () => { | ||
await fillOpcoInfosForPartners() | ||
await fillSiretInfosForPartners() | ||
await fillRomeForPartners() | ||
await validateComputedJobPartners() | ||
} |
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
116 changes: 116 additions & 0 deletions
116
server/src/jobs/offrePartenaire/fillRomeForPartners.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,116 @@ | ||
import { givenSomeComputedJobPartners } from "@tests/fixture/givenSomeComputedJobPartners" | ||
import { useMongo } from "@tests/utils/mongo.test.utils" | ||
import nock from "nock" | ||
import { IRomeoAPIResponse } from "shared/models/cacheRomeo.model" | ||
import { beforeEach, describe, expect, it, vi } from "vitest" | ||
|
||
import { nockFranceTravailRomeo } from "@/common/apis/franceTravail/franceTravail.client.fixture" | ||
import { getDbCollection } from "@/common/utils/mongodbUtils" | ||
|
||
import { cacheRomeFixture, cacheRomeResultFixture } from "../../../../shared/fixtures/cacheRome.fixture" | ||
import { nockFranceTravailTokenAccessRomeo } from "../../common/apis/franceTravail/franceTravail.client.fixture" | ||
|
||
import { fillRomeForPartners } from "./fillRomeForPartners" | ||
|
||
const now = new Date("2024-07-21T04:49:06.000+02:00") | ||
|
||
describe("fillRomeForPartners", () => { | ||
useMongo() | ||
|
||
beforeEach(() => { | ||
vi.useFakeTimers() | ||
vi.setSystemTime(now) | ||
|
||
nock("https://api.francetravail.io").post(/.*/).reply(404) | ||
|
||
return async () => { | ||
vi.useRealTimers() | ||
nock.cleanAll() | ||
await getDbCollection("computed_jobs_partners").deleteMany({}) | ||
await getDbCollection("cache_romeo").deleteMany({}) | ||
} | ||
}) | ||
|
||
const title = "Chef de partie, second de cuisine H/F" | ||
const nafLabel = "Commerce de détail d'habillement en magasin spécialisé" | ||
|
||
it("should enrich with cache", async () => { | ||
// given | ||
const romeCode = "K1601" | ||
await givenSomeComputedJobPartners([ | ||
{ | ||
offer_title: title, | ||
workplace_naf_label: nafLabel, | ||
offer_rome_codes: null, | ||
}, | ||
]) | ||
const cacheRomeo = cacheRomeFixture({ | ||
intitule: title, | ||
contexte: nafLabel, | ||
metiersRome: [ | ||
cacheRomeResultFixture({ | ||
codeRome: romeCode, | ||
}), | ||
], | ||
}) | ||
await getDbCollection("cache_romeo").insertOne(cacheRomeo) | ||
// when | ||
await fillRomeForPartners() | ||
// then | ||
const jobs = await getDbCollection("computed_jobs_partners").find({}).toArray() | ||
expect.soft(jobs.length).toBe(1) | ||
const [job] = jobs | ||
const { offer_rome_codes } = job | ||
expect.soft(job.errors).toEqual([]) | ||
expect.soft(offer_rome_codes).toEqual([romeCode]) | ||
}) | ||
it("should enrich with api", async () => { | ||
// given | ||
const romeCode = "J1501" | ||
await givenSomeComputedJobPartners([ | ||
{ | ||
offer_title: title, | ||
workplace_naf_label: nafLabel, | ||
offer_rome_codes: null, | ||
}, | ||
]) | ||
nock.cleanAll() | ||
nockFranceTravailTokenAccessRomeo() | ||
const apiResponse: IRomeoAPIResponse = [ | ||
{ | ||
intitule: title, | ||
identifiant: "0", | ||
contexte: nafLabel, | ||
metiersRome: [ | ||
cacheRomeResultFixture({ | ||
codeRome: romeCode, | ||
scorePrediction: 0.8, | ||
}), | ||
cacheRomeResultFixture({ | ||
codeRome: "ignored", | ||
scorePrediction: 0.7, | ||
}), | ||
], | ||
}, | ||
] | ||
nockFranceTravailRomeo( | ||
[ | ||
{ | ||
intitule: title, | ||
identifiant: "0", | ||
contexte: nafLabel, | ||
}, | ||
], | ||
apiResponse | ||
) | ||
// when | ||
await fillRomeForPartners() | ||
// then | ||
const jobs = await getDbCollection("computed_jobs_partners").find({}).toArray() | ||
expect.soft(jobs.length).toBe(1) | ||
const [job] = jobs | ||
const { offer_rome_codes } = job | ||
expect.soft(job.errors).toEqual([]) | ||
expect.soft(offer_rome_codes).toEqual([romeCode]) | ||
}) | ||
}) |
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,33 @@ | ||
import { COMPUTED_ERROR_SOURCE, IComputedJobsPartners } from "shared/models/jobsPartnersComputed.model" | ||
|
||
import { getRomesInfos } from "../../services/cacheRomeo.service" | ||
|
||
import { fillFieldsForPartnersFactory } from "./fillFieldsForPartnersFactory" | ||
|
||
export const fillRomeForPartners = async () => { | ||
const filledFields = ["offer_rome_codes"] as const satisfies (keyof IComputedJobsPartners)[] | ||
return fillFieldsForPartnersFactory({ | ||
job: COMPUTED_ERROR_SOURCE.API_ROMEO, | ||
sourceFields: ["offer_title", "workplace_naf_label"], | ||
filledFields, | ||
groupSize: 50, | ||
getData: async (documents) => { | ||
const validDocuments = documents.flatMap((document) => (document.offer_title ? [document] : [])) | ||
const queries = validDocuments.map(({ offer_title, workplace_naf_label }) => ({ intitule: offer_title!, contexte: workplace_naf_label })) | ||
const allRomeInfos = await getRomesInfos(queries) | ||
|
||
return validDocuments.flatMap((document, index) => { | ||
const romeInfos = allRomeInfos[index] | ||
if (!romeInfos) { | ||
return [] | ||
} | ||
|
||
const result: Pick<IComputedJobsPartners, (typeof filledFields)[number] | "_id"> = { | ||
_id: document._id, | ||
offer_rome_codes: [romeInfos], | ||
} | ||
return [result] | ||
}) | ||
}, | ||
}) | ||
} |
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
Oops, something went wrong.