Skip to content

Commit

Permalink
feat: update test & services
Browse files Browse the repository at this point in the history
  • Loading branch information
kevbarns committed Dec 19, 2024
1 parent 6685379 commit 343e99a
Show file tree
Hide file tree
Showing 11 changed files with 61 additions and 61 deletions.
2 changes: 1 addition & 1 deletion .talismanrc
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ fileignoreconfig:
- filename: shared/constants/recruteur.ts
checksum: af4631fe998b78b13691dbc821a8ffa71ffc2f4cb6967361cb5ef19965dc95cb
- filename: shared/fixtures/application.fixture.ts
checksum: 4c4590586b8c5683ce7aebb32d2286af3265bb9d3d39581f6d7a1f8ed1a2850d
checksum: 5f77b1127060f10911006a797590a7ff36f81ca61dbc0567049bc4e866e17c89
- filename: shared/fixtures/appointment.fixture.ts
checksum: 8b894b4059d8f7531e26f249901b83dbec433d4e660c0eca193c8e61572b3ae0
- filename: shared/fixtures/recruiter.fixture.ts
Expand Down
2 changes: 2 additions & 0 deletions server/src/http/controllers/application.controller.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,10 +84,12 @@ describe("POST /v1/application", () => {
})

const applications = await getDbCollection("applications").find({}).toArray()
const applicant = await getDbCollection("applicants").findOne({ _id: applications[0]?.applicant_id })

expect(applications).toEqual([
{
_id: expect.any(ObjectId),
applicant_id: applicant?._id,
applicant_attachment_name: body.applicant_file_name,
applicant_email: body.applicant_email,
applicant_first_name: body.applicant_first_name,
Expand Down
8 changes: 8 additions & 0 deletions server/src/http/controllers/application.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { oldItemTypeToNewItemType } from "shared/constants/lbaitem"
import { zRoutes } from "shared/index"

import { getDbCollection } from "../../common/utils/mongodbUtils"
import { getApplicantFromDB } from "../../services/applicant.service"
import { getCompanyEmailFromToken, sendApplication, sendMailToApplicant } from "../../services/application.service"
import { Server } from "../server"

Expand Down Expand Up @@ -69,8 +70,15 @@ export default function (server: Server) {
throw notFound()
}

const applicant = await getApplicantFromDB({ _id: application.applicant_id })

if (!applicant) {
throw notFound(`unexpected: applicant not found for application ${application._id}`)
}

await sendMailToApplicant({
application,
applicant,
email,
phone,
company_recruitment_intention,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -136,12 +136,14 @@ describe("POST /v2/application", () => {
})

const application = await getDbCollection("applications").findOne({ company_siret: recruteur.siret })
const applicant = await getDbCollection("applicants").findOne({ _id: application?.applicant_id })

expect.soft(response.statusCode).toEqual(202)
expect.soft(response.json()).toEqual({ id: application!._id.toString() })

expect(application).toEqual({
_id: expect.any(ObjectId),
applicant_id: applicant?._id,
applicant_attachment_name: body.applicant_attachment_name,
applicant_email: body.applicant_email,
applicant_first_name: body.applicant_first_name,
Expand Down Expand Up @@ -192,12 +194,14 @@ describe("POST /v2/application", () => {
})

const application = await getDbCollection("applications").findOne({ job_id: job._id.toString() })
const applicant = await getDbCollection("applicants").findOne({ _id: application?.applicant_id })

expect.soft(response.statusCode).toEqual(202)
expect.soft(response.json()).toEqual({ id: application!._id.toString() })

expect(application).toEqual({
_id: expect.any(ObjectId),
applicant_id: applicant?._id,
applicant_attachment_name: body.applicant_attachment_name,
applicant_email: body.applicant_email,
applicant_first_name: body.applicant_first_name,
Expand Down
4 changes: 4 additions & 0 deletions server/src/jobs/applications/processApplications.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,10 @@ const processApplicationGroup = async (applicationFilter: Filter<IApplication>,
return
}
const applicant = await getApplicantFromDB({ _id: application.applicant_id })
if (!applicant) {
await getDbCollection("applications").findOneAndUpdate({ _id: application._id }, { $set: { scan_status: ApplicationScanStatus.ERROR_APPLICANT_NOT_FOUND } })
return
}
try {
let hasVirus: boolean = false
if (application.scan_status !== ApplicationScanStatus.NO_VIRUS_DETECTED) {
Expand Down
5 changes: 0 additions & 5 deletions server/src/jobs/simpleJobDefinitions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ import { opcoReminderJob } from "./recruiters/opcoReminderJob"
import { updateMissingStartDate } from "./recruiters/updateMissingStartDateJob"
import { updateSiretInfosInError } from "./recruiters/updateSiretInfosInErrorJob"
import { importReferentielRome } from "./referentielRome/referentielRome"
import { migrationTest } from "./test"

type SimpleJobDefinition = {
fct: () => Promise<unknown>
Expand Down Expand Up @@ -216,8 +215,4 @@ export const simpleJobDefinitions: SimpleJobDefinition[] = [
fct: processJobPartners,
description: "Chaîne complète de traitement des jobs_partners",
},
{
fct: migrationTest,
description: "test",
},
]
41 changes: 0 additions & 41 deletions server/src/jobs/test.ts

This file was deleted.

4 changes: 2 additions & 2 deletions server/src/services/application.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -914,7 +914,7 @@ export const getApplicationByCompanyCount = async (sirets: ILbaCompany["siret"][
* if hardbounce event si related to an application sent to a compay then
* warns the applicant and returns true otherwise returns false
*/
export const processApplicationHardbounceEvent = async (payload, sendNotificationToApplicant = notifyHardbounceToApplicant) => {
export const processApplicationHardbounceEvent = async (payload, sendNotificationToApplicant: any = notifyHardbounceToApplicant) => {
const { email } = payload
const messageId = payload["message-id"]

Expand All @@ -936,7 +936,7 @@ export const processApplicationCandidateHardbounceEvent = async (payload) => {
const messageId = payload["message-id"]

const applicant = await getDbCollection("applicants").findOne({ email })
const application = await getDbCollection("applications").findOne({ applicant_id: applicant!._id, to_applicant_message_id: messageId })
const application = await getDbCollection("applications").findOne({ applicant_id: applicant?._id, to_applicant_message_id: messageId })

if (application) {
return true
Expand Down
29 changes: 19 additions & 10 deletions server/src/services/emails.service.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { EApplicantRole } from "shared/constants/rdva"
import { generateApplicationFixture } from "shared/fixtures/application.fixture"
import { generateApplicantFixture, generateApplicationFixture } from "shared/fixtures/application.fixture"
import { generateAppointmentFixture, generateEligibleTrainingEstablishmentFixture, generateEligibleTrainingFixture } from "shared/fixtures/appointment.fixture"
import { generateUserFixture } from "shared/fixtures/user.fixture"
import { generateUserWithAccountFixture } from "shared/fixtures/userWithAccount.fixture"
Expand All @@ -16,6 +16,7 @@ import { IBrevoWebhookEvent, processHardBounceWebhookEvent } from "./emails.serv
async function cleanTest() {
await getDbCollection("emailblacklists").deleteMany({})
await getDbCollection("applications").deleteMany({})
await getDbCollection("applicants").deleteMany({})
await getDbCollection("recruteurslba").deleteMany({})
await getDbCollection("etablissements").deleteMany({})
await getDbCollection("users").deleteMany({})
Expand All @@ -25,15 +26,7 @@ async function cleanTest() {

describe("email blaklist events", () => {
useMongo()

beforeEach(async () => {
return async () => {
await cleanTest()
}
})

const blacklistedEmail = "blacklisted@email.com"

const fakeMessageId_1 = "<fake_id@domain.net>"

const baseWebHookPayload: IBrevoWebhookEvent = {
Expand All @@ -59,13 +52,21 @@ describe("email blaklist events", () => {
},
]

beforeEach(async () => {
return async () => {
await cleanTest()
}
})

it("Non 'blocked' event shoud throw an error", async () => {
baseWebHookPayload.event = BrevoEventStatus.DELIVRE
await expect.soft(processHardBounceWebhookEvent(baseWebHookPayload)).rejects.toThrow("Non hardbounce event received on hardbounce webhook route")
})

it("Unidentified hardbounce should register campaign origin", async () => {
baseWebHookPayload.event = BrevoEventStatus.HARD_BOUNCE
const applicant = generateApplicantFixture({ email: blacklistedEmail })
await getDbCollection("applicants").insertOne(applicant)
await processHardBounceWebhookEvent(baseWebHookPayload)

const blEvent = await getDbCollection("emailblacklists").findOne({ email: blacklistedEmail })
Expand All @@ -90,7 +91,11 @@ describe("email blaklist events", () => {
})

it("Applicant blocked should register candidature_spontanee_candidat (blocked)", async () => {
await getDbCollection("applications").insertOne(generateApplicationFixture({ applicant_email: blacklistedEmail, to_applicant_message_id: fakeMessageId_1 }))
const applicant = generateApplicantFixture({ email: blacklistedEmail })
await getDbCollection("applicants").insertOne(applicant)
await getDbCollection("applications").insertOne(
generateApplicationFixture({ applicant_id: applicant._id, applicant_email: blacklistedEmail, to_applicant_message_id: fakeMessageId_1 })
)
baseWebHookPayload.event = BrevoEventStatus.BLOCKED
baseWebHookPayload["message-id"] = fakeMessageId_1

Expand All @@ -107,6 +112,8 @@ describe("email blaklist events", () => {

it("Unsubscribed variation events should register correct origin with (unsubscribed) reason", async () => {
baseBlockedAddress[0].reason.code = BrevoBlockedReasons.UNSUBSCRIBED_VIA_API
const applicant = generateApplicantFixture({ email: blacklistedEmail })
await getDbCollection("applicants").insertOne(applicant)
await getDbCollection("applications").insertOne(generateApplicationFixture({ applicant_email: blacklistedEmail }))

await saveBlacklistEmails(baseBlockedAddress)
Expand Down Expand Up @@ -179,6 +186,8 @@ describe("email blaklist events", () => {
})

it("Recruteur LBA with SPAM (plainte) should register candidature_spontanee_recruteur (spam)", async () => {
const applicant = generateApplicantFixture({ email: blacklistedEmail })
await getDbCollection("applicants").insertOne(applicant)
await getDbCollection("applications").insertOne(generateApplicationFixture({ company_email: blacklistedEmail, to_company_message_id: fakeMessageId_1 }))
baseWebHookPayload.event = BrevoEventStatus.SPAM
baseWebHookPayload["message-id"] = fakeMessageId_1
Expand Down
20 changes: 18 additions & 2 deletions shared/fixtures/application.fixture.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
import { ObjectId } from "bson"

import { LBA_ITEM_TYPE } from "../constants/lbaitem"
import { ApplicationScanStatus, IApplication } from "../models"
import { ApplicationScanStatus, IApplicant, IApplication } from "../models"

export function generateApplicationFixture(data: Partial<IApplication>): IApplication {
const applicant = generateApplicantFixture()
return {
_id: new ObjectId(),
applicant_email: "test@test.fr",
applicant_id: applicant._id,
applicant_email: "applicant@mail.fr",
applicant_first_name: "a",
applicant_last_name: "a",
applicant_phone: "0125252525",
Expand All @@ -33,6 +35,20 @@ export function generateApplicationFixture(data: Partial<IApplication>): IApplic
}
}

export function generateApplicantFixture(data: Partial<IApplicant> = {}): IApplicant {
return {
_id: new ObjectId(),
firstname: "applicant_firstname",
lastname: "applicant_lastname",
phone: "0123456789",
email: "applicant@mail.fr",
last_connection: new Date("2024-07-28T03:05:34.187Z"),
createdAt: new Date("2024-07-28T03:05:34.187Z"),
updatedAt: new Date("2024-07-28T03:05:34.187Z"),
...data,
}
}

export const applicationTestFile =
"data:application/pdf;base64,JVBERi0xLjQKJeLjz9MKNCAwIG9iago8PC9MZW5ndGggMTg2OS9GaWx0ZXIvRmxhdGVEZWNvZGU+PnN0cmVhbQp4nKWazXLbNhDH73oKHJ2ZmMYHQZC5Of6qWydOJCWnXDQx7VFHlmtZapNbX69v0avfogCJJbgAlK4nB48l7W+xPzL82wbDx8nb+URqVkvD5jeTsimLUrFDUbp3R+eCuVe3k4PzxdftbtO+mv8+OfQQd4guRSEEO+SFcG8PWEf4TzuCR0Xef1zyshAVTDqYtrcFe8NOTi+lFJJrxauqH9ZzLx52dC7BfTxWmboozTD25P7GjXUzpRa1qN9X/D3vlvXkzx2lquypKodxp4tty267U7nYLh/WbnR1JOSR5FL2U/uGn5xa6qKWw9R3D+vtYr19Yu23PzbL+2f7Ys3OdpuHJ/bl4O8vr/rBfQ99sNCykP61Gl404cOq6tvP5pOPk8fuS7JfbeViwgvN/prIxtjvlVBFw6SR9nVd2u5NO5lZ2l6XbhhnwhaZUZ3M/fiadFZ28THYNHYVImsXFZK+KI21i/JhumR1x53dt9ttu9uwN3tXT5uObzbt09Mz+zffxSr7rwU6sus4vf589u6YzY5nn/IdVQUjfIfi7O3ljG12LbtYbhabm3yf5lFfowTnzF1Xm3a3XOW7VBl15TFRR9j51PZqXkpZS8XTJsWFu2ySw79q2XT3vd2y49VivbctOQdCGNvXspv2Rwfku5MzYTS3mfhwPL2c7W1KTsT5ZrH+2noeJwNd97Vr13Vj8/F/Z7JHjdqHZvNnO7RNvQ+f/SnbRW8czr5uy5WJ6srYK9Z4QPAmKpemCeWGF7WK17eLC1e8Dx6reDoAI5dVYuAhJBQobfiAdK99HQR9CfmuxpalDShYipzlAIycE0uAkDS2BCQYD5ZQQtLYslZg2cOJJQAj59TSQ0g6svRIMA6WvoSksWVlBssOTiwBGDmnlh5C0pGlR4JxsPQlJI0ttRgsOzixBGDknFp6CElHlh4JxsHSl5A0tlRDeno4sVTj9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udCAxL0tpZHNbNiAwIFJdPj4KZW5kb2JqCjcgMCBvYmoKPDwvVHlwZS9DYXRhbG9nL1BhZ2VzIDUgMCBSPj4KZW5kb2JqCjggMCBvYmoKPDwvUHJvZHVjZXIoaVRleHRTaGFycJIgNS41LjEwIKkyMDAwLTIwMTYgaVRleHQgR3JvdXAgTlYgXChBR1BMLXZlcnNpb25cKSkvQ3JlYXRpb25EYXRlKEQ6MjAyMzA1MTEwOTMwMjUrMDInMDAnKS9Nb2REYXRlKEQ6MjAyMzA1MTEwOTMwMjUrMDInMDAnKT4+CmVuZG9iagp4cmVmCjAgOQowMDAwMDAwMDAwIDY1NTM1IGYgCjAwMDAwMDIwODIgMDAwMDAgbiAKMDAwMDAwMjE3NSAwMDAwMCBuIAowMDAwMDAyMjYzIDAwMDAwIG4gCjAwMDAwMDAwMTUgMDAwMDAgbiAKMDAwMDAwMjM1MyAwMDAwMCBuIAowMDAwMDAxOTUyIDAwMDAwIG4gCjAwMDAwMDI0MDQgMDAwMDAgbiAKMDAwMDAwMjQ0OSAwMDAwMCBuIAp0cmFpbGVyCjw8L1NpemUgOS9Sb290IDcgMCBSL0luZm8gOCAwIFIvSUQgWzwwYTE1N2MxMDBiMDJiMzBjYzZmNTRmMGE4ZWJhYWMzYT48MGExNTdjMTAwYjAyYjMwY2M2ZjU0ZjBhOGViYWFjM2E+XT4+CiVpVGV4dC01LjUuMTAKc3RhcnR4cmVmCjI2MTIKJSVFT0YK"

Expand Down
3 changes: 3 additions & 0 deletions shared/models/applications.model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ export enum ApplicationScanStatus {
ERROR_CLAMAV = "ERROR_CLAMAV",
NO_VIRUS_DETECTED = "NO_VIRUS_DETECTED",
DO_NOT_SEND = "DO_NOT_SEND",
ERROR_APPLICANT_NOT_FOUND = "ERROR_APPLICANT_NOT_FOUND",
}

export const ZApplication = z
Expand Down Expand Up @@ -112,6 +113,7 @@ export const ZNewApplication = ZApplication.extend({
})
.omit({
_id: true,
applicant_id: true,
applicant_message_to_company: true,
applicant_attachment_name: true,
job_origin: true,
Expand Down Expand Up @@ -157,6 +159,7 @@ const ZNewApplicationTransitionToV2 = ZApplication.extend({
})
.omit({
_id: true,
applicant_id: true,
applicant_message_to_company: true,
applicant_attachment_name: true,
job_origin: true,
Expand Down

0 comments on commit 343e99a

Please sign in to comment.