Skip to content

Commit

Permalink
feat: test cancel ok (#1719)
Browse files Browse the repository at this point in the history
  • Loading branch information
alanlr authored Dec 18, 2024
1 parent 364fa57 commit add74ed
Showing 1 changed file with 24 additions and 16 deletions.
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

0 comments on commit add74ed

Please sign in to comment.