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
@@ -234,6 +234,9 @@ func ExecuteSeed(ctx context.Context, seeder Seeder, input seedusecase.Input, ou
|
||||
for _, item := range report.Created {
|
||||
fmt.Fprintf(&text, "created: %s\n", item)
|
||||
}
|
||||
for _, item := range report.Updated {
|
||||
fmt.Fprintf(&text, "updated: %s\n", item)
|
||||
}
|
||||
for _, login := range report.Logins {
|
||||
fmt.Fprintf(&text, "login: %s (%s)\n", login.Email, login.Role)
|
||||
}
|
||||
|
||||
@@ -6,6 +6,7 @@ import (
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
"time"
|
||||
|
||||
"github.com/google/uuid"
|
||||
"github.com/jackc/pgx/v5"
|
||||
@@ -204,6 +205,33 @@ func insertTrainingBinding(ctx context.Context, tx pgx.Tx, binding outbound.Demo
|
||||
return nil
|
||||
}
|
||||
|
||||
// AdvanceCandidateOnboarding moves a verified candidate with a saved
|
||||
// questionnaire from an earlier candidate step to candidate_assessment. The
|
||||
// statement is the questionnaire transition of the product repository,
|
||||
// widened to the earlier steps, and it touches no later step. It bumps the
|
||||
// account version as the product transitions do.
|
||||
func (store *DemoSeedStore) AdvanceCandidateOnboarding(ctx context.Context, userID uuid.UUID, at time.Time) (bool, error) {
|
||||
const location = "DemoSeedStore.AdvanceCandidateOnboarding"
|
||||
result, err := store.pool.Exec(ctx, `
|
||||
UPDATE users
|
||||
SET
|
||||
onboarding_step = 'candidate_assessment',
|
||||
version = users.version + 1,
|
||||
updated_at = GREATEST(users.updated_at, $2::timestamptz)
|
||||
WHERE users.id = $1
|
||||
AND users.scenario = 'candidate'
|
||||
AND users.email_verified_at IS NOT NULL
|
||||
AND users.onboarding_step IN ('candidate_consents', 'candidate_profile', 'candidate_questionnaire')
|
||||
AND EXISTS (
|
||||
SELECT 1 FROM candidate_questionnaires AS questionnaire
|
||||
WHERE questionnaire.user_id = users.id
|
||||
)`, userID, at)
|
||||
if err != nil {
|
||||
return false, fmt.Errorf("%s - advance onboarding: %w", location, sanitizeConnectError(err))
|
||||
}
|
||||
return result.RowsAffected() == 1, nil
|
||||
}
|
||||
|
||||
// Inventory counts the records of synthetic accounts and of the seed's bank
|
||||
// categories in one read-only statement.
|
||||
func (store *DemoSeedStore) Inventory(
|
||||
|
||||
@@ -3,6 +3,7 @@ package outbound
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"time"
|
||||
|
||||
"github.com/google/uuid"
|
||||
|
||||
@@ -89,6 +90,15 @@ type DemoSeedStore interface {
|
||||
// count differs from ItemCount.
|
||||
BindTrainingBank(ctx context.Context, binding DemoTrainingBinding) error
|
||||
|
||||
// AdvanceCandidateOnboarding sets the saved onboarding step of a verified
|
||||
// candidate to candidate_assessment, the step that a saved questionnaire
|
||||
// leaves, when the step is still an earlier candidate step and the
|
||||
// questionnaire is saved. No product transition moves the consent step,
|
||||
// and the profile and questionnaire transitions apply only from their own
|
||||
// step, so a stand whose rows were saved earlier needs this statement. It
|
||||
// never moves a later step back, and it reports whether it changed the step.
|
||||
AdvanceCandidateOnboarding(ctx context.Context, userID uuid.UUID, at time.Time) (bool, error)
|
||||
|
||||
// Inventory counts the seed's records on the stand.
|
||||
Inventory(ctx context.Context, syntheticDomain string, categories []string) (DemoInventory, error)
|
||||
}
|
||||
@@ -311,9 +311,18 @@ func (service *AttemptService) persistFinalizedAttempt(
|
||||
return nil
|
||||
}
|
||||
|
||||
// expressResultSummary is the user-facing text of a finished express run. The
|
||||
// product UI is in Russian, and the text is stored in the immutable result, so
|
||||
// a run finished before this text changed keeps the text it was stored with.
|
||||
const expressResultSummary = "Это тренировочный запуск: он не оценивает и не подтверждает уровень."
|
||||
|
||||
// expressEndedSummary is the text of an express run that expired or was left
|
||||
// unfinished. Like expressResultSummary, it is stored in the immutable result.
|
||||
const expressEndedSummary = "Тренировочный запуск завершился до окончания: он не оценивает и не подтверждает уровень."
|
||||
|
||||
func assessmentFinalizedResultPresentation(kind domain.AssessmentAttemptKind) (string, []string) {
|
||||
if kind == domain.AssessmentAttemptKindDemoExpress {
|
||||
return "This training run is educational only. It does not assess or confirm a grade.", []string{"demonstration_only"}
|
||||
return expressResultSummary, []string{"demonstration_only"}
|
||||
}
|
||||
return "", []string{"uncalibrated_thresholds", "demo_bank", "practice_not_included", "unproctored"}
|
||||
}
|
||||
@@ -411,7 +420,7 @@ func terminalAttemptResult(attempt domain.AssessmentAttempt) (AssessmentAttemptR
|
||||
switch snapshot.Kind {
|
||||
case domain.AssessmentAttemptKindDemoExpress:
|
||||
result.Outcome = domain.AssessmentAttemptOutcomeDemonstration
|
||||
result.Summary = "This training run ended before completion. It does not assess or confirm a grade."
|
||||
result.Summary = expressEndedSummary
|
||||
case domain.AssessmentAttemptKindRoot, domain.AssessmentAttemptKindCorrective:
|
||||
result.Limitations = []string{"uncalibrated_thresholds", "demo_bank", "practice_not_included", "unproctored"}
|
||||
result.Outcome = domain.AssessmentAttemptOutcomeNotDetermined
|
||||
|
||||
@@ -84,11 +84,13 @@ type Input struct {
|
||||
Password domain.Password
|
||||
}
|
||||
|
||||
// Report lists what one run created and what it found. It holds addresses
|
||||
// of synthetic accounts and identifiers only.
|
||||
// Report lists what one run created, what it changed in an existing record,
|
||||
// and what it found. It holds addresses of synthetic accounts and identifiers
|
||||
// only.
|
||||
type Report struct {
|
||||
PolicyVersion int32
|
||||
Created []string
|
||||
Updated []string
|
||||
Present []string
|
||||
Logins []Login
|
||||
PreparedAttempts []PreparedAttempt
|
||||
@@ -114,6 +116,13 @@ func (report *Report) record(created bool, item string) {
|
||||
report.Present = append(report.Present, item)
|
||||
}
|
||||
|
||||
// update notes a change to a record that already existed. It is kept apart
|
||||
// from the created records, so a repeated run that repairs a stand reports no
|
||||
// new record.
|
||||
func (report *Report) update(item string) {
|
||||
report.Updated = append(report.Updated, item)
|
||||
}
|
||||
|
||||
// Seed builds the demo world or finds it complete.
|
||||
func (seeder *Seeder) Seed(ctx context.Context, input Input) (Report, error) {
|
||||
const location = "Seeder.Seed"
|
||||
@@ -565,8 +574,9 @@ func (seeder *Seeder) ensureMembership(ctx context.Context, organizationID, user
|
||||
}
|
||||
|
||||
// ensureCandidate gives a candidate its consents, manual profile, and
|
||||
// questionnaire; a prepared candidate also gets the prepared full attempt and
|
||||
// a published card. It returns the prepared attempt, or a zero ID.
|
||||
// questionnaire, then sets the onboarding step that the questionnaire leaves;
|
||||
// a prepared candidate also gets the prepared full attempt and a published
|
||||
// card. It returns the prepared attempt, or a zero ID.
|
||||
func (seeder *Seeder) ensureCandidate(
|
||||
ctx context.Context,
|
||||
spec accountSpec,
|
||||
@@ -593,6 +603,9 @@ func (seeder *Seeder) ensureCandidate(
|
||||
return domain.AssessmentAttemptID{}, fmt.Errorf("%s - %w", location, err)
|
||||
}
|
||||
report.record(created, "questionnaire of "+spec.email())
|
||||
if err := seeder.ensureOnboarding(ctx, user.ID, spec.email(), report); err != nil {
|
||||
return domain.AssessmentAttemptID{}, fmt.Errorf("%s - %w", location, err)
|
||||
}
|
||||
if spec.role != rolePrepared {
|
||||
return domain.AssessmentAttemptID{}, nil
|
||||
}
|
||||
@@ -609,6 +622,20 @@ func (seeder *Seeder) ensureCandidate(
|
||||
return attemptID, nil
|
||||
}
|
||||
|
||||
// ensureOnboarding leaves the candidate at candidate_assessment, the step that
|
||||
// a saved questionnaire leaves in the ordinary flow. A stand that already has
|
||||
// the step, or a later one, is unchanged, so a repeat reports no update.
|
||||
func (seeder *Seeder) ensureOnboarding(ctx context.Context, userID uuid.UUID, email string, report *Report) error {
|
||||
changed, err := seeder.deps.Store.AdvanceCandidateOnboarding(ctx, userID, seeder.now())
|
||||
if err != nil {
|
||||
return fmt.Errorf("advance onboarding of %s: %w", email, err)
|
||||
}
|
||||
if changed {
|
||||
report.update("onboarding of " + email + " at candidate_assessment")
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// grantConsent grants the current text of the purpose; a repeat of the same
|
||||
// version is idempotent in the ledger.
|
||||
func (seeder *Seeder) grantConsent(ctx context.Context, subjectID uuid.UUID, purpose domain.ConsentPurpose) error {
|
||||
|
||||
Reference in new issue
Block a user