87 lines
3.1 KiB
TypeScript
87 lines
3.1 KiB
TypeScript
import assert from "node:assert/strict";
|
|
import { correlateEventWithServiceSession, normalizeServiceId, serviceEventExternalIds } from "../src/events/record-grow-event.js";
|
|
import { canonicalGrowEventType } from "../src/events/normalize.js";
|
|
import type { GrowEventEnvelope } from "../src/events/envelope.js";
|
|
|
|
const event: GrowEventEnvelope = {
|
|
id: "event-1",
|
|
userId: "user-a",
|
|
source: "interview-service",
|
|
type: "interview.session.completed",
|
|
category: "service",
|
|
occurredAt: "2026-07-14T00:00:00.000Z",
|
|
correlation: { sessionId: "session-1" },
|
|
payload: { status: "completed" },
|
|
};
|
|
|
|
const link = {
|
|
userId: "user-a",
|
|
missionInstanceId: "sprint-1",
|
|
missionId: "curator-sprint",
|
|
stageId: "day-1:interview",
|
|
metadata: { taskId: "curator-task-1" },
|
|
};
|
|
|
|
{
|
|
const correlated = correlateEventWithServiceSession(event, "user-a", link);
|
|
assert.deepEqual(correlated.correlation, {
|
|
sessionId: "session-1",
|
|
taskId: "curator-task-1",
|
|
curatorTaskId: "curator-task-1",
|
|
missionInstanceId: "sprint-1",
|
|
missionId: "curator-sprint",
|
|
stageId: "day-1:interview",
|
|
});
|
|
assert.deepEqual(correlated.mission, {
|
|
instanceId: "sprint-1",
|
|
missionId: "curator-sprint",
|
|
stageId: "day-1:interview",
|
|
});
|
|
}
|
|
|
|
{
|
|
const foreign = correlateEventWithServiceSession(event, "user-a", { ...link, userId: "user-b" });
|
|
assert.strictEqual(foreign, event, "a service session owned by another user must never enrich the event");
|
|
}
|
|
|
|
{
|
|
const unresolved = correlateEventWithServiceSession(event, undefined, link);
|
|
assert.strictEqual(unresolved, event, "an unresolved event must never inherit session context");
|
|
}
|
|
|
|
{
|
|
const explicit = correlateEventWithServiceSession({
|
|
...event,
|
|
mission: { missionId: "explicit-mission", stageId: "explicit-stage" },
|
|
correlation: { sessionId: "session-1", taskId: "explicit-task" },
|
|
}, "user-a", link);
|
|
assert.equal(explicit.correlation?.taskId, "explicit-task");
|
|
assert.deepEqual(explicit.mission, { missionId: "explicit-mission", stageId: "explicit-stage" });
|
|
}
|
|
|
|
{
|
|
assert.deepEqual(serviceEventExternalIds({
|
|
...event,
|
|
correlation: { courseId: "course-1", lesson_id: "lesson-1", externalId: "course-1" },
|
|
subject: { serviceId: "courses-service", externalId: "lesson-1" },
|
|
payload: { resume_id: "resume-1", assessmentId: "assessment-1" },
|
|
}), ["course-1", "lesson-1", "resume-1", "assessment-1"]);
|
|
}
|
|
|
|
{
|
|
assert.equal(normalizeServiceId("social-branding-service"), "brand");
|
|
assert.equal(normalizeServiceId("courses-service"), "course");
|
|
assert.equal(normalizeServiceId("cover-letter-service"), "cover_letter");
|
|
assert.equal(normalizeServiceId("matchmaking-v2"), "matchmaking");
|
|
}
|
|
|
|
{
|
|
assert.equal(canonicalGrowEventType("roleplay.session.completed"), "roleplay.scenario.completed");
|
|
assert.equal(canonicalGrowEventType("roleplay.review.completed"), "roleplay.feedback.generated");
|
|
assert.equal(canonicalGrowEventType("course.video.completed"), "course.completed");
|
|
assert.equal(canonicalGrowEventType("social.profile.synced"), "brand.profile.updated");
|
|
assert.equal(canonicalGrowEventType("resume.analysis.completed"), "resume.analysis.completed");
|
|
}
|
|
|
|
console.log("service session correlation tests passed");
|