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)
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user