fix(demo): advance seeded candidates past onboarding and show the express summary in Russian

This commit is contained in:
shira committed 2026-10-10 01:39:58 +03:00
1 parent 41206abbcf
commit 945ab6d6a9
9 files changed
+296 -10

No files matched your search

+80 -2
View File
@@ -224,13 +224,14 @@ func TestDemoSeedCommand(t *testing.T) {
}
second, err := stand.run(t, nil, "seed", "--actor", "operator:another-operator")
if err != nil || !strings.Contains(second, "created 0 records") {
t.Fatalf("second seed = %q, %v, want nothing created", second, err)
if err != nil || !strings.Contains(second, "created 0 records") || strings.Contains(second, "updated:") {
t.Fatalf("second seed = %q, %v, want nothing created or updated", second, err)
}
if afterSecond := stand.inventory(t); afterSecond != afterFirst {
t.Fatalf("inventory changed on the repeat:\nfirst:\n%s\nsecond:\n%s", afterFirst, afterSecond)
}
assertDemoSeedOnboarding(t, stand)
assertDemoSeedMarkers(t, stand)
assertDemoSeedPermissions(t, stand)
assertDemoSeedVisibleCohort(t, stand)
@@ -252,6 +253,79 @@ func TestDemoSeedCommand(t *testing.T) {
t.Fatal("the visitor account changed")
}
})
t.Run("repairs the onboarding step of a stand seeded before the step was set", func(t *testing.T) {
stand := newDemoSeedStand(ctx, t, env)
first, err := stand.run(t, nil, "seed", "--actor", demoSeedActor)
if err != nil {
t.Fatalf("first seed error = %v (output %q)", err, first)
}
afterFirst := stand.inventory(t)
// An earlier seed left every candidate at the consent step. One prepared
// candidate has moved on to a later step, which a repair must keep.
if _, err := stand.pool.Exec(stand.ctx, `
UPDATE users SET onboarding_step = 'candidate_consents'
WHERE scenario = 'candidate' AND email_normalized LIKE '%@' || $1`, seedusecase.SyntheticDomain); err != nil {
t.Fatalf("set the consent step on every candidate: %v", err)
}
if _, err := stand.pool.Exec(stand.ctx, `UPDATE users SET onboarding_step = 'completed' WHERE email_normalized = $1`,
demoEmail("prepared-1")); err != nil {
t.Fatalf("move one candidate past the assessment: %v", err)
}
repaired, err := stand.run(t, nil, "seed", "--actor", demoSeedActor)
if err != nil || !strings.Contains(repaired, "created 0 records") || strings.Count(repaired, "updated: onboarding of ") != 6 {
t.Fatalf("repairing seed = %q, %v, want six updated steps and no created record", repaired, err)
}
if step := stand.onboardingStep(t, demoEmail("prepared-1")); step != "completed" {
t.Fatalf("a later step of prepared-1 = %q, want completed kept", step)
}
if at := stand.count(t, `SELECT count(*) FROM users WHERE scenario = 'candidate'
AND email_normalized LIKE '%@' || $1 AND onboarding_step = 'candidate_assessment'`, seedusecase.SyntheticDomain); at != 6 {
t.Fatalf("candidates repaired to the assessment step = %d, want six", at)
}
if afterRepair := stand.inventory(t); afterRepair != afterFirst {
t.Fatalf("inventory changed by the repair:\nfirst:\n%s\nrepaired:\n%s", afterFirst, afterRepair)
}
again, err := stand.run(t, nil, "seed", "--actor", demoSeedActor)
if err != nil || !strings.Contains(again, "created 0 records") || strings.Contains(again, "updated:") {
t.Fatalf("seed after the repair = %q, %v, want nothing created or updated", again, err)
}
})
}
// onboardingStep reads the saved onboarding step of one account.
func (stand demoSeedStand) onboardingStep(t *testing.T, email string) string {
t.Helper()
var step string
if err := stand.pool.QueryRow(stand.ctx, `SELECT onboarding_step FROM users WHERE email_normalized = $1`, email).Scan(&step); err != nil {
t.Fatalf("read onboarding step of %s: %v", email, err)
}
return step
}
// assertDemoSeedOnboarding checks that every synthetic candidate, the
// self-service one and the prepared ones alike, stands at the step that a
// saved questionnaire leaves, and that the employers are unchanged.
func assertDemoSeedOnboarding(t *testing.T, stand demoSeedStand) {
t.Helper()
const candidates = 7
if total := stand.count(t, `SELECT count(*) FROM users WHERE scenario = 'candidate' AND email_normalized LIKE '%@' || $1`,
seedusecase.SyntheticDomain); total != candidates {
t.Fatalf("synthetic candidates = %d, want %d", total, candidates)
}
if at := stand.count(t, `SELECT count(*) FROM users WHERE scenario = 'candidate'
AND email_normalized LIKE '%@' || $1 AND onboarding_step = 'candidate_assessment'`, seedusecase.SyntheticDomain); at != candidates {
t.Errorf("candidates at the assessment step = %d, want %d", at, candidates)
}
if step := stand.onboardingStep(t, demoEmail("candidate")); step != "candidate_assessment" {
t.Errorf("the self-service candidate step = %q, want candidate_assessment", step)
}
if employers := stand.count(t, `SELECT count(*) FROM users WHERE scenario = 'employer' AND onboarding_step = 'employer_company'
AND email_normalized LIKE '%@' || $1`, seedusecase.SyntheticDomain); employers != 2 {
t.Errorf("synthetic employers at employer_company = %d, want 2", employers)
}
}
// assertDemoSeedMarkers checks that every organization and profile of the seed
@@ -429,6 +503,10 @@ func assertExpressAssignsNoCategory(t *testing.T, stand demoSeedStand) {
if outcome := stand.count(t, `SELECT count(*) FROM assessment_attempts WHERE id = $1 AND outcome = 'demonstration'`, express.ID().UUID()); outcome != 1 {
t.Fatalf("express outcome rows = %d, want one demonstration outcome", outcome)
}
result, err := attempts.GetMyResult(stand.ctx, candidateID, express.ID())
if err != nil || result.Summary != "Это тренировочный запуск: он не оценивает и не подтверждает уровень." {
t.Fatalf("express result summary = %q, %v, want the Russian training text", result.Summary, err)
}
if facts := stand.count(t, `SELECT count(*) FROM skill_evidence_facts`); facts != factsBefore {
t.Fatalf("evidence facts after the express = %d, want %d", facts, factsBefore)
}