| 
 | 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 | +})  | 
0 commit comments