Skip to content

Commit 2e89c11

Browse files
fix(lbac-3200): appel classification cfa (#2378)
1 parent 376f373 commit 2e89c11

File tree

3 files changed

+131
-11
lines changed

3 files changed

+131
-11
lines changed
Lines changed: 123 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,123 @@
1+
import nock from "nock"
2+
import { IClassificationLabBatchResponse } from "shared/models/cacheClassification.model"
3+
import { COMPUTED_ERROR_SOURCE } from "shared/models/jobsPartnersComputed.model"
4+
import { beforeEach, describe, expect, it } from "vitest"
5+
6+
import { getDbCollection } from "@/common/utils/mongodbUtils"
7+
import config from "@/config"
8+
import { detectClassificationJobsPartners as detectClassificationJobsPartnersRaw } from "@/jobs/offrePartenaire/detectClassificationJobsPartners"
9+
import { givenSomeComputedJobPartners } from "@tests/fixture/givenSomeComputedJobPartners"
10+
import { useMongo } from "@tests/utils/mongo.test.utils"
11+
12+
const detectClassificationJobsPartners = () => detectClassificationJobsPartnersRaw({ shouldNotifySlack: false })
13+
14+
const offer_title = "vendeur / vendeuse"
15+
const workplace_name = "decathlon"
16+
const workplace_description = "description d'un magasin decathlon"
17+
const offer_description = "description d'une offre de vendeur"
18+
const partner_job_id = "partner_job_id"
19+
20+
describe("detectClassificationJobsPartners", () => {
21+
useMongo()
22+
23+
beforeEach(() => {
24+
const apiResponse: IClassificationLabBatchResponse = [
25+
{
26+
id: partner_job_id,
27+
label: "entreprise",
28+
model: "model",
29+
scores: { cfa: 0.5, entreprise: 0.4, entreprise_cfa: 0.2 },
30+
text: "Software Engineer",
31+
},
32+
]
33+
nock(config.labonnealternanceLab.baseUrl).post("/scores").reply(200, apiResponse)
34+
return async () => {
35+
await getDbCollection("computed_jobs_partners").deleteMany({})
36+
}
37+
})
38+
39+
it("should pass on a job partner with all fields", async () => {
40+
// given
41+
await givenSomeComputedJobPartners([
42+
{
43+
partner_job_id,
44+
offer_title,
45+
workplace_name,
46+
workplace_description,
47+
offer_description,
48+
},
49+
])
50+
// when
51+
await detectClassificationJobsPartners()
52+
// then
53+
const jobs = await getDbCollection("computed_jobs_partners").find({}).toArray()
54+
expect.soft(jobs.length).toEqual(1)
55+
const [job] = jobs
56+
expect.soft(job.jobs_in_success.includes(COMPUTED_ERROR_SOURCE.CLASSIFICATION)).toEqual(true)
57+
})
58+
59+
it("should pass on a job partner with only a title", async () => {
60+
// given
61+
await givenSomeComputedJobPartners([
62+
{
63+
partner_job_id,
64+
offer_title,
65+
},
66+
])
67+
// when
68+
await detectClassificationJobsPartners()
69+
// then
70+
const jobs = await getDbCollection("computed_jobs_partners").find({}).toArray()
71+
expect.soft(jobs.length).toEqual(1)
72+
const [job] = jobs
73+
expect.soft(job.jobs_in_success.includes(COMPUTED_ERROR_SOURCE.CLASSIFICATION)).toEqual(true)
74+
})
75+
it("should pass on a job partner with only a workplace name", async () => {
76+
// given
77+
await givenSomeComputedJobPartners([
78+
{
79+
partner_job_id,
80+
workplace_name,
81+
},
82+
])
83+
// when
84+
await detectClassificationJobsPartners()
85+
// then
86+
const jobs = await getDbCollection("computed_jobs_partners").find({}).toArray()
87+
expect.soft(jobs.length).toEqual(1)
88+
const [job] = jobs
89+
expect.soft(job.jobs_in_success.includes(COMPUTED_ERROR_SOURCE.CLASSIFICATION)).toEqual(true)
90+
})
91+
it("should pass on a job partner with only a workplace description", async () => {
92+
// given
93+
await givenSomeComputedJobPartners([
94+
{
95+
partner_job_id,
96+
workplace_description,
97+
},
98+
])
99+
// when
100+
await detectClassificationJobsPartners()
101+
// then
102+
const jobs = await getDbCollection("computed_jobs_partners").find({}).toArray()
103+
expect.soft(jobs.length).toEqual(1)
104+
const [job] = jobs
105+
expect.soft(job.jobs_in_success.includes(COMPUTED_ERROR_SOURCE.CLASSIFICATION)).toEqual(true)
106+
})
107+
it("should pass on a job partner with only an offer description", async () => {
108+
// given
109+
await givenSomeComputedJobPartners([
110+
{
111+
partner_job_id,
112+
offer_description,
113+
},
114+
])
115+
// when
116+
await detectClassificationJobsPartners()
117+
// then
118+
const jobs = await getDbCollection("computed_jobs_partners").find({}).toArray()
119+
expect.soft(jobs.length).toEqual(1)
120+
const [job] = jobs
121+
expect.soft(job.jobs_in_success.includes(COMPUTED_ERROR_SOURCE.CLASSIFICATION)).toEqual(true)
122+
})
123+
})

server/src/jobs/offrePartenaire/detectClassificationJobsPartners.ts

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,6 @@ export const detectClassificationJobsPartners = async ({ addedMatchFilter, shoul
1010
const filledFields = ["business_error"] as const satisfies (keyof IComputedJobsPartners)[]
1111
const filters: Filter<IComputedJobsPartners>[] = [
1212
{
13-
workplace_description: { $ne: null },
14-
workplace_name: { $ne: null },
15-
offer_description: { $ne: null },
1613
business_error: null,
1714
},
1815
]
@@ -29,10 +26,10 @@ export const detectClassificationJobsPartners = async ({ addedMatchFilter, shoul
2926
const payload = documents.map((document) => {
3027
const { workplace_description, offer_description, offer_title, workplace_name, partner_job_id, partner_label } = document
3128
return {
32-
workplace_name: workplace_name!,
33-
workplace_description: workplace_description!,
34-
offer_title: offer_title!,
35-
offer_description: offer_description!,
29+
workplace_name: workplace_name ?? undefined,
30+
workplace_description: workplace_description ?? undefined,
31+
offer_title: offer_title ?? undefined,
32+
offer_description: offer_description ?? undefined,
3633
partner_job_id,
3734
partner_label,
3835
}

server/src/services/cacheClassification.service.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,10 @@ import { getDbCollection } from "@/common/utils/mongodbUtils"
77
export type TJobClassification = {
88
partner_label: string
99
partner_job_id: string
10-
workplace_name: string
11-
workplace_description: string
12-
offer_title: string
13-
offer_description: string
10+
workplace_name?: string
11+
workplace_description?: string
12+
offer_title?: string
13+
offer_description?: string
1414
}
1515

1616
const getClassificationFromDB = async (jobs: TJobClassification[]): Promise<(IClassificationJobsPartners | null)[]> => {

0 commit comments

Comments
 (0)