Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: test job cancel ok #1719

Merged
merged 1 commit into from
Dec 18, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 24 additions & 16 deletions server/src/jobs/offrePartenaire/cancelRemovedJobsPartners.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { JOB_STATUS_ENGLISH } from "shared/models"
import { JOBPARTNERS_LABEL } from "shared/models/jobsPartners.model"
import { beforeEach, describe, expect, it } from "vitest"

import { getDbCollection } from "@/common/utils/mongodbUtils"
Expand All @@ -15,39 +16,46 @@ describe("Canceling jobs_partners that have been removed from computed_jobs_part
// 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 })
await createJobPartner({ partner_job_id: "existing_1", partner_label: "bidon", offer_status: JOB_STATUS_ENGLISH.ACTIVE })
await createJobPartner({ partner_job_id: "existing_2", partner_label: JOBPARTNERS_LABEL.RH_ALTERNANCE, offer_status: JOB_STATUS_ENGLISH.ACTIVE })
await createJobPartner({ partner_job_id: "existing_3", partner_label: JOBPARTNERS_LABEL.HELLOWORK, offer_status: JOB_STATUS_ENGLISH.ACTIVE })
await createJobPartner({ partner_job_id: "existing_4", partner_label: JOBPARTNERS_LABEL.HELLOWORK, offer_status: JOB_STATUS_ENGLISH.ACTIVE })
await createJobPartner({ partner_job_id: "existing_5", partner_label: JOBPARTNERS_LABEL.HELLOWORK, offer_status: JOB_STATUS_ENGLISH.ACTIVE })

await createComputedJobPartner({ partner_job_id: "computed_1", partner_label: JOBPARTNERS_LABEL.RH_ALTERNANCE, validated: true })
await createComputedJobPartner({ partner_job_id: "computed_2", partner_label: JOBPARTNERS_LABEL.RH_ALTERNANCE, validated: false })
await createComputedJobPartner({ partner_job_id: "existing_3", partner_label: JOBPARTNERS_LABEL.HELLOWORK, validated: true })
await createComputedJobPartner({ partner_job_id: "existing_4", partner_label: JOBPARTNERS_LABEL.HELLOWORK, validated: true })

return async () => {
await getDbCollection("computed_jobs_partners").deleteMany({})
await getDbCollection("jobs_partners").deleteMany({})
}
})

it.skip("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 () => {
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"] },
partner_job_id: { $in: ["existing_2", "existing_5"] },
offer_status: JOB_STATUS_ENGLISH.ANNULEE,
})
expect.soft(countCanceledJobsPartners).toEqual(2)

// les éléments de jobs_partners qui ne sont pas des collections à vérifier sont intouchés
const countNotCanceledJobsPartners = await getDbCollection("jobs_partners").countDocuments({
partner_job_id: { $in: ["existing_1"] },
offer_status: JOB_STATUS_ENGLISH.ACTIVE,
})
expect.soft(countNotCanceledJobsPartners).toEqual(1)

// 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"] },
const countRemainingActiveJobsPartners = await getDbCollection("jobs_partners").countDocuments({
partner_job_id: { $in: ["existing_1", "existing_3", "existing_4"] },
offer_status: JOB_STATUS_ENGLISH.ACTIVE,
})
expect.soft(countRemainingJobsPartners).toEqual(3)
expect.soft(countRemainingActiveJobsPartners).toEqual(3)

// aucun éléments de jobs_partners n'a été retiré de la collection
const countJobsPartners = await getDbCollection("jobs_partners").countDocuments({})
Expand Down
Loading