-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: LBA-2137 LBA-2139 tracking referer et utm (#1556)
* feat: model new collection * feat: setting tracking cookie * feat: saving application source info * feat: prise en compte utm_source utm_medium * feat: save en service * feat: save source sur création user * chore: tree shaking * feat: enregistrement hash email * feat: avec tests et nom collection normalisé * Update server/src/services/application.service.ts Co-authored-by: Rémy Auricoste <[email protected]> * feat: unused export --------- Co-authored-by: Rémy Auricoste <[email protected]>
- Loading branch information
1 parent
a9fd623
commit 1b0d8c1
Showing
16 changed files
with
324 additions
and
38 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,133 @@ | ||
import { useMongo } from "@tests/utils/mongo.test.utils" | ||
import { ObjectId } from "mongodb" | ||
import { TrafficType } from "shared/models" | ||
import { beforeEach, describe, expect, it } from "vitest" | ||
|
||
import { getDbCollection } from "@/common/utils/mongodbUtils" | ||
|
||
import { hashEmail, saveApplicationTrafficSourceIfAny, saveUserTrafficSourceIfAny } from "./trafficSource.service" | ||
|
||
useMongo() | ||
|
||
describe("Recording traffic source", () => { | ||
beforeEach(async () => { | ||
return async () => { | ||
await getDbCollection("trafficsources").deleteMany({}) | ||
} | ||
}) | ||
|
||
it("Le hash est consistant", async () => { | ||
const result1 = hashEmail("[email protected]") | ||
const result2 = hashEmail("[email protected]") | ||
const result3 = hashEmail("[email protected]") | ||
|
||
expect.soft(result1).toEqual(result2) | ||
expect.soft(result1).not.toEqual(result3) | ||
}) | ||
|
||
it("Un sourceTracking est enregistré si referer", async () => { | ||
const application_id = new ObjectId() | ||
await saveApplicationTrafficSourceIfAny({ | ||
application_id, | ||
applicant_email: "[email protected]", | ||
source: { | ||
referer: "referer1", | ||
utm_campaign: null, | ||
utm_medium: null, | ||
utm_source: null, | ||
}, | ||
}) | ||
|
||
const result = await getDbCollection("trafficsources").findOne({ application_id }) | ||
|
||
expect.soft(result).toEqual( | ||
expect.objectContaining({ | ||
referer: "referer1", | ||
utm_campaign: null, | ||
utm_medium: null, | ||
utm_source: null, | ||
applicant_email_hash: hashEmail("[email protected]"), | ||
user_id: null, | ||
traffic_type: TrafficType.APPLICATION, | ||
}) | ||
) | ||
}) | ||
|
||
it("Un sourceTracking est enregistré si utm_campaign", async () => { | ||
const user_id_entreprise = new ObjectId() | ||
await saveUserTrafficSourceIfAny({ | ||
user_id: user_id_entreprise, | ||
type: TrafficType.ENTREPRISE, | ||
source: { | ||
referer: null, | ||
utm_campaign: "campaign", | ||
utm_medium: "medium", | ||
utm_source: "source", | ||
}, | ||
}) | ||
|
||
const user_id_cfa = new ObjectId() | ||
await saveUserTrafficSourceIfAny({ | ||
user_id: user_id_cfa, | ||
type: TrafficType.CFA, | ||
source: { | ||
referer: "referer2", | ||
utm_campaign: "campaign", | ||
utm_medium: "medium", | ||
utm_source: "source", | ||
}, | ||
}) | ||
|
||
const resultEntreprise = await getDbCollection("trafficsources").findOne({ user_id: user_id_entreprise }) | ||
|
||
expect.soft(resultEntreprise).toEqual( | ||
expect.objectContaining({ | ||
referer: null, | ||
utm_campaign: "campaign", | ||
utm_medium: "medium", | ||
utm_source: "source", | ||
traffic_type: TrafficType.ENTREPRISE, | ||
applicant_email_hash: null, | ||
user_id: user_id_entreprise, | ||
}) | ||
) | ||
|
||
const resultCfa = await getDbCollection("trafficsources").findOne({ user_id: user_id_cfa }) | ||
|
||
expect.soft(resultCfa).toEqual( | ||
expect.objectContaining({ | ||
referer: "referer2", | ||
utm_campaign: "campaign", | ||
utm_medium: "medium", | ||
utm_source: "source", | ||
applicant_email_hash: null, | ||
traffic_type: TrafficType.CFA, | ||
user_id: user_id_cfa, | ||
}) | ||
) | ||
}) | ||
|
||
it("Aucun sourcetracking enregistré si ni referer ni campaign", async () => { | ||
const application_id = new ObjectId() | ||
|
||
const countBefore = await getDbCollection("trafficsources").countDocuments({}) | ||
|
||
await saveApplicationTrafficSourceIfAny({ | ||
application_id, | ||
applicant_email: "[email protected]", | ||
source: { | ||
referer: null, | ||
utm_campaign: null, | ||
utm_medium: null, | ||
utm_source: null, | ||
}, | ||
}) | ||
|
||
const countAfter = await getDbCollection("trafficsources").countDocuments({}) | ||
|
||
const result = await getDbCollection("trafficsources").findOne({ application_id }) | ||
|
||
expect.soft(countBefore).toEqual(countAfter) | ||
expect.soft(result).toEqual(null) | ||
}) | ||
}) |
Oops, something went wrong.