fix(demo): advance seeded candidates past onboarding and show the express summary in Russian
This commit is contained in:
1 parent
41206abbcf
commit
945ab6d6a9
9 files changed
+296
-10
No files matched your search
@@ -1095,3 +1095,132 @@ func waitForAttemptIdleDeadline(t *testing.T, ctx context.Context, pool *pgxpool
|
||||
}
|
||||
t.Fatal("assessment attempt idle deadline did not pass during the row lock")
|
||||
}
|
||||
|
||||
// TestDemoExpressActiveAttemptOverHTTP covers an express run the candidate
|
||||
// leaves unfinished. The availability read has no express field by contract,
|
||||
// so the candidate keeps the identifier from the 201 response or replays the
|
||||
// Idempotency-Key of that creation. A new start is refused while the run is
|
||||
// active and succeeds once the run's own deadline has passed.
|
||||
func TestDemoExpressActiveAttemptOverHTTP(t *testing.T) {
|
||||
env := bootstrap(t, postgresService, redisService)
|
||||
ctx, cancel := context.WithTimeout(t.Context(), assessmentAttemptHTTPTimeout)
|
||||
defer cancel()
|
||||
databaseURL := env.createIsolatedDatabase(ctx, t)
|
||||
applyMigrations(ctx, t, databaseURL)
|
||||
isolatedEnv := *env
|
||||
isolatedEnv.Config.DatabaseURL = databaseURL
|
||||
harness := newAssessmentAttemptHTTPHarness(ctx, t, &isolatedEnv)
|
||||
seedAssessmentAttemptHTTPBank(ctx, t, harness.pool)
|
||||
|
||||
passwordHash, err := harness.credentials.HashNewPassword(ctx, sessionHTTPTestPass)
|
||||
if err != nil {
|
||||
t.Fatalf("HashNewPassword() error = %v", err)
|
||||
}
|
||||
candidate := createSessionHTTPUser(ctx, t, harness.sessionHTTPHarness, "express-resume@example.test", passwordHash, true)
|
||||
cookie, csrf := loginConsentHTTP(t, harness.sessionHTTPHarness, candidate.Email.Address(), "192.0.2.201:1234")
|
||||
body := `{"kind":"demo_express"}`
|
||||
|
||||
first := assessmentAttemptHTTPRequest(t, harness, http.MethodPost, "/api/v1/me/assessment-attempts", body,
|
||||
sessionHTTPTestOrigin, cookie.Value, csrf, "express-first", "192.0.2.202:1234")
|
||||
if first.Code != http.StatusCreated {
|
||||
t.Fatalf("create express = %d %s", first.Code, first.Body.String())
|
||||
}
|
||||
firstID := assessmentAttemptIDOf(t, first)
|
||||
|
||||
// Another key is refused while the first run is active, and creates nothing.
|
||||
second := assessmentAttemptHTTPRequest(t, harness, http.MethodPost, "/api/v1/me/assessment-attempts", body,
|
||||
sessionHTTPTestOrigin, cookie.Value, csrf, "express-second", "192.0.2.203:1234")
|
||||
requireSessionProblem(t, second, http.StatusConflict, "state_conflict")
|
||||
assertAttemptCount(t, ctx, harness.pool, 1)
|
||||
|
||||
// The creation key replays the stored 201, which returns the identifier of
|
||||
// the active run.
|
||||
replay := assessmentAttemptHTTPRequest(t, harness, http.MethodPost, "/api/v1/me/assessment-attempts", body,
|
||||
sessionHTTPTestOrigin, cookie.Value, csrf, "express-first", "192.0.2.204:1234")
|
||||
assertAssessmentAttemptReplay(t, "express-first while active", first, replay)
|
||||
|
||||
active := assessmentAttemptHTTPRequest(t, harness, http.MethodGet, "/api/v1/me/assessment-attempts/"+firstID.String(), "",
|
||||
"", cookie.Value, "", "", "192.0.2.205:1234")
|
||||
if state := assessmentAttemptStateOf(t, active); active.Code != http.StatusOK || state != "in_progress" {
|
||||
t.Fatalf("read active express = %d state %q, want 200 in_progress", active.Code, state)
|
||||
}
|
||||
|
||||
// The run ends at its own deadline. The fixture moves the run's clock fields
|
||||
// back instead of waiting for the policy duration, and the next start commits
|
||||
// the due transition.
|
||||
ageDemoExpressAttempt(t, ctx, harness.pool, firstID, 10*time.Minute)
|
||||
third := assessmentAttemptHTTPRequest(t, harness, http.MethodPost, "/api/v1/me/assessment-attempts", body,
|
||||
sessionHTTPTestOrigin, cookie.Value, csrf, "express-third", "192.0.2.206:1234")
|
||||
if third.Code != http.StatusCreated {
|
||||
t.Fatalf("create express after the deadline = %d %s", third.Code, third.Body.String())
|
||||
}
|
||||
assertAttemptCount(t, ctx, harness.pool, 2)
|
||||
|
||||
ended := assessmentAttemptHTTPRequest(t, harness, http.MethodGet, "/api/v1/me/assessment-attempts/"+firstID.String(), "",
|
||||
"", cookie.Value, "", "", "192.0.2.207:1234")
|
||||
if state := assessmentAttemptStateOf(t, ended); ended.Code != http.StatusOK || state != "expired" {
|
||||
t.Fatalf("read the first express after its deadline = %d state %q, want 200 expired", ended.Code, state)
|
||||
}
|
||||
result := assessmentAttemptHTTPRequest(t, harness, http.MethodGet, "/api/v1/me/assessment-attempts/"+firstID.String()+"/result", "",
|
||||
"", cookie.Value, "", "", "192.0.2.208:1234")
|
||||
var summary struct {
|
||||
Outcome string `json:"outcome"`
|
||||
Summary string `json:"summary"`
|
||||
}
|
||||
if err := json.Unmarshal(result.Body.Bytes(), &summary); err != nil || result.Code != http.StatusOK ||
|
||||
summary.Outcome != "demonstration" || summary.Summary != "Тренировочный запуск завершился до окончания: он не оценивает и не подтверждает уровень." {
|
||||
t.Fatalf("result of the expired express = %d %s, decode error %v", result.Code, result.Body.String(), err)
|
||||
}
|
||||
}
|
||||
|
||||
// assessmentAttemptIDOf reads the identifier of an attempt response.
|
||||
func assessmentAttemptIDOf(t *testing.T, response *httptest.ResponseRecorder) uuid.UUID {
|
||||
t.Helper()
|
||||
var snapshot struct {
|
||||
ID uuid.UUID `json:"id"`
|
||||
}
|
||||
if err := json.Unmarshal(response.Body.Bytes(), &snapshot); err != nil || snapshot.ID == uuid.Nil {
|
||||
t.Fatalf("attempt response %d %s has no identifier: %v", response.Code, response.Body.String(), err)
|
||||
}
|
||||
return snapshot.ID
|
||||
}
|
||||
|
||||
// assessmentAttemptStateOf reads the state of an attempt response.
|
||||
func assessmentAttemptStateOf(t *testing.T, response *httptest.ResponseRecorder) string {
|
||||
t.Helper()
|
||||
var snapshot struct {
|
||||
State string `json:"state"`
|
||||
}
|
||||
if err := json.Unmarshal(response.Body.Bytes(), &snapshot); err != nil {
|
||||
t.Fatalf("decode attempt response %d %s: %v", response.Code, response.Body.String(), err)
|
||||
}
|
||||
return snapshot.State
|
||||
}
|
||||
|
||||
// ageDemoExpressAttempt moves an attempt and its clock fields back by by, with
|
||||
// the triggers off for this one transaction, so that its deadline has passed.
|
||||
// The shift keeps every ordering constraint because all fields move together.
|
||||
func ageDemoExpressAttempt(t *testing.T, ctx context.Context, pool *pgxpool.Pool, attemptID uuid.UUID, by time.Duration) {
|
||||
t.Helper()
|
||||
tx, err := pool.Begin(ctx)
|
||||
if err != nil {
|
||||
t.Fatalf("begin express aging fixture: %v", err)
|
||||
}
|
||||
defer func() { _ = tx.Rollback(ctx) }()
|
||||
if _, err := tx.Exec(ctx, `SET LOCAL session_replication_role = replica`); err != nil {
|
||||
t.Fatalf("disable triggers for the express aging fixture: %v", err)
|
||||
}
|
||||
shift := fmt.Sprintf("%d seconds", int64(by.Seconds()))
|
||||
command, err := tx.Exec(ctx, `
|
||||
UPDATE assessment_attempts
|
||||
SET created_at = created_at - $2::interval, updated_at = updated_at - $2::interval,
|
||||
expires_at = expires_at - $2::interval, session_started_at = session_started_at - $2::interval,
|
||||
last_activity_at = last_activity_at - $2::interval
|
||||
WHERE id = $1 AND kind = 'demo_express'`, attemptID, shift)
|
||||
if err != nil || command.RowsAffected() != 1 {
|
||||
t.Fatalf("age express attempt = %d rows, error %v", command.RowsAffected(), err)
|
||||
}
|
||||
if err := tx.Commit(ctx); err != nil {
|
||||
t.Fatalf("commit express aging fixture: %v", err)
|
||||
}
|
||||
}
|
||||
@@ -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)
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user