fix(assessment): return confirmed categories with their basis and label demonstration categories
This commit is contained in:
1 parent
623d41b969
commit
d4903a3796
77 files changed
+1441
-288
No files matched your search
@@ -17,7 +17,9 @@ function read<T>(
|
||||
return { status, data, error, isRefetching: false, refetch };
|
||||
}
|
||||
|
||||
const profile = { version: 1 } as CandidateProfile;
|
||||
// The home reads only the version and the confirmed categories of the profile.
|
||||
type ProfileHome = Pick<CandidateProfile, "version" | "confirmed_categories">;
|
||||
const profile: ProfileHome = { version: 1, confirmed_categories: [] };
|
||||
const questionnaire = {
|
||||
version: 1,
|
||||
specializations: [
|
||||
@@ -34,7 +36,13 @@ const questionnaire = {
|
||||
} as CandidateQuestionnaire;
|
||||
const availability = {
|
||||
specializations: [
|
||||
{ specialization: "backend", confirmed_grade: null, active_attempt_id: null, grades: [] },
|
||||
{
|
||||
specialization: "backend",
|
||||
confirmed_grade: null,
|
||||
confirmed_basis: null,
|
||||
active_attempt_id: null,
|
||||
grades: [],
|
||||
},
|
||||
],
|
||||
} as AssessmentAvailability;
|
||||
const results = {
|
||||
@@ -75,6 +83,33 @@ describe("combineJourneyReads", () => {
|
||||
}
|
||||
});
|
||||
|
||||
it("passes the profile categories into the journey", () => {
|
||||
const state = combineJourneyReads(
|
||||
"candidate_assessment",
|
||||
read("success", {
|
||||
version: 1,
|
||||
confirmed_categories: [
|
||||
{
|
||||
specialization: "qa",
|
||||
grade: "junior",
|
||||
basis: "synthetic_demo",
|
||||
confirmed_at: "2026-10-08T10:00:00Z",
|
||||
attempt_id: "0199b4f2-7c1e-7d3a-9f00-aabbccddee10",
|
||||
},
|
||||
],
|
||||
}),
|
||||
read("success", questionnaire),
|
||||
read("success", availability),
|
||||
read("success", results),
|
||||
);
|
||||
|
||||
expect(state.status).toBe("success");
|
||||
if (state.status === "success") {
|
||||
expect(state.journey.confirmed.map((standing) => standing.specialization)).toEqual(["qa"]);
|
||||
expect(state.journey.nextStep).toEqual({ kind: "result" });
|
||||
}
|
||||
});
|
||||
|
||||
it("fails as a whole instead of guessing a step from partial data", () => {
|
||||
const failure = apiError(500);
|
||||
const state = combineJourneyReads(
|
||||
|
||||
@@ -21,10 +21,10 @@ import {
|
||||
} from "../../../shared/api/schemas";
|
||||
import { buildCandidateJourney, type CandidateJourney } from "../model/home";
|
||||
|
||||
// The home needs only the version of the profile: 0 means it was never saved.
|
||||
// The profile form validates the rest of the document itself.
|
||||
const profileVersionSchema = CandidateProfile.pick({ version: true });
|
||||
type CandidateProfileVersion = Pick<CandidateProfile, "version">;
|
||||
// The home reads the version of the profile (0 means it was never saved) and
|
||||
// its confirmed categories. The profile form validates the rest of the document.
|
||||
const profileHomeSchema = CandidateProfile.pick({ version: true, confirmed_categories: true });
|
||||
type CandidateProfileHome = Pick<CandidateProfile, "version" | "confirmed_categories">;
|
||||
|
||||
const homeQueryPrefix = ["candidate-home"] as const;
|
||||
|
||||
@@ -94,11 +94,11 @@ function useHomeQuery<T>(
|
||||
}
|
||||
|
||||
export function useCandidateProfileRead(session: Session | undefined) {
|
||||
return useHomeQuery<CandidateProfileVersion>(
|
||||
return useHomeQuery<CandidateProfileHome>(
|
||||
session,
|
||||
candidateHomeQueryKeys.profile,
|
||||
(signal) => getMyProfile({ signal }),
|
||||
profileVersionSchema,
|
||||
profileHomeSchema,
|
||||
);
|
||||
}
|
||||
|
||||
@@ -122,9 +122,10 @@ export function useCandidateAvailabilityRead(session: Session | undefined) {
|
||||
|
||||
/**
|
||||
* The first page of real results, newest first. The home screen shows its
|
||||
* first item as the last result and reads the current category of each
|
||||
* specialization from the newest decision in the same page. The page size is
|
||||
* the maximum of the list endpoint; the full history stays on the results page.
|
||||
* first item as the last result and uses the page only to tell whether the
|
||||
* candidate has a result; the confirmed categories come from the availability
|
||||
* and profile reads. The page size is the maximum of the list endpoint; the
|
||||
* full history stays on the results page.
|
||||
*/
|
||||
export function useCandidateLatestResultRead(session: Session | undefined) {
|
||||
return useHomeQuery<AssessmentResultHistoryPage>(
|
||||
@@ -162,16 +163,16 @@ function isAccessError(error: unknown): boolean {
|
||||
}
|
||||
|
||||
/**
|
||||
* Joins the four reads that the next step depends on: the profile version,
|
||||
* the questionnaire, the assessment availability, and the first page of
|
||||
* results. One failed read fails the whole state, because a step chosen from
|
||||
* partial data could send the candidate to a form they already completed, or
|
||||
* hide a confirmed category. A denied read wins over other failures so that
|
||||
* the forbidden state is shown instead of a retry.
|
||||
* Joins the four reads that the next step depends on: the profile (its version
|
||||
* and confirmed categories), the questionnaire, the assessment availability,
|
||||
* and the first page of results. One failed read fails the whole state, because
|
||||
* a step chosen from partial data could send the candidate to a form they
|
||||
* already completed, or hide a confirmed category. A denied read wins over
|
||||
* other failures so that the forbidden state is shown instead of a retry.
|
||||
*/
|
||||
export function combineJourneyReads(
|
||||
savedStep: CandidateJourney["savedStep"],
|
||||
profile: ReadResult<CandidateProfileVersion>,
|
||||
profile: ReadResult<CandidateProfileHome>,
|
||||
questionnaire: ReadResult<CandidateQuestionnaire>,
|
||||
availability: ReadResult<AssessmentAvailability>,
|
||||
results: ReadResult<AssessmentResultHistoryPage>,
|
||||
@@ -202,6 +203,7 @@ export function combineJourneyReads(
|
||||
journey: buildCandidateJourney({
|
||||
savedStep,
|
||||
profileVersion: profile.data.version,
|
||||
profileCategories: profile.data.confirmed_categories,
|
||||
questionnaire: questionnaire.data,
|
||||
availability: availability.data,
|
||||
results: results.data,
|
||||
|
||||
@@ -7,6 +7,8 @@ import type {
|
||||
} from "../../../shared/api/schemas";
|
||||
import { buildCandidateJourney, summarizeVisibility, type CandidateJourneyInput } from "./home";
|
||||
|
||||
type ProfileCategory = CandidateJourneyInput["profileCategories"][number];
|
||||
|
||||
type Availability = AssessmentAvailability["specializations"][number];
|
||||
|
||||
function gradeRows(status: "available" | "cooldown"): Availability["grades"] {
|
||||
@@ -33,6 +35,7 @@ function availabilityRow(
|
||||
return {
|
||||
specialization,
|
||||
confirmed_grade: options.confirmed ?? null,
|
||||
confirmed_basis: options.confirmed ? "synthetic_demo" : null,
|
||||
active_attempt_id: options.attemptId ?? null,
|
||||
grades: gradeRows(options.status ?? "available"),
|
||||
};
|
||||
@@ -57,27 +60,11 @@ function questionnaire(
|
||||
type ResultRow = CandidateJourneyInput["results"]["items"][number];
|
||||
|
||||
/**
|
||||
* One real result as the results list returns it. A v2 result carries the
|
||||
* category decision with the grade in force when the attempt ended; a legacy
|
||||
* result carries none.
|
||||
* One real result as the results list returns it, with the category decision
|
||||
* that was in force when the attempt ended. The home screen reads the result
|
||||
* list only to tell whether a result exists, so this row never sets a grade.
|
||||
*/
|
||||
function resultRow(
|
||||
specialization: SpecializationCode,
|
||||
options: { grade?: GradeCode | null; decidedAt?: string; legacy?: boolean } = {},
|
||||
): ResultRow {
|
||||
const grade = options.grade ?? null;
|
||||
const decision = options.legacy
|
||||
? {}
|
||||
: {
|
||||
category_decision: {
|
||||
status: grade ? "assigned" : "not_eligible",
|
||||
previous_confirmed_grade: null,
|
||||
current_confirmed_grade: grade,
|
||||
method: grade ? "demo_basic_pass_mark" : null,
|
||||
source: grade ? "synthetic_demo" : null,
|
||||
calibration_status: "uncalibrated",
|
||||
},
|
||||
};
|
||||
function resultRow(specialization: SpecializationCode, grade: GradeCode | null = null): ResultRow {
|
||||
return {
|
||||
kind: "root",
|
||||
attempt_id: "0199b4f2-7c1e-7d3a-9f00-aabbccddee10",
|
||||
@@ -85,15 +72,34 @@ function resultRow(
|
||||
outcome: grade ? "confirmed" : "not_confirmed",
|
||||
confirmed_grade: grade,
|
||||
previous_confirmed_grade: null,
|
||||
decided_at: options.decidedAt ?? "2026-10-08T10:00:00Z",
|
||||
...decision,
|
||||
decided_at: "2026-10-08T10:00:00Z",
|
||||
category_decision: {
|
||||
status: grade ? "assigned" : "not_eligible",
|
||||
previous_confirmed_grade: null,
|
||||
current_confirmed_grade: grade,
|
||||
method: grade ? "demo_basic_pass_mark" : null,
|
||||
source: grade ? "synthetic_demo" : null,
|
||||
calibration_status: "uncalibrated",
|
||||
},
|
||||
} as unknown as ResultRow;
|
||||
}
|
||||
|
||||
/** One confirmed category of the profile read, as the server returns it. */
|
||||
function profileCategory(specialization: SpecializationCode, grade: GradeCode): ProfileCategory {
|
||||
return {
|
||||
specialization,
|
||||
grade,
|
||||
basis: "synthetic_demo",
|
||||
confirmed_at: "2026-10-08T10:00:00Z",
|
||||
attempt_id: "0199b4f2-7c1e-7d3a-9f00-aabbccddee10",
|
||||
};
|
||||
}
|
||||
|
||||
function input(overrides: Partial<CandidateJourneyInput> = {}): CandidateJourneyInput {
|
||||
return {
|
||||
savedStep: "candidate_consents",
|
||||
profileVersion: 0,
|
||||
profileCategories: [],
|
||||
questionnaire: questionnaire([]),
|
||||
availability: { specializations: [] },
|
||||
results: { items: [] },
|
||||
@@ -234,18 +240,18 @@ describe("buildCandidateJourney next step", () => {
|
||||
});
|
||||
});
|
||||
|
||||
// Regression: the availability read reported no confirmed grade for a candidate
|
||||
// whose newest result confirmed Junior, so the next step said "take the test"
|
||||
// while the result block said the category was confirmed.
|
||||
// The confirmed category comes from the availability read and, for a
|
||||
// specialization the questionnaire no longer lists, from the profile read.
|
||||
// A result never sets a grade: the results list only tells whether one exists.
|
||||
describe("buildCandidateJourney confirmed category", () => {
|
||||
it("confirms the category from the newest result when the availability read has none", () => {
|
||||
it("confirms the category from the availability read", () => {
|
||||
const journey = buildCandidateJourney(
|
||||
input({
|
||||
savedStep: "candidate_consents",
|
||||
profileVersion: 1,
|
||||
questionnaire: questionnaire([["backend", "junior"]]),
|
||||
availability: { specializations: [availabilityRow("backend")] },
|
||||
results: { items: [resultRow("backend", { grade: "junior" })] },
|
||||
availability: { specializations: [availabilityRow("backend", { confirmed: "junior" })] },
|
||||
results: { items: [resultRow("backend", "junior")] },
|
||||
}),
|
||||
);
|
||||
|
||||
@@ -258,61 +264,13 @@ describe("buildCandidateJourney confirmed category", () => {
|
||||
expect(journey.hasResults).toBe(true);
|
||||
});
|
||||
|
||||
it("keeps the grade of the availability read when both sources name one", () => {
|
||||
const journey = buildCandidateJourney(
|
||||
input({
|
||||
profileVersion: 1,
|
||||
questionnaire: questionnaire([["backend", "middle"]]),
|
||||
availability: { specializations: [availabilityRow("backend", { confirmed: "middle" })] },
|
||||
results: { items: [resultRow("backend", { grade: "junior" })] },
|
||||
}),
|
||||
);
|
||||
|
||||
expect(journey.standings[0]?.confirmedGrade).toBe("middle");
|
||||
});
|
||||
|
||||
it("takes the grade in force from the newest decision, whatever the order of the page", () => {
|
||||
const journey = buildCandidateJourney(
|
||||
input({
|
||||
profileVersion: 1,
|
||||
questionnaire: questionnaire([["backend", "senior"]]),
|
||||
results: {
|
||||
items: [
|
||||
resultRow("backend", { grade: "junior", decidedAt: "2026-10-01T10:00:00Z" }),
|
||||
resultRow("backend", { grade: "senior", decidedAt: "2026-10-08T10:00:00Z" }),
|
||||
],
|
||||
},
|
||||
}),
|
||||
);
|
||||
|
||||
expect(journey.standings[0]?.confirmedGrade).toBe("senior");
|
||||
});
|
||||
|
||||
it("does not revive an older grade behind a newer decision that confirms none", () => {
|
||||
const journey = buildCandidateJourney(
|
||||
input({
|
||||
profileVersion: 1,
|
||||
questionnaire: questionnaire([["backend", "junior"]]),
|
||||
results: {
|
||||
items: [
|
||||
resultRow("backend", { grade: "junior", decidedAt: "2026-10-01T10:00:00Z" }),
|
||||
resultRow("backend", { grade: null, decidedAt: "2026-10-08T10:00:00Z" }),
|
||||
],
|
||||
},
|
||||
}),
|
||||
);
|
||||
|
||||
expect(journey.confirmed).toEqual([]);
|
||||
expect(journey.nextStep).toEqual({ kind: "assessment" });
|
||||
});
|
||||
|
||||
it("ignores legacy results that carry no category decision", () => {
|
||||
it("takes no grade from a result when the availability read confirms none", () => {
|
||||
const journey = buildCandidateJourney(
|
||||
input({
|
||||
profileVersion: 1,
|
||||
questionnaire: questionnaire([["backend", "junior"]]),
|
||||
availability: { specializations: [availabilityRow("backend")] },
|
||||
results: { items: [resultRow("backend", { grade: "junior", legacy: true })] },
|
||||
results: { items: [resultRow("backend", "junior")] },
|
||||
}),
|
||||
);
|
||||
|
||||
@@ -321,12 +279,25 @@ describe("buildCandidateJourney confirmed category", () => {
|
||||
expect(journey.nextStep).toEqual({ kind: "assessment" });
|
||||
});
|
||||
|
||||
it("keeps the availability grade when the profile names another one", () => {
|
||||
const journey = buildCandidateJourney(
|
||||
input({
|
||||
profileVersion: 1,
|
||||
questionnaire: questionnaire([["backend", "middle"]]),
|
||||
availability: { specializations: [availabilityRow("backend", { confirmed: "middle" })] },
|
||||
profileCategories: [profileCategory("backend", "junior")],
|
||||
}),
|
||||
);
|
||||
|
||||
expect(journey.standings[0]?.confirmedGrade).toBe("middle");
|
||||
});
|
||||
|
||||
it("keeps a confirmed category visible when the questionnaire no longer lists it", () => {
|
||||
const journey = buildCandidateJourney(
|
||||
input({
|
||||
profileVersion: 1,
|
||||
questionnaire: questionnaire([]),
|
||||
results: { items: [resultRow("qa", { grade: "junior" })] },
|
||||
profileCategories: [profileCategory("qa", "junior")],
|
||||
}),
|
||||
);
|
||||
|
||||
|
||||
@@ -2,6 +2,7 @@ import type {
|
||||
Account,
|
||||
AssessmentAvailability,
|
||||
AssessmentResultHistoryPage,
|
||||
CandidateProfile,
|
||||
CandidateQuestionnaire,
|
||||
GradeCode,
|
||||
PrivacySettings,
|
||||
@@ -49,6 +50,8 @@ export type CandidateJourneyInput = {
|
||||
savedStep: OnboardingStep;
|
||||
/** `version` of the profile read; 0 means it was never saved. */
|
||||
profileVersion: number;
|
||||
/** `confirmed_categories` of the profile read, in catalog order. */
|
||||
profileCategories: CandidateProfile["confirmed_categories"];
|
||||
questionnaire: Pick<CandidateQuestionnaire, "version" | "specializations">;
|
||||
availability: Pick<AssessmentAvailability, "specializations">;
|
||||
/** The first page of the candidate's real results, newest first. */
|
||||
@@ -67,48 +70,25 @@ export type CandidateJourney = {
|
||||
nextStep: CandidateNextStep;
|
||||
};
|
||||
|
||||
type ResultItem = AssessmentResultHistoryPage["items"][number];
|
||||
|
||||
/**
|
||||
* Grade in force for each specialization, read from the newest result of that
|
||||
* specialization. A v2 result records the grade in force when its attempt
|
||||
* ended, so the newest decision is the current category. A legacy result has
|
||||
* no decision and yields no grade; a result that confirms no grade leaves the
|
||||
* specialization unconfirmed. Older results never override a newer decision.
|
||||
* Standings of the questionnaire specializations and of the confirmed
|
||||
* categories. The confirmed grade comes from the availability read, which
|
||||
* answers for every questionnaire specialization. A category whose
|
||||
* specialization the questionnaire no longer lists comes from the profile read,
|
||||
* so a confirmed grade never disappears from the home screen. Results are not a
|
||||
* source of the grade: the home takes the category from the server's current
|
||||
* state only.
|
||||
*/
|
||||
export function currentGradesFromResults(
|
||||
results: readonly ResultItem[],
|
||||
): Map<SpecializationCode, GradeCode> {
|
||||
// The server lists results newest first; sorting here keeps the rule local.
|
||||
const newestFirst = [...results].sort((left, right) =>
|
||||
right.decided_at.localeCompare(left.decided_at),
|
||||
);
|
||||
const grades = new Map<SpecializationCode, GradeCode>();
|
||||
const decided = new Set<SpecializationCode>();
|
||||
for (const result of newestFirst) {
|
||||
if (decided.has(result.specialization)) continue;
|
||||
decided.add(result.specialization);
|
||||
const grade = result.category_decision?.current_confirmed_grade ?? null;
|
||||
if (grade !== null) grades.set(result.specialization, grade);
|
||||
}
|
||||
return grades;
|
||||
}
|
||||
|
||||
function buildStandings(
|
||||
input: CandidateJourneyInput,
|
||||
resultGrades: ReadonlyMap<SpecializationCode, GradeCode>,
|
||||
): SpecializationStanding[] {
|
||||
function buildStandings(input: CandidateJourneyInput): SpecializationStanding[] {
|
||||
const standings = new Map<SpecializationCode, SpecializationStanding>();
|
||||
const listedByAvailability = new Set<SpecializationCode>();
|
||||
|
||||
// The availability list is the server's view of the questionnaire
|
||||
// specializations; the questionnaire adds the declared grade. The current
|
||||
// confirmed grade comes from the availability read when it has one, and from
|
||||
// the newest result of the specialization otherwise.
|
||||
for (const item of input.availability.specializations) {
|
||||
listedByAvailability.add(item.specialization);
|
||||
standings.set(item.specialization, {
|
||||
specialization: item.specialization,
|
||||
declaredGrade: null,
|
||||
confirmedGrade: item.confirmed_grade ?? resultGrades.get(item.specialization) ?? null,
|
||||
confirmedGrade: item.confirmed_grade ?? null,
|
||||
activeAttemptId: item.active_attempt_id,
|
||||
canStartAttempt: item.grades.some((grade) => grade.status === "available"),
|
||||
});
|
||||
@@ -118,21 +98,20 @@ function buildStandings(
|
||||
standings.set(item.specialization, {
|
||||
specialization: item.specialization,
|
||||
declaredGrade: item.self_assessed_grade,
|
||||
confirmedGrade: existing?.confirmedGrade ?? resultGrades.get(item.specialization) ?? null,
|
||||
confirmedGrade: existing?.confirmedGrade ?? null,
|
||||
activeAttemptId: existing?.activeAttemptId ?? null,
|
||||
canStartAttempt: existing?.canStartAttempt ?? false,
|
||||
});
|
||||
}
|
||||
// A result can name a specialization that the current questionnaire no
|
||||
// longer lists. Its confirmed grade is still a fact, so it stays visible.
|
||||
for (const [specialization, grade] of resultGrades) {
|
||||
if (standings.has(specialization)) continue;
|
||||
standings.set(specialization, {
|
||||
specialization,
|
||||
declaredGrade: null,
|
||||
confirmedGrade: grade,
|
||||
activeAttemptId: null,
|
||||
canStartAttempt: false,
|
||||
for (const category of input.profileCategories) {
|
||||
if (listedByAvailability.has(category.specialization)) continue;
|
||||
const existing = standings.get(category.specialization);
|
||||
standings.set(category.specialization, {
|
||||
specialization: category.specialization,
|
||||
declaredGrade: existing?.declaredGrade ?? null,
|
||||
confirmedGrade: category.grade,
|
||||
activeAttemptId: existing?.activeAttemptId ?? null,
|
||||
canStartAttempt: existing?.canStartAttempt ?? false,
|
||||
});
|
||||
}
|
||||
return [...standings.values()];
|
||||
@@ -145,14 +124,14 @@ function buildStandings(
|
||||
* questionnaire is saved from the matching step, so a saved profile can sit
|
||||
* behind an earlier stored step. Presence of saved data therefore decides
|
||||
* between the profile, the questionnaire, and the test. Facts about the
|
||||
* category and the test come only from the availability and results reads.
|
||||
* category and the test come only from the availability, profile, and results
|
||||
* reads.
|
||||
*
|
||||
* The client invents no category, grade, or threshold: a category exists only
|
||||
* when the availability read or the newest result returns a confirmed grade.
|
||||
* when the availability read or the profile read returns a confirmed grade.
|
||||
*/
|
||||
export function buildCandidateJourney(input: CandidateJourneyInput): CandidateJourney {
|
||||
const resultGrades = currentGradesFromResults(input.results.items);
|
||||
const standings = buildStandings(input, resultGrades);
|
||||
const standings = buildStandings(input);
|
||||
const confirmed = standings.filter((standing) => standing.confirmedGrade !== null);
|
||||
const profileSaved = input.profileVersion > 0;
|
||||
const questionnaireSaved =
|
||||
|
||||
Reference in new issue
Block a user