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
@@ -55,6 +55,14 @@ SELECT candidate_id, specialization, grade, source_attempt_id, source_review_id,
|
||||
FROM candidate_assessment_categories
|
||||
WHERE candidate_id = sqlc.arg(candidate_id) AND specialization = sqlc.arg(specialization);
|
||||
|
||||
-- name: ListCandidateAssessmentCategories :many
|
||||
SELECT candidate_id, specialization, grade, source_attempt_id, source_review_id,
|
||||
product_policy_version_id, product_policy_version, grading_policy_version_id,
|
||||
opening_id, opening_manifest_sha256, source, calibration_status, assigned_at
|
||||
FROM candidate_assessment_categories
|
||||
WHERE candidate_id = sqlc.arg(candidate_id)
|
||||
ORDER BY specialization;
|
||||
|
||||
-- name: GetSyntheticCategoryReview :one
|
||||
SELECT review.id, review.opening_id, review.category, review.source,
|
||||
review.opening_manifest_sha256, review.product_policy_version_id,
|
||||
|
||||
@@ -53,7 +53,11 @@ SELECT
|
||||
COALESCE(
|
||||
(
|
||||
SELECT jsonb_agg(
|
||||
jsonb_build_object('specialization', category.specialization, 'grade', category.grade)
|
||||
jsonb_build_object(
|
||||
'specialization', category.specialization,
|
||||
'grade', category.grade,
|
||||
'source', category.source
|
||||
)
|
||||
ORDER BY category.specialization
|
||||
)::text
|
||||
FROM candidate_assessment_categories AS category
|
||||
@@ -187,7 +191,11 @@ SELECT
|
||||
COALESCE(
|
||||
(
|
||||
SELECT jsonb_agg(
|
||||
jsonb_build_object('specialization', category.specialization, 'grade', category.grade)
|
||||
jsonb_build_object(
|
||||
'specialization', category.specialization,
|
||||
'grade', category.grade,
|
||||
'source', category.source
|
||||
)
|
||||
ORDER BY category.specialization
|
||||
)::text
|
||||
FROM candidate_assessment_categories AS category
|
||||
|
||||
@@ -710,6 +710,7 @@ func TestAssessmentCategoryAssignmentOverHTTP(t *testing.T) {
|
||||
}
|
||||
wantHigh := []domain.CandidateViewConfirmedCategoryInput{{
|
||||
Specialization: domain.SpecializationBackend, Grade: domain.GradeIntern, Strength: domain.CandidateViewStrengthStandard,
|
||||
Basis: domain.AssessmentCategorySourceSyntheticDemo,
|
||||
}}
|
||||
if len(sources) != 2 || fmt.Sprint(categories[high.id]) != fmt.Sprint(wantHigh) || len(categories[low.id]) != 0 {
|
||||
t.Fatalf("organization projection = %v, want only the current intern category of the confirmed candidate", categories)
|
||||
|
||||
@@ -0,0 +1,166 @@
|
||||
//go:build integration
|
||||
|
||||
package integration_test
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"net/http"
|
||||
"strings"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
v1 "lincodex/backend/internal/adapter/primary/http/v1"
|
||||
"lincodex/backend/internal/domain"
|
||||
"lincodex/backend/internal/usecase/assessment"
|
||||
profileusecase "lincodex/backend/internal/usecase/profile"
|
||||
)
|
||||
|
||||
// TestConfirmedCategoryReadsOverHTTP checks the two candidate reads that show
|
||||
// the confirmed category, with its basis: the availability and the profile. A
|
||||
// candidate without a category gets null and an empty list. A higher passing
|
||||
// result replaces the category, and a lower passing result leaves it as it is.
|
||||
func TestConfirmedCategoryReadsOverHTTP(t *testing.T) {
|
||||
env := bootstrap(t, postgresService, redisService)
|
||||
ctx, cancel := context.WithTimeout(t.Context(), 2*assessmentAttemptHTTPTimeout)
|
||||
defer cancel()
|
||||
databaseURL := env.createIsolatedDatabase(ctx, t)
|
||||
applyMigrations(ctx, t, databaseURL)
|
||||
isolatedEnv := *env
|
||||
isolatedEnv.Config.DatabaseURL = databaseURL
|
||||
harness := newAssessmentAttemptHTTPHarnessWithOptions(ctx, t, &isolatedEnv,
|
||||
assessment.AssessmentCategoryDecisionSettings{SyntheticDemoAssignmentsEnabled: true},
|
||||
func(parts assessmentHarnessParts) []v1.HandlerOption {
|
||||
return []v1.HandlerOption{v1.WithProfile(v1.NewProfileHandler(profileusecase.NewService(parts.transactor, parts.clock.Now)))}
|
||||
})
|
||||
bank := seedAssessmentCategoryHTTPBank(ctx, t, harness.pool, domain.DemoProductPolicyV2(), true)
|
||||
threshold := passPoints(int(bank.policy.Policy().Assessment.StopRule.MaxScoredItems), int(bank.policy.Policy().Assessment.Attempt.BasicPassMark))
|
||||
client := &categoryHTTPClient{harness: harness, ctx: ctx}
|
||||
|
||||
none := client.candidate(t, "category-read-none@example.test")
|
||||
failed := client.candidate(t, "category-read-failed@example.test")
|
||||
held := client.candidate(t, "category-read-held@example.test")
|
||||
|
||||
t.Run("a candidate without any result sees no confirmed category in either read", func(t *testing.T) {
|
||||
assertAvailabilityConfirmation(t, client, none, "backend", nil, nil)
|
||||
assertProfileConfirmedCategoriesEmpty(t, client, none)
|
||||
})
|
||||
|
||||
t.Run("a candidate whose attempt confirmed nothing still sees no category", func(t *testing.T) {
|
||||
run := client.run(t, failed, "backend", "intern", func(int) int { return threshold - 1 })
|
||||
if run.result["outcome"] != "not_confirmed" {
|
||||
t.Fatalf("failing run outcome = %v, want not_confirmed", run.result["outcome"])
|
||||
}
|
||||
assertAvailabilityConfirmation(t, client, failed, "backend", nil, nil)
|
||||
assertProfileConfirmedCategoriesEmpty(t, client, failed)
|
||||
})
|
||||
|
||||
var intern, junior attemptRun
|
||||
t.Run("an assigned category is shown with its basis and attempt in both reads", func(t *testing.T) {
|
||||
intern = client.run(t, held, "backend", "intern", func(int) int { return threshold })
|
||||
assertAvailabilityConfirmation(t, client, held, "backend", "intern", "synthetic_demo")
|
||||
assertAvailabilityConfirmation(t, client, held, "frontend", nil, nil)
|
||||
assertProfileBackendCategory(t, client, held, "intern", "synthetic_demo", intern)
|
||||
})
|
||||
|
||||
t.Run("a higher passing result replaces the category and a lower one never lowers it", func(t *testing.T) {
|
||||
// The promotion interval counts on database time, so the finished intern
|
||||
// attempt is moved past it instead of waiting for days.
|
||||
moveFinishedAttemptBack(t, ctx, harness.pool, intern.id, categoryHTTPPromotionGap)
|
||||
junior = client.run(t, held, "backend", "junior", func(int) int { return threshold })
|
||||
if decision := decisionOf(t, junior.result); decision["status"] != "assigned" {
|
||||
t.Fatalf("junior decision = %v, want assigned", decision)
|
||||
}
|
||||
assertAvailabilityConfirmation(t, client, held, "backend", "junior", "synthetic_demo")
|
||||
assertProfileBackendCategory(t, client, held, "junior", "synthetic_demo", junior)
|
||||
|
||||
lower := client.run(t, held, "backend", "intern", func(int) int { return threshold })
|
||||
if decision := decisionOf(t, lower.result); decision["status"] != "unchanged" || decision["current_confirmed_grade"] != "junior" {
|
||||
t.Fatalf("lower passing decision = %v, want unchanged at junior", decision)
|
||||
}
|
||||
assertAvailabilityConfirmation(t, client, held, "backend", "junior", "synthetic_demo")
|
||||
assertProfileBackendCategory(t, client, held, "junior", "synthetic_demo", junior)
|
||||
})
|
||||
}
|
||||
|
||||
// assertAvailabilityConfirmation checks the confirmed grade and basis of one
|
||||
// specialization in the availability read. A nil argument stands for JSON null.
|
||||
func assertAvailabilityConfirmation(t *testing.T, client *categoryHTTPClient, who categoryHTTPCandidate, specialization string, grade, basis any) {
|
||||
t.Helper()
|
||||
status, body := client.call(t, who, http.MethodGet, "/api/v1/me/assessment-availability", "", "")
|
||||
if status != http.StatusOK {
|
||||
t.Fatalf("read availability = %d %s", status, body)
|
||||
}
|
||||
var read struct {
|
||||
Specializations []map[string]any `json:"specializations"`
|
||||
}
|
||||
if err := json.Unmarshal(body, &read); err != nil {
|
||||
t.Fatalf("decode availability: %v", err)
|
||||
}
|
||||
for _, item := range read.Specializations {
|
||||
if item["specialization"] != specialization {
|
||||
continue
|
||||
}
|
||||
if item["confirmed_grade"] != grade || item["confirmed_basis"] != basis {
|
||||
t.Fatalf("availability %s = grade %v basis %v, want grade %v basis %v", specialization, item["confirmed_grade"], item["confirmed_basis"], grade, basis)
|
||||
}
|
||||
return
|
||||
}
|
||||
t.Fatalf("availability lists no %s specialization: %s", specialization, body)
|
||||
}
|
||||
|
||||
func readProfileBody(t *testing.T, client *categoryHTTPClient, who categoryHTTPCandidate) []byte {
|
||||
t.Helper()
|
||||
status, body := client.call(t, who, http.MethodGet, "/api/v1/me/profile", "", "")
|
||||
if status != http.StatusOK {
|
||||
t.Fatalf("read profile = %d %s", status, body)
|
||||
}
|
||||
return body
|
||||
}
|
||||
|
||||
func assertProfileConfirmedCategoriesEmpty(t *testing.T, client *categoryHTTPClient, who categoryHTTPCandidate) {
|
||||
t.Helper()
|
||||
if body := readProfileBody(t, client, who); !strings.Contains(string(body), `"confirmed_categories":[]`) {
|
||||
t.Fatalf("profile = %s, want an empty confirmed_categories list", body)
|
||||
}
|
||||
}
|
||||
|
||||
// assertProfileBackendCategory checks that the profile holds exactly one
|
||||
// confirmed category, the backend one, with its grade, basis, and the attempt
|
||||
// whose result assigned it. The assignment time is the decision time of that
|
||||
// result.
|
||||
func assertProfileBackendCategory(t *testing.T, client *categoryHTTPClient, who categoryHTTPCandidate, grade, basis string, attempt attemptRun) {
|
||||
t.Helper()
|
||||
var profile struct {
|
||||
ConfirmedCategories []map[string]any `json:"confirmed_categories"`
|
||||
}
|
||||
if err := json.Unmarshal(readProfileBody(t, client, who), &profile); err != nil {
|
||||
t.Fatalf("decode profile: %v", err)
|
||||
}
|
||||
if len(profile.ConfirmedCategories) != 1 {
|
||||
t.Fatalf("confirmed_categories = %v, want exactly the backend category", profile.ConfirmedCategories)
|
||||
}
|
||||
category := profile.ConfirmedCategories[0]
|
||||
if len(category) != 5 {
|
||||
t.Fatalf("confirmed category has %d properties, want exactly specialization, grade, basis, confirmed_at, attempt_id: %v", len(category), category)
|
||||
}
|
||||
if category["specialization"] != "backend" || category["grade"] != grade || category["basis"] != basis ||
|
||||
category["attempt_id"] != attempt.id.String() {
|
||||
t.Fatalf("confirmed category = %v, want backend %s with basis %s from attempt %s", category, grade, basis, attempt.id)
|
||||
}
|
||||
confirmedAt, ok := category["confirmed_at"].(string)
|
||||
if !ok {
|
||||
t.Fatalf("confirmed_at = %v, want a timestamp", category["confirmed_at"])
|
||||
}
|
||||
assignedAt, err := time.Parse(time.RFC3339Nano, confirmedAt)
|
||||
if err != nil {
|
||||
t.Fatalf("parse confirmed_at %q: %v", confirmedAt, err)
|
||||
}
|
||||
decidedAt, err := time.Parse(time.RFC3339Nano, attempt.result["decided_at"].(string))
|
||||
if err != nil {
|
||||
t.Fatalf("parse decided_at: %v", err)
|
||||
}
|
||||
if !assignedAt.Equal(decidedAt) {
|
||||
t.Fatalf("confirmed_at = %s, want the decision time %s of the attempt", assignedAt, decidedAt)
|
||||
}
|
||||
}
|
||||
@@ -130,6 +130,7 @@ type matchEntryBody struct {
|
||||
Category *struct {
|
||||
Specialization string `json:"specialization"`
|
||||
Grade string `json:"grade"`
|
||||
Basis string `json:"basis"`
|
||||
} `json:"category"`
|
||||
Strength *string `json:"strength"`
|
||||
PublicContext struct {
|
||||
@@ -545,6 +546,13 @@ func TestMatchSearchOverHTTP(t *testing.T) {
|
||||
t.Fatalf("organization A confirmed bank = %d main, %d near, %d unconfirmed; want exactly the eleven visible confirmed candidates",
|
||||
len(bankA.Groups.Main), len(bankA.Groups.Near), len(bankA.Groups.Unconfirmed))
|
||||
}
|
||||
// Every confirmed category names its basis, so a demonstration grade is
|
||||
// never presented as a standard confirmation.
|
||||
for _, entry := range bankA.Groups.Main {
|
||||
if entry.Category == nil || entry.Category.Basis != "synthetic_demo" {
|
||||
t.Fatalf("confirmed entry %s category = %+v, want the synthetic_demo basis", entry.CandidateHandle, entry.Category)
|
||||
}
|
||||
}
|
||||
if slices.Contains(handlesOf(bankA.Groups.Main), aliasIn(orgA.ID(), hiddenFromA.id)) {
|
||||
t.Fatal("organization A received a candidate that hides it")
|
||||
}
|
||||
|
||||
@@ -10300,6 +10300,10 @@ func (s *AssessmentSpecializationAvailability) encodeFields(e *jx.Encoder) {
|
||||
e.FieldStart("confirmed_grade")
|
||||
s.ConfirmedGrade.Encode(e)
|
||||
}
|
||||
{
|
||||
e.FieldStart("confirmed_basis")
|
||||
s.ConfirmedBasis.Encode(e)
|
||||
}
|
||||
{
|
||||
e.FieldStart("active_attempt_id")
|
||||
s.ActiveAttemptID.Encode(e)
|
||||
@@ -10314,11 +10318,12 @@ func (s *AssessmentSpecializationAvailability) encodeFields(e *jx.Encoder) {
|
||||
}
|
||||
}
|
||||
|
||||
var jsonFieldsNameOfAssessmentSpecializationAvailability = [4]string{
|
||||
var jsonFieldsNameOfAssessmentSpecializationAvailability = [5]string{
|
||||
0: "specialization",
|
||||
1: "confirmed_grade",
|
||||
2: "active_attempt_id",
|
||||
3: "grades",
|
||||
2: "confirmed_basis",
|
||||
3: "active_attempt_id",
|
||||
4: "grades",
|
||||
}
|
||||
|
||||
// Decode decodes AssessmentSpecializationAvailability from json.
|
||||
@@ -10350,8 +10355,18 @@ func (s *AssessmentSpecializationAvailability) Decode(d *jx.Decoder) error {
|
||||
}(); err != nil {
|
||||
return errors.Wrap(err, "decode field \"confirmed_grade\"")
|
||||
}
|
||||
case "active_attempt_id":
|
||||
case "confirmed_basis":
|
||||
requiredBitSet[0] |= 1 << 2
|
||||
if err := func() error {
|
||||
if err := s.ConfirmedBasis.Decode(d); err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}(); err != nil {
|
||||
return errors.Wrap(err, "decode field \"confirmed_basis\"")
|
||||
}
|
||||
case "active_attempt_id":
|
||||
requiredBitSet[0] |= 1 << 3
|
||||
if err := func() error {
|
||||
if err := s.ActiveAttemptID.Decode(d); err != nil {
|
||||
return err
|
||||
@@ -10361,7 +10376,7 @@ func (s *AssessmentSpecializationAvailability) Decode(d *jx.Decoder) error {
|
||||
return errors.Wrap(err, "decode field \"active_attempt_id\"")
|
||||
}
|
||||
case "grades":
|
||||
requiredBitSet[0] |= 1 << 3
|
||||
requiredBitSet[0] |= 1 << 4
|
||||
if err := func() error {
|
||||
s.Grades = make([]AssessmentGradeAvailability, 0)
|
||||
if err := d.Arr(func(d *jx.Decoder) error {
|
||||
@@ -10388,7 +10403,7 @@ func (s *AssessmentSpecializationAvailability) Decode(d *jx.Decoder) error {
|
||||
// Validate required fields.
|
||||
var failures []validate.FieldError
|
||||
for i, mask := range [1]uint8{
|
||||
0b00001111,
|
||||
0b00011111,
|
||||
} {
|
||||
if result := (requiredBitSet[i] & mask) ^ mask; result != 0 {
|
||||
// Mask only required fields and check equality to mask using XOR.
|
||||
@@ -13612,12 +13627,17 @@ func (s *CardCategory) encodeFields(e *jx.Encoder) {
|
||||
e.FieldStart("strength")
|
||||
s.Strength.Encode(e)
|
||||
}
|
||||
{
|
||||
e.FieldStart("basis")
|
||||
s.Basis.Encode(e)
|
||||
}
|
||||
}
|
||||
|
||||
var jsonFieldsNameOfCardCategory = [3]string{
|
||||
var jsonFieldsNameOfCardCategory = [4]string{
|
||||
0: "specialization",
|
||||
1: "grade",
|
||||
2: "strength",
|
||||
3: "basis",
|
||||
}
|
||||
|
||||
// Decode decodes CardCategory from json.
|
||||
@@ -13659,6 +13679,16 @@ func (s *CardCategory) Decode(d *jx.Decoder) error {
|
||||
}(); err != nil {
|
||||
return errors.Wrap(err, "decode field \"strength\"")
|
||||
}
|
||||
case "basis":
|
||||
requiredBitSet[0] |= 1 << 3
|
||||
if err := func() error {
|
||||
if err := s.Basis.Decode(d); err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}(); err != nil {
|
||||
return errors.Wrap(err, "decode field \"basis\"")
|
||||
}
|
||||
default:
|
||||
return errors.Errorf("unexpected field %q", k)
|
||||
}
|
||||
@@ -13669,7 +13699,7 @@ func (s *CardCategory) Decode(d *jx.Decoder) error {
|
||||
// Validate required fields.
|
||||
var failures []validate.FieldError
|
||||
for i, mask := range [1]uint8{
|
||||
0b00000111,
|
||||
0b00001111,
|
||||
} {
|
||||
if result := (requiredBitSet[i] & mask) ^ mask; result != 0 {
|
||||
// Mask only required fields and check equality to mask using XOR.
|
||||
@@ -29198,11 +29228,16 @@ func (s *MatchCategory) encodeFields(e *jx.Encoder) {
|
||||
e.FieldStart("grade")
|
||||
s.Grade.Encode(e)
|
||||
}
|
||||
{
|
||||
e.FieldStart("basis")
|
||||
s.Basis.Encode(e)
|
||||
}
|
||||
}
|
||||
|
||||
var jsonFieldsNameOfMatchCategory = [2]string{
|
||||
var jsonFieldsNameOfMatchCategory = [3]string{
|
||||
0: "specialization",
|
||||
1: "grade",
|
||||
2: "basis",
|
||||
}
|
||||
|
||||
// Decode decodes MatchCategory from json.
|
||||
@@ -29234,6 +29269,16 @@ func (s *MatchCategory) Decode(d *jx.Decoder) error {
|
||||
}(); err != nil {
|
||||
return errors.Wrap(err, "decode field \"grade\"")
|
||||
}
|
||||
case "basis":
|
||||
requiredBitSet[0] |= 1 << 2
|
||||
if err := func() error {
|
||||
if err := s.Basis.Decode(d); err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}(); err != nil {
|
||||
return errors.Wrap(err, "decode field \"basis\"")
|
||||
}
|
||||
default:
|
||||
return errors.Errorf("unexpected field %q", k)
|
||||
}
|
||||
@@ -29244,7 +29289,7 @@ func (s *MatchCategory) Decode(d *jx.Decoder) error {
|
||||
// Validate required fields.
|
||||
var failures []validate.FieldError
|
||||
for i, mask := range [1]uint8{
|
||||
0b00000011,
|
||||
0b00000111,
|
||||
} {
|
||||
if result := (requiredBitSet[i] & mask) ^ mask; result != 0 {
|
||||
// Mask only required fields and check equality to mask using XOR.
|
||||
@@ -39018,6 +39063,50 @@ func (s *NilEmailAddress) UnmarshalJSON(data []byte) error {
|
||||
return s.Decode(d)
|
||||
}
|
||||
|
||||
// Encode encodes EvidenceBasis as json.
|
||||
func (o NilEvidenceBasis) Encode(e *jx.Encoder) {
|
||||
if o.Null {
|
||||
e.Null()
|
||||
return
|
||||
}
|
||||
e.Str(string(o.Value))
|
||||
}
|
||||
|
||||
// Decode decodes EvidenceBasis from json.
|
||||
func (o *NilEvidenceBasis) Decode(d *jx.Decoder) error {
|
||||
if o == nil {
|
||||
return errors.New("invalid: unable to decode NilEvidenceBasis to nil")
|
||||
}
|
||||
if d.Next() == jx.Null {
|
||||
if err := d.Null(); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
var v EvidenceBasis
|
||||
o.Value = v
|
||||
o.Null = true
|
||||
return nil
|
||||
}
|
||||
o.Null = false
|
||||
if err := o.Value.Decode(d); err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// MarshalJSON implements stdjson.Marshaler.
|
||||
func (s NilEvidenceBasis) MarshalJSON() ([]byte, error) {
|
||||
e := jx.Encoder{}
|
||||
s.Encode(&e)
|
||||
return e.Bytes(), nil
|
||||
}
|
||||
|
||||
// UnmarshalJSON implements stdjson.Unmarshaler.
|
||||
func (s *NilEvidenceBasis) UnmarshalJSON(data []byte) error {
|
||||
d := jx.DecodeBytes(data)
|
||||
return s.Decode(d)
|
||||
}
|
||||
|
||||
// Encode encodes float64 as json.
|
||||
func (o NilFloat64) Encode(e *jx.Encoder) {
|
||||
if o.Null {
|
||||
@@ -49486,6 +49575,10 @@ func (s *ProfileConfirmedCategory) encodeFields(e *jx.Encoder) {
|
||||
e.FieldStart("grade")
|
||||
s.Grade.Encode(e)
|
||||
}
|
||||
{
|
||||
e.FieldStart("basis")
|
||||
s.Basis.Encode(e)
|
||||
}
|
||||
{
|
||||
e.FieldStart("confirmed_at")
|
||||
s.ConfirmedAt.Encode(e)
|
||||
@@ -49496,11 +49589,12 @@ func (s *ProfileConfirmedCategory) encodeFields(e *jx.Encoder) {
|
||||
}
|
||||
}
|
||||
|
||||
var jsonFieldsNameOfProfileConfirmedCategory = [4]string{
|
||||
var jsonFieldsNameOfProfileConfirmedCategory = [5]string{
|
||||
0: "specialization",
|
||||
1: "grade",
|
||||
2: "confirmed_at",
|
||||
3: "attempt_id",
|
||||
2: "basis",
|
||||
3: "confirmed_at",
|
||||
4: "attempt_id",
|
||||
}
|
||||
|
||||
// Decode decodes ProfileConfirmedCategory from json.
|
||||
@@ -49532,8 +49626,18 @@ func (s *ProfileConfirmedCategory) Decode(d *jx.Decoder) error {
|
||||
}(); err != nil {
|
||||
return errors.Wrap(err, "decode field \"grade\"")
|
||||
}
|
||||
case "confirmed_at":
|
||||
case "basis":
|
||||
requiredBitSet[0] |= 1 << 2
|
||||
if err := func() error {
|
||||
if err := s.Basis.Decode(d); err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}(); err != nil {
|
||||
return errors.Wrap(err, "decode field \"basis\"")
|
||||
}
|
||||
case "confirmed_at":
|
||||
requiredBitSet[0] |= 1 << 3
|
||||
if err := func() error {
|
||||
if err := s.ConfirmedAt.Decode(d); err != nil {
|
||||
return err
|
||||
@@ -49543,7 +49647,7 @@ func (s *ProfileConfirmedCategory) Decode(d *jx.Decoder) error {
|
||||
return errors.Wrap(err, "decode field \"confirmed_at\"")
|
||||
}
|
||||
case "attempt_id":
|
||||
requiredBitSet[0] |= 1 << 3
|
||||
requiredBitSet[0] |= 1 << 4
|
||||
if err := func() error {
|
||||
v, err := json.DecodeUUID(d)
|
||||
s.AttemptID = v
|
||||
@@ -49564,7 +49668,7 @@ func (s *ProfileConfirmedCategory) Decode(d *jx.Decoder) error {
|
||||
// Validate required fields.
|
||||
var failures []validate.FieldError
|
||||
for i, mask := range [1]uint8{
|
||||
0b00001111,
|
||||
0b00011111,
|
||||
} {
|
||||
if result := (requiredBitSet[i] & mask) ^ mask; result != 0 {
|
||||
// Mask only required fields and check equality to mask using XOR.
|
||||
|
||||
@@ -5395,6 +5395,10 @@ type AssessmentSpecializationAvailability struct {
|
||||
Specialization SpecializationCode `json:"specialization"`
|
||||
// Currently confirmed grade of the specialization, or null.
|
||||
ConfirmedGrade NilGradeCode `json:"confirmed_grade"`
|
||||
// What the confirmed grade rests on, or null exactly when `confirmed_grade` is null. `synthetic_demo`
|
||||
// marks a demonstration category, which is not a validated measurement and must not be shown as a real
|
||||
// confirmation.
|
||||
ConfirmedBasis NilEvidenceBasis `json:"confirmed_basis"`
|
||||
// Identifier of the active attempt of the specialization, or null.
|
||||
ActiveAttemptID NilUUID `json:"active_attempt_id"`
|
||||
// Every grade of the scale in ascending order.
|
||||
@@ -5411,6 +5415,11 @@ func (s *AssessmentSpecializationAvailability) GetConfirmedGrade() NilGradeCode
|
||||
return s.ConfirmedGrade
|
||||
}
|
||||
|
||||
// GetConfirmedBasis returns the value of ConfirmedBasis.
|
||||
func (s *AssessmentSpecializationAvailability) GetConfirmedBasis() NilEvidenceBasis {
|
||||
return s.ConfirmedBasis
|
||||
}
|
||||
|
||||
// GetActiveAttemptID returns the value of ActiveAttemptID.
|
||||
func (s *AssessmentSpecializationAvailability) GetActiveAttemptID() NilUUID {
|
||||
return s.ActiveAttemptID
|
||||
@@ -5431,6 +5440,11 @@ func (s *AssessmentSpecializationAvailability) SetConfirmedGrade(val NilGradeCod
|
||||
s.ConfirmedGrade = val
|
||||
}
|
||||
|
||||
// SetConfirmedBasis sets the value of ConfirmedBasis.
|
||||
func (s *AssessmentSpecializationAvailability) SetConfirmedBasis(val NilEvidenceBasis) {
|
||||
s.ConfirmedBasis = val
|
||||
}
|
||||
|
||||
// SetActiveAttemptID sets the value of ActiveAttemptID.
|
||||
func (s *AssessmentSpecializationAvailability) SetActiveAttemptID(val NilUUID) {
|
||||
s.ActiveAttemptID = val
|
||||
@@ -7030,13 +7044,15 @@ func (s *CardAccessListHeaders) SetResponse(val CardAccessList) {
|
||||
|
||||
func (*CardAccessListHeaders) listMyCardAccessHistoryRes() {}
|
||||
|
||||
// A category confirmed by assessment results, as the card shows it.
|
||||
// A category confirmed by assessment results, as the card shows it. `basis` says what the grade rests
|
||||
// on; `synthetic_demo` marks a demonstration category, which is never a standard confirmation.
|
||||
// Ref: #/components/schemas/CardCategory
|
||||
type CardCategory struct {
|
||||
Specialization SpecializationCode `json:"specialization"`
|
||||
Grade GradeCode `json:"grade"`
|
||||
// Coarse strength of the authoritative confirmation.
|
||||
Strength CardCategoryStrength `json:"strength"`
|
||||
Basis EvidenceBasis `json:"basis"`
|
||||
}
|
||||
|
||||
// GetSpecialization returns the value of Specialization.
|
||||
@@ -7054,6 +7070,11 @@ func (s *CardCategory) GetStrength() CardCategoryStrength {
|
||||
return s.Strength
|
||||
}
|
||||
|
||||
// GetBasis returns the value of Basis.
|
||||
func (s *CardCategory) GetBasis() EvidenceBasis {
|
||||
return s.Basis
|
||||
}
|
||||
|
||||
// SetSpecialization sets the value of Specialization.
|
||||
func (s *CardCategory) SetSpecialization(val SpecializationCode) {
|
||||
s.Specialization = val
|
||||
@@ -7069,6 +7090,11 @@ func (s *CardCategory) SetStrength(val CardCategoryStrength) {
|
||||
s.Strength = val
|
||||
}
|
||||
|
||||
// SetBasis sets the value of Basis.
|
||||
func (s *CardCategory) SetBasis(val EvidenceBasis) {
|
||||
s.Basis = val
|
||||
}
|
||||
|
||||
// Coarse strength of the authoritative confirmation.
|
||||
type CardCategoryStrength string
|
||||
|
||||
@@ -12918,10 +12944,13 @@ func (s *MatchAppliedFilters) SetConditions(val NilMatchAppliedConditions) {
|
||||
}
|
||||
|
||||
// A confirmed category. Its specialization must equal the enclosing match entry's specialization.
|
||||
// `basis` says what the grade rests on; `synthetic_demo` marks a demonstration category, which an
|
||||
// organization must read as one and never as a standard confirmation.
|
||||
// Ref: #/components/schemas/MatchCategory
|
||||
type MatchCategory struct {
|
||||
Specialization SpecializationCode `json:"specialization"`
|
||||
Grade GradeCode `json:"grade"`
|
||||
Basis EvidenceBasis `json:"basis"`
|
||||
}
|
||||
|
||||
// GetSpecialization returns the value of Specialization.
|
||||
@@ -12934,6 +12963,11 @@ func (s *MatchCategory) GetGrade() GradeCode {
|
||||
return s.Grade
|
||||
}
|
||||
|
||||
// GetBasis returns the value of Basis.
|
||||
func (s *MatchCategory) GetBasis() EvidenceBasis {
|
||||
return s.Basis
|
||||
}
|
||||
|
||||
// SetSpecialization sets the value of Specialization.
|
||||
func (s *MatchCategory) SetSpecialization(val SpecializationCode) {
|
||||
s.Specialization = val
|
||||
@@ -12944,6 +12978,11 @@ func (s *MatchCategory) SetGrade(val GradeCode) {
|
||||
s.Grade = val
|
||||
}
|
||||
|
||||
// SetBasis sets the value of Basis.
|
||||
func (s *MatchCategory) SetBasis(val EvidenceBasis) {
|
||||
s.Basis = val
|
||||
}
|
||||
|
||||
// Confirmation state for this specialization only. A result for one specialization never changes the
|
||||
// state of another specialization.
|
||||
// Ref: #/components/schemas/MatchConfirmationStatus
|
||||
@@ -18060,6 +18099,51 @@ func (o NilEmailAddress) Or(d EmailAddress) EmailAddress {
|
||||
return d
|
||||
}
|
||||
|
||||
// NewNilEvidenceBasis returns new NilEvidenceBasis with value set to v.
|
||||
func NewNilEvidenceBasis(v EvidenceBasis) NilEvidenceBasis {
|
||||
return NilEvidenceBasis{
|
||||
Value: v,
|
||||
}
|
||||
}
|
||||
|
||||
// NilEvidenceBasis is nullable EvidenceBasis.
|
||||
type NilEvidenceBasis struct {
|
||||
Value EvidenceBasis
|
||||
Null bool
|
||||
}
|
||||
|
||||
// SetTo sets value to v.
|
||||
func (o *NilEvidenceBasis) SetTo(v EvidenceBasis) {
|
||||
o.Null = false
|
||||
o.Value = v
|
||||
}
|
||||
|
||||
// IsNull returns true if value is Null.
|
||||
func (o NilEvidenceBasis) IsNull() bool { return o.Null }
|
||||
|
||||
// SetToNull sets value to null.
|
||||
func (o *NilEvidenceBasis) SetToNull() {
|
||||
o.Null = true
|
||||
var v EvidenceBasis
|
||||
o.Value = v
|
||||
}
|
||||
|
||||
// Get returns value and boolean that denotes whether value was set.
|
||||
func (o NilEvidenceBasis) Get() (v EvidenceBasis, ok bool) {
|
||||
if o.Null {
|
||||
return v, false
|
||||
}
|
||||
return o.Value, true
|
||||
}
|
||||
|
||||
// Or returns value if set, or given parameter if does not.
|
||||
func (o NilEvidenceBasis) Or(d EvidenceBasis) EvidenceBasis {
|
||||
if v, ok := o.Get(); ok {
|
||||
return v
|
||||
}
|
||||
return d
|
||||
}
|
||||
|
||||
// NewNilFloat64 returns new NilFloat64 with value set to v.
|
||||
func NewNilFloat64(v float64) NilFloat64 {
|
||||
return NilFloat64{
|
||||
@@ -26050,11 +26134,13 @@ type ProfileClaimTrustLevel int32
|
||||
// read-only and derived by the server from the assessment results of the candidate; no request carries
|
||||
// it and the profile storage holds no such column, so neither a form nor an import can write a
|
||||
// confirmed grade. It is separate from the claims of the profile and from the self-assessed grades in
|
||||
// `roles`.
|
||||
// `roles`. `basis` says what the grade rests on; `synthetic_demo` marks a demonstration category that
|
||||
// is not a validated measurement.
|
||||
// Ref: #/components/schemas/ProfileConfirmedCategory
|
||||
type ProfileConfirmedCategory struct {
|
||||
Specialization SpecializationCode `json:"specialization"`
|
||||
Grade GradeCode `json:"grade"`
|
||||
Basis EvidenceBasis `json:"basis"`
|
||||
ConfirmedAt Timestamp `json:"confirmed_at"`
|
||||
// Assessment attempt whose result confirmed the grade. The attempt belongs to the candidate.
|
||||
AttemptID uuid.UUID `json:"attempt_id"`
|
||||
@@ -26070,6 +26156,11 @@ func (s *ProfileConfirmedCategory) GetGrade() GradeCode {
|
||||
return s.Grade
|
||||
}
|
||||
|
||||
// GetBasis returns the value of Basis.
|
||||
func (s *ProfileConfirmedCategory) GetBasis() EvidenceBasis {
|
||||
return s.Basis
|
||||
}
|
||||
|
||||
// GetConfirmedAt returns the value of ConfirmedAt.
|
||||
func (s *ProfileConfirmedCategory) GetConfirmedAt() Timestamp {
|
||||
return s.ConfirmedAt
|
||||
@@ -26090,6 +26181,11 @@ func (s *ProfileConfirmedCategory) SetGrade(val GradeCode) {
|
||||
s.Grade = val
|
||||
}
|
||||
|
||||
// SetBasis sets the value of Basis.
|
||||
func (s *ProfileConfirmedCategory) SetBasis(val EvidenceBasis) {
|
||||
s.Basis = val
|
||||
}
|
||||
|
||||
// SetConfirmedAt sets the value of ConfirmedAt.
|
||||
func (s *ProfileConfirmedCategory) SetConfirmedAt(val Timestamp) {
|
||||
s.ConfirmedAt = val
|
||||
|
||||
@@ -4477,6 +4477,24 @@ func (s *AssessmentSpecializationAvailability) Validate() error {
|
||||
Error: err,
|
||||
})
|
||||
}
|
||||
if err := func() error {
|
||||
if value, ok := s.ConfirmedBasis.Get(); ok {
|
||||
if err := func() error {
|
||||
if err := value.Validate(); err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}(); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}(); err != nil {
|
||||
failures = append(failures, validate.FieldError{
|
||||
Name: "confirmed_basis",
|
||||
Error: err,
|
||||
})
|
||||
}
|
||||
if err := func() error {
|
||||
if s.Grades == nil {
|
||||
return errors.New("nil is invalid value")
|
||||
@@ -6388,6 +6406,17 @@ func (s *CardCategory) Validate() error {
|
||||
Error: err,
|
||||
})
|
||||
}
|
||||
if err := func() error {
|
||||
if err := s.Basis.Validate(); err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}(); err != nil {
|
||||
failures = append(failures, validate.FieldError{
|
||||
Name: "basis",
|
||||
Error: err,
|
||||
})
|
||||
}
|
||||
if len(failures) > 0 {
|
||||
return &validate.Error{Fields: failures}
|
||||
}
|
||||
@@ -12044,6 +12073,17 @@ func (s *MatchCategory) Validate() error {
|
||||
Error: err,
|
||||
})
|
||||
}
|
||||
if err := func() error {
|
||||
if err := s.Basis.Validate(); err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}(); err != nil {
|
||||
failures = append(failures, validate.FieldError{
|
||||
Name: "basis",
|
||||
Error: err,
|
||||
})
|
||||
}
|
||||
if len(failures) > 0 {
|
||||
return &validate.Error{Fields: failures}
|
||||
}
|
||||
@@ -19717,6 +19757,17 @@ func (s *ProfileConfirmedCategory) Validate() error {
|
||||
Error: err,
|
||||
})
|
||||
}
|
||||
if err := func() error {
|
||||
if err := s.Basis.Validate(); err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}(); err != nil {
|
||||
failures = append(failures, validate.FieldError{
|
||||
Name: "basis",
|
||||
Error: err,
|
||||
})
|
||||
}
|
||||
if len(failures) > 0 {
|
||||
return &validate.Error{Fields: failures}
|
||||
}
|
||||
|
||||
@@ -49,11 +49,19 @@ func assessmentAvailabilityResponse(
|
||||
Grades: make([]api.AssessmentGradeAvailability, 0, len(item.Grades)),
|
||||
}
|
||||
specialization.ConfirmedGrade.SetToNull()
|
||||
specialization.ConfirmedBasis.SetToNull()
|
||||
if (item.ConfirmedGrade == nil) != (item.ConfirmedBasis == nil) {
|
||||
return api.AssessmentAvailability{}, errors.New("assessment availability pairs a confirmed grade with its basis inconsistently")
|
||||
}
|
||||
if item.ConfirmedGrade != nil {
|
||||
if !item.ConfirmedGrade.IsKnown() {
|
||||
return api.AssessmentAvailability{}, errors.New("assessment availability has an unknown confirmed grade")
|
||||
}
|
||||
if !item.ConfirmedBasis.IsKnown() {
|
||||
return api.AssessmentAvailability{}, errors.New("assessment availability has an unknown confirmed basis")
|
||||
}
|
||||
specialization.ConfirmedGrade.SetTo(api.GradeCode(*item.ConfirmedGrade))
|
||||
specialization.ConfirmedBasis.SetTo(api.EvidenceBasis(*item.ConfirmedBasis))
|
||||
}
|
||||
specialization.ActiveAttemptID.SetToNull()
|
||||
if item.ActiveAttemptID != nil {
|
||||
|
||||
@@ -97,3 +97,46 @@ func TestGetMyAssessmentAvailabilityMapsAuthAndUnavailableMode(t *testing.T) {
|
||||
}
|
||||
|
||||
func noPrincipalContext() context.Context { return context.Background() }
|
||||
|
||||
// A confirmed grade is never returned without the basis that says whether it
|
||||
// is a demonstration, and a basis never arrives without its grade.
|
||||
func TestAssessmentAvailabilityResponseCarriesTheBasisOfTheConfirmedGrade(t *testing.T) {
|
||||
basis := domain.AssessmentCategorySourceSyntheticDemo
|
||||
grade := domain.GradeJunior
|
||||
confirmed, err := assessmentAvailabilityResponse(assessmentusecase.AssessmentAvailability{
|
||||
Specializations: []assessmentusecase.SpecializationAvailability{{
|
||||
Specialization: domain.SpecializationBackend, ConfirmedGrade: &grade, ConfirmedBasis: &basis,
|
||||
}},
|
||||
})
|
||||
if err != nil {
|
||||
t.Fatalf("assessmentAvailabilityResponse(confirmed) error = %v", err)
|
||||
}
|
||||
item := confirmed.Specializations[0]
|
||||
if grade, found := item.ConfirmedGrade.Get(); !found || grade != api.GradeCodeJunior {
|
||||
t.Fatalf("confirmed_grade = %+v, want junior", item.ConfirmedGrade)
|
||||
}
|
||||
if got, found := item.ConfirmedBasis.Get(); !found || got != api.EvidenceBasisSyntheticDemo {
|
||||
t.Fatalf("confirmed_basis = %+v, want synthetic_demo", item.ConfirmedBasis)
|
||||
}
|
||||
|
||||
unconfirmed, err := assessmentAvailabilityResponse(assessmentusecase.AssessmentAvailability{
|
||||
Specializations: []assessmentusecase.SpecializationAvailability{{Specialization: domain.SpecializationBackend}},
|
||||
})
|
||||
if err != nil {
|
||||
t.Fatalf("assessmentAvailabilityResponse(unconfirmed) error = %v", err)
|
||||
}
|
||||
if !unconfirmed.Specializations[0].ConfirmedGrade.IsNull() || !unconfirmed.Specializations[0].ConfirmedBasis.IsNull() {
|
||||
t.Fatalf("unconfirmed specialization = %+v, want null grade and basis", unconfirmed.Specializations[0])
|
||||
}
|
||||
|
||||
for _, orphan := range []assessmentusecase.SpecializationAvailability{
|
||||
{Specialization: domain.SpecializationBackend, ConfirmedGrade: &grade},
|
||||
{Specialization: domain.SpecializationBackend, ConfirmedBasis: &basis},
|
||||
} {
|
||||
if _, err := assessmentAvailabilityResponse(assessmentusecase.AssessmentAvailability{
|
||||
Specializations: []assessmentusecase.SpecializationAvailability{orphan},
|
||||
}); err == nil {
|
||||
t.Fatalf("assessmentAvailabilityResponse(%+v) error = nil, want an inconsistent pair to fail", orphan)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -225,6 +225,7 @@ func matchConfirmedCandidate(entry matching.Entry) api.MatchConfirmedCandidate {
|
||||
if entry.Category != nil {
|
||||
candidate.Category = api.MatchCategory{
|
||||
Specialization: api.SpecializationCode(entry.Category.Specialization), Grade: api.GradeCode(entry.Category.Grade),
|
||||
Basis: api.EvidenceBasis(entry.Category.Basis),
|
||||
}
|
||||
candidate.Strength = api.MatchStrength(entry.Category.Strength)
|
||||
}
|
||||
|
||||
@@ -128,7 +128,10 @@ func TestSearchOrganizationMatchesMapsAConfirmedEntryWithANullPercentile(t *test
|
||||
handle := "cv1_aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
|
||||
stub := &matchOperationsStub{result: matching.Result{Main: []matching.Entry{{
|
||||
CandidateHandle: handle, Specialization: domain.SpecializationBackend,
|
||||
Category: &domain.CandidateViewCategory{Specialization: domain.SpecializationBackend, Grade: domain.GradeMiddle, Strength: domain.CandidateViewStrengthStrong},
|
||||
Category: &domain.CandidateViewCategory{
|
||||
Specialization: domain.SpecializationBackend, Grade: domain.GradeMiddle, Strength: domain.CandidateViewStrengthStrong,
|
||||
Basis: domain.AssessmentCategorySourceSyntheticDemo,
|
||||
},
|
||||
Components: matching.Components{
|
||||
Fit: 0.5, Coverage: 0.5, Domain: 0.5, Semantics: 0.5, Freshness: 0.5, Responsiveness: 0.5, RankScore: 0.45125,
|
||||
},
|
||||
@@ -147,7 +150,8 @@ func TestSearchOrganizationMatchesMapsAConfirmedEntryWithANullPercentile(t *test
|
||||
t.Fatalf("encode response: %v", err)
|
||||
}
|
||||
for _, want := range []string{
|
||||
`"confirmation_status":"confirmed"`, `"declared_grade":null`, `"category":{"specialization":"backend","grade":"middle"}`, `"strength":"strong"`,
|
||||
`"confirmation_status":"confirmed"`, `"declared_grade":null`,
|
||||
`"category":{"specialization":"backend","grade":"middle","basis":"synthetic_demo"}`, `"strength":"strong"`,
|
||||
`"percentile":null`, `"competition":0`, `"rank_score":0.45125`,
|
||||
} {
|
||||
if !strings.Contains(string(encoded), want) {
|
||||
|
||||
@@ -535,7 +535,7 @@ func anonymousCardResponse(view domain.AnonymousCandidateViewDTO) api.AnonymousC
|
||||
for _, category := range view.Categories {
|
||||
content.Categories = append(content.Categories, api.CardCategory{
|
||||
Specialization: api.SpecializationCode(category.Specialization), Grade: api.GradeCode(category.Grade),
|
||||
Strength: api.CardCategoryStrength(category.Strength),
|
||||
Strength: api.CardCategoryStrength(category.Strength), Basis: api.EvidenceBasis(category.Basis),
|
||||
})
|
||||
}
|
||||
for _, skill := range view.Skills {
|
||||
|
||||
@@ -23,6 +23,7 @@ func TestPrivacyGetOrganizationCandidateCardMapsClosedProjection(t *testing.T) {
|
||||
Pseudonym: "cv1_aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
|
||||
Categories: []domain.CandidateViewCategory{{
|
||||
Specialization: domain.SpecializationBackend, Grade: domain.GradeJunior, Strength: domain.CandidateViewStrengthStrong,
|
||||
Basis: domain.AssessmentCategorySourceSyntheticDemo,
|
||||
}},
|
||||
Skills: []domain.CandidateViewSkillCode{"go"},
|
||||
SelfAssessment: []domain.CandidateViewSelfAssessment{{
|
||||
@@ -45,6 +46,7 @@ func TestPrivacyGetOrganizationCandidateCardMapsClosedProjection(t *testing.T) {
|
||||
}
|
||||
if body.CacheControl != api.CacheControlNoStoreNoStore || body.Response.Pseudonym != view.Pseudonym ||
|
||||
len(body.Response.Categories) != 1 || body.Response.Categories[0].Strength != api.CardCategoryStrengthStrong ||
|
||||
body.Response.Categories[0].Basis != api.EvidenceBasisSyntheticDemo ||
|
||||
len(body.Response.Stack) != 1 || body.Response.Stack[0] != "go" ||
|
||||
len(body.Response.SelfAssessment) != 1 || body.Response.SelfAssessment[0].ConfirmationStatus != api.CardSelfAssessmentConfirmationStatusUnconfirmed {
|
||||
t.Fatalf("anonymous content mapping = %+v", body)
|
||||
|
||||
@@ -16,8 +16,8 @@ import (
|
||||
// ProfileOperations reads and version-saves the authenticated candidate's
|
||||
// private manual profile.
|
||||
type ProfileOperations interface {
|
||||
GetMyProfile(ctx context.Context, userID uuid.UUID) (domain.CandidateProfile, error)
|
||||
SaveMyProfile(ctx context.Context, userID uuid.UUID, expectedVersion int64, input domain.CandidateProfileInput) (domain.CandidateProfile, error)
|
||||
GetMyProfile(ctx context.Context, userID uuid.UUID) (profile.View, error)
|
||||
SaveMyProfile(ctx context.Context, userID uuid.UUID, expectedVersion int64, input domain.CandidateProfileInput) (profile.View, error)
|
||||
}
|
||||
|
||||
// ProfileHandler serves the candidate's own profile operations.
|
||||
@@ -51,13 +51,13 @@ func (handler *ProfileHandler) GetMyProfile(ctx context.Context) (api.GetMyProfi
|
||||
if !ok {
|
||||
return (*api.GetMyProfileUnauthorized)(&problem.New(ctx, api.ProblemCodeUnauthenticated).Response), nil
|
||||
}
|
||||
profile, err := handler.operations.GetMyProfile(ctx, principal.UserID)
|
||||
view, err := handler.operations.GetMyProfile(ctx, principal.UserID)
|
||||
if err != nil {
|
||||
return profileReadFailure(ctx, err)
|
||||
}
|
||||
return &api.CandidateProfileHeaders{
|
||||
CacheControl: api.CacheControlNoStoreNoStore,
|
||||
Response: candidateProfileResponse(profile),
|
||||
Response: candidateProfileResponse(view),
|
||||
}, nil
|
||||
}
|
||||
|
||||
@@ -69,13 +69,13 @@ func (handler *ProfileHandler) SaveMyProfile(ctx context.Context, request *api.C
|
||||
if request == nil {
|
||||
return (*api.SaveMyProfileBadRequest)(&problem.InvalidField(ctx, api.ProblemFieldLocationBody, "").Response), nil
|
||||
}
|
||||
profile, err := handler.operations.SaveMyProfile(ctx, principal.UserID, int64(request.ExpectedVersion), candidateProfileInput(request))
|
||||
view, err := handler.operations.SaveMyProfile(ctx, principal.UserID, int64(request.ExpectedVersion), candidateProfileInput(request))
|
||||
if err != nil {
|
||||
return profileSaveFailure(ctx, err)
|
||||
}
|
||||
return &api.CandidateProfileHeaders{
|
||||
CacheControl: api.CacheControlNoStoreNoStore,
|
||||
Response: candidateProfileResponse(profile),
|
||||
Response: candidateProfileResponse(view),
|
||||
}, nil
|
||||
}
|
||||
|
||||
@@ -194,16 +194,16 @@ func profileYearMonth(value api.NilProfileYearMonth) string {
|
||||
return string(month)
|
||||
}
|
||||
|
||||
func candidateProfileResponse(profile domain.CandidateProfile) api.CandidateProfile {
|
||||
content := profile.Content()
|
||||
func candidateProfileResponse(view profile.View) api.CandidateProfile {
|
||||
saved := view.Profile
|
||||
content := saved.Content()
|
||||
response := api.CandidateProfile{
|
||||
Version: api.ProfileVersion(profile.Version()),
|
||||
ExperienceOverlaps: make([]api.ProfileExperienceOverlap, 0),
|
||||
Stack: make([]api.ProfileStackItem, 0),
|
||||
Roles: make([]api.ProfileRoleItem, 0),
|
||||
Experience: make([]api.ProfileExperienceItem, 0),
|
||||
SoftSkills: make([]api.ProfileSoftSkillItem, 0),
|
||||
ConfirmedCategories: make([]api.ProfileConfirmedCategory, 0),
|
||||
Version: api.ProfileVersion(saved.Version()),
|
||||
ExperienceOverlaps: make([]api.ProfileExperienceOverlap, 0),
|
||||
Stack: make([]api.ProfileStackItem, 0),
|
||||
Roles: make([]api.ProfileRoleItem, 0),
|
||||
Experience: make([]api.ProfileExperienceItem, 0),
|
||||
SoftSkills: make([]api.ProfileSoftSkillItem, 0),
|
||||
}
|
||||
if name, ok := content.FullName(); ok {
|
||||
response.FullName = profileFullNameClaim(name)
|
||||
@@ -279,15 +279,39 @@ func candidateProfileResponse(profile domain.CandidateProfile) api.CandidateProf
|
||||
}
|
||||
response.Terms = candidateProfileTerms(content)
|
||||
updatedAt := api.NilTimestamp{}
|
||||
if profile.UpdatedAt().IsZero() {
|
||||
if saved.UpdatedAt().IsZero() {
|
||||
updatedAt.SetToNull()
|
||||
} else {
|
||||
updatedAt.SetTo(api.Timestamp(profile.UpdatedAt()))
|
||||
updatedAt.SetTo(api.Timestamp(saved.UpdatedAt()))
|
||||
}
|
||||
response.UpdatedAt = updatedAt
|
||||
response.ConfirmedCategories = confirmedCategoriesResponse(view.ConfirmedCategories)
|
||||
return response
|
||||
}
|
||||
|
||||
// confirmedCategoriesResponse maps the categories in their stored order. The
|
||||
// result is never nil, so a profile without categories encodes as an empty list.
|
||||
func confirmedCategoriesResponse(categories []domain.CandidateAssessmentCategory) []api.ProfileConfirmedCategory {
|
||||
response := make([]api.ProfileConfirmedCategory, 0, len(categories))
|
||||
for _, category := range categories {
|
||||
response = append(response, confirmedCategoryResponse(category))
|
||||
}
|
||||
return response
|
||||
}
|
||||
|
||||
// confirmedCategoryResponse maps a stored category, including its basis, so a
|
||||
// demonstration grade is never returned as if an assessment had measured it.
|
||||
func confirmedCategoryResponse(category domain.CandidateAssessmentCategory) api.ProfileConfirmedCategory {
|
||||
snapshot := category.Snapshot()
|
||||
return api.ProfileConfirmedCategory{
|
||||
Specialization: api.SpecializationCode(snapshot.Specialization),
|
||||
Grade: api.GradeCode(snapshot.Grade),
|
||||
Basis: api.EvidenceBasis(snapshot.Source),
|
||||
ConfirmedAt: api.Timestamp(snapshot.AssignedAt),
|
||||
AttemptID: snapshot.SourceAttemptID.UUID(),
|
||||
}
|
||||
}
|
||||
|
||||
func candidateProfileTerms(content domain.CandidateProfileContent) api.ProfileTerms {
|
||||
terms := api.ProfileTerms{}
|
||||
if location, ok := content.Location(); ok {
|
||||
|
||||
@@ -0,0 +1,48 @@
|
||||
package v1
|
||||
|
||||
import (
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/google/uuid"
|
||||
|
||||
"lincodex/backend/internal/adapter/primary/http/api"
|
||||
"lincodex/backend/internal/domain"
|
||||
"lincodex/backend/internal/usecase/profile"
|
||||
)
|
||||
|
||||
func TestCandidateProfileResponseCarriesConfirmedCategoriesWithTheirBasis(t *testing.T) {
|
||||
userID := uuid.New()
|
||||
saved, err := domain.EmptyCandidateProfile(userID)
|
||||
if err != nil {
|
||||
t.Fatalf("EmptyCandidateProfile() error = %v", err)
|
||||
}
|
||||
assignedAt := time.Date(2026, time.October, 8, 10, 30, 0, 0, time.UTC)
|
||||
attemptID := uuid.New()
|
||||
category, err := domain.RestoreCandidateAssessmentCategory(domain.CandidateAssessmentCategorySnapshot{
|
||||
CandidateID: userID, Specialization: domain.SpecializationBackend, Grade: domain.GradeJunior,
|
||||
SourceAttemptID: domain.AssessmentAttemptID(attemptID), SourceReviewID: uuid.New(),
|
||||
ProductPolicyVersionID: domain.PolicyVersionID(uuid.New()), ProductPolicyVersion: 1,
|
||||
OpeningID: uuid.New(), OpeningManifestHash: [32]byte{1},
|
||||
Source: domain.AssessmentCategorySourceSyntheticDemo, CalibrationStatus: domain.AssessmentCategoryCalibrationUncalibrated,
|
||||
AssignedAt: assignedAt,
|
||||
})
|
||||
if err != nil {
|
||||
t.Fatalf("RestoreCandidateAssessmentCategory() error = %v", err)
|
||||
}
|
||||
|
||||
response := candidateProfileResponse(profile.View{Profile: saved, ConfirmedCategories: []domain.CandidateAssessmentCategory{category}})
|
||||
if len(response.ConfirmedCategories) != 1 {
|
||||
t.Fatalf("confirmed_categories = %+v, want one category", response.ConfirmedCategories)
|
||||
}
|
||||
got := response.ConfirmedCategories[0]
|
||||
if got.Specialization != api.SpecializationCodeBackend || got.Grade != api.GradeCodeJunior ||
|
||||
got.Basis != api.EvidenceBasisSyntheticDemo || got.AttemptID != attemptID || time.Time(got.ConfirmedAt) != assignedAt {
|
||||
t.Fatalf("confirmed category = %+v, want backend junior from attempt %s with basis synthetic_demo", got, attemptID)
|
||||
}
|
||||
|
||||
empty := candidateProfileResponse(profile.View{Profile: saved})
|
||||
if empty.ConfirmedCategories == nil || len(empty.ConfirmedCategories) != 0 {
|
||||
t.Fatalf("confirmed_categories of an empty view = %#v, want an empty list", empty.ConfirmedCategories)
|
||||
}
|
||||
}
|
||||
@@ -339,6 +339,29 @@ func (repository assessmentAttemptRepository) GetCandidateCategory(
|
||||
return category, true, nil
|
||||
}
|
||||
|
||||
func (repository assessmentAttemptRepository) ListCandidateCategories(
|
||||
ctx context.Context,
|
||||
candidateID uuid.UUID,
|
||||
) ([]domain.CandidateAssessmentCategory, error) {
|
||||
const location = "assessmentAttemptRepository.ListCandidateCategories"
|
||||
if candidateID == uuid.Nil {
|
||||
return nil, fmt.Errorf("%s - candidate scope is invalid: %w", location, domain.ErrInvalidAssessmentCategory)
|
||||
}
|
||||
rows, err := repository.queries.ListCandidateAssessmentCategories(ctx, pgUUID(candidateID))
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("%s - select current categories: %w", location, mapAssessmentAttemptError(err))
|
||||
}
|
||||
categories := make([]domain.CandidateAssessmentCategory, 0, len(rows))
|
||||
for _, row := range rows {
|
||||
category, err := restoreCandidateAssessmentCategory(row)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("%s - stored category is invalid: %w", location, err)
|
||||
}
|
||||
categories = append(categories, category)
|
||||
}
|
||||
return categories, nil
|
||||
}
|
||||
|
||||
func restoreCandidateAssessmentCategory(row sqlc.CandidateAssessmentCategory) (domain.CandidateAssessmentCategory, error) {
|
||||
manifestHash, err := assessmentManifestHash(row.OpeningManifestSha256)
|
||||
if err != nil || !row.CandidateID.Valid || !row.SourceAttemptID.Valid || !row.SourceReviewID.Valid ||
|
||||
|
||||
@@ -154,16 +154,18 @@ func newPrivacyCohortCandidate(
|
||||
const privacyCohortCategoryStrength = domain.CandidateViewStrengthStandard
|
||||
|
||||
// privacyCohortConfirmedCategories reads the current categories selected by
|
||||
// the cohort query: only a specialization and a grade of each, never the
|
||||
// attempt, score, policy, or review that produced it.
|
||||
// the cohort query: a specialization, a grade, and the basis of each, never the
|
||||
// attempt, score, policy, or review that produced it. A category without a
|
||||
// known basis is rejected rather than shown as a real confirmation.
|
||||
func privacyCohortConfirmedCategories(value any) ([]domain.CandidateViewConfirmedCategoryInput, error) {
|
||||
encoded, err := privacyCohortEncodedJSONBytes(value)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("invalid confirmed categories: %w", domain.ErrInvalidCandidateViewSource)
|
||||
}
|
||||
var stored []struct {
|
||||
Specialization domain.SpecializationCode `json:"specialization"`
|
||||
Grade domain.GradeCode `json:"grade"`
|
||||
Specialization domain.SpecializationCode `json:"specialization"`
|
||||
Grade domain.GradeCode `json:"grade"`
|
||||
Source domain.AssessmentCategorySource `json:"source"`
|
||||
}
|
||||
decoder := json.NewDecoder(bytes.NewReader(encoded))
|
||||
decoder.DisallowUnknownFields()
|
||||
@@ -172,8 +174,12 @@ func privacyCohortConfirmedCategories(value any) ([]domain.CandidateViewConfirme
|
||||
}
|
||||
categories := make([]domain.CandidateViewConfirmedCategoryInput, 0, len(stored))
|
||||
for _, category := range stored {
|
||||
if !category.Source.IsKnown() {
|
||||
return nil, fmt.Errorf("confirmed category has an unknown basis: %w", domain.ErrInvalidCandidateViewSource)
|
||||
}
|
||||
categories = append(categories, domain.CandidateViewConfirmedCategoryInput{
|
||||
Specialization: category.Specialization, Grade: category.Grade, Strength: privacyCohortCategoryStrength,
|
||||
Specialization: category.Specialization, Grade: category.Grade,
|
||||
Strength: privacyCohortCategoryStrength, Basis: category.Source,
|
||||
})
|
||||
}
|
||||
return categories, nil
|
||||
|
||||
@@ -0,0 +1,35 @@
|
||||
package postgres
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"testing"
|
||||
|
||||
"lincodex/backend/internal/domain"
|
||||
)
|
||||
|
||||
func TestPrivacyCohortConfirmedCategoriesCarryTheStoredBasis(t *testing.T) {
|
||||
categories, err := privacyCohortConfirmedCategories(`[{"specialization":"backend","grade":"junior","source":"synthetic_demo"}]`)
|
||||
if err != nil {
|
||||
t.Fatalf("privacyCohortConfirmedCategories() error = %v", err)
|
||||
}
|
||||
if len(categories) != 1 || categories[0].Specialization != domain.SpecializationBackend ||
|
||||
categories[0].Grade != domain.GradeJunior || categories[0].Basis != domain.AssessmentCategorySourceSyntheticDemo {
|
||||
t.Fatalf("categories = %+v, want the backend junior category with its synthetic basis", categories)
|
||||
}
|
||||
}
|
||||
|
||||
// A category whose basis is missing or unknown must not reach a card as if it
|
||||
// were a real confirmation, so the projection fails instead of guessing.
|
||||
func TestPrivacyCohortConfirmedCategoriesRejectAnUnknownBasis(t *testing.T) {
|
||||
for name, value := range map[string]string{
|
||||
"missing basis": `[{"specialization":"backend","grade":"junior"}]`,
|
||||
"unknown basis": `[{"specialization":"backend","grade":"junior","source":"real"}]`,
|
||||
"unknown property": `[{"specialization":"backend","grade":"junior","source":"synthetic_demo","score":9}]`,
|
||||
} {
|
||||
t.Run(name, func(t *testing.T) {
|
||||
if _, err := privacyCohortConfirmedCategories(value); !errors.Is(err, domain.ErrInvalidCandidateViewSource) {
|
||||
t.Fatalf("privacyCohortConfirmedCategories() error = %v, want invalid candidate view source", err)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
@@ -244,6 +244,49 @@ func (q *Queries) InsertSyntheticCategoryReview(ctx context.Context, arg InsertS
|
||||
return result.RowsAffected(), nil
|
||||
}
|
||||
|
||||
const listCandidateAssessmentCategories = `-- name: ListCandidateAssessmentCategories :many
|
||||
SELECT candidate_id, specialization, grade, source_attempt_id, source_review_id,
|
||||
product_policy_version_id, product_policy_version, grading_policy_version_id,
|
||||
opening_id, opening_manifest_sha256, source, calibration_status, assigned_at
|
||||
FROM candidate_assessment_categories
|
||||
WHERE candidate_id = $1
|
||||
ORDER BY specialization
|
||||
`
|
||||
|
||||
func (q *Queries) ListCandidateAssessmentCategories(ctx context.Context, candidateID pgtype.UUID) ([]CandidateAssessmentCategory, error) {
|
||||
rows, err := q.db.Query(ctx, listCandidateAssessmentCategories, candidateID)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer rows.Close()
|
||||
var items []CandidateAssessmentCategory
|
||||
for rows.Next() {
|
||||
var i CandidateAssessmentCategory
|
||||
if err := rows.Scan(
|
||||
&i.CandidateID,
|
||||
&i.Specialization,
|
||||
&i.Grade,
|
||||
&i.SourceAttemptID,
|
||||
&i.SourceReviewID,
|
||||
&i.ProductPolicyVersionID,
|
||||
&i.ProductPolicyVersion,
|
||||
&i.GradingPolicyVersionID,
|
||||
&i.OpeningID,
|
||||
&i.OpeningManifestSha256,
|
||||
&i.Source,
|
||||
&i.CalibrationStatus,
|
||||
&i.AssignedAt,
|
||||
); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
items = append(items, i)
|
||||
}
|
||||
if err := rows.Err(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return items, nil
|
||||
}
|
||||
|
||||
const listCandidateAssessmentResults = `-- name: ListCandidateAssessmentResults :many
|
||||
SELECT attempt_id, user_id, schema_version, result_snapshot::text,
|
||||
COALESCE(category_decision::text, '')::text AS category_decision, current_confirmed_grade, decided_at
|
||||
|
||||
@@ -57,7 +57,11 @@ SELECT
|
||||
COALESCE(
|
||||
(
|
||||
SELECT jsonb_agg(
|
||||
jsonb_build_object('specialization', category.specialization, 'grade', category.grade)
|
||||
jsonb_build_object(
|
||||
'specialization', category.specialization,
|
||||
'grade', category.grade,
|
||||
'source', category.source
|
||||
)
|
||||
ORDER BY category.specialization
|
||||
)::text
|
||||
FROM candidate_assessment_categories AS category
|
||||
@@ -286,7 +290,11 @@ SELECT
|
||||
COALESCE(
|
||||
(
|
||||
SELECT jsonb_agg(
|
||||
jsonb_build_object('specialization', category.specialization, 'grade', category.grade)
|
||||
jsonb_build_object(
|
||||
'specialization', category.specialization,
|
||||
'grade', category.grade,
|
||||
'source', category.source
|
||||
)
|
||||
ORDER BY category.specialization
|
||||
)::text
|
||||
FROM candidate_assessment_categories AS category
|
||||
|
||||
@@ -656,6 +656,7 @@ type Querier interface {
|
||||
ListAssessmentOriginMarks(ctx context.Context, attemptID pgtype.UUID) ([]AssessmentAttemptOriginMark, error)
|
||||
// Reads the exact family membership pinned by a training binding.
|
||||
ListAssessmentTrainingBindingFamilies(ctx context.Context, bindingID pgtype.UUID) ([]ListAssessmentTrainingBindingFamiliesRow, error)
|
||||
ListCandidateAssessmentCategories(ctx context.Context, candidateID pgtype.UUID) ([]CandidateAssessmentCategory, error)
|
||||
// The caller validates and signs an opaque owner-bound cursor. This query
|
||||
// applies the keyset to the same stable order and fetches one extra row.
|
||||
ListCandidateAssessmentResults(ctx context.Context, arg ListCandidateAssessmentResultsParams) ([]ListCandidateAssessmentResultsRow, error)
|
||||
|
||||
@@ -37,6 +37,11 @@ type AssessmentCategorySource string
|
||||
|
||||
const AssessmentCategorySourceSyntheticDemo AssessmentCategorySource = "synthetic_demo"
|
||||
|
||||
// IsKnown reports whether source is a value that the category contract names.
|
||||
func (source AssessmentCategorySource) IsKnown() bool {
|
||||
return source == AssessmentCategorySourceSyntheticDemo
|
||||
}
|
||||
|
||||
// AssessmentSyntheticCategoryReviewSnapshot pins the reviewed synthetic bank
|
||||
// opening to the exact product policy under which demo categories may be assigned.
|
||||
type AssessmentSyntheticCategoryReviewSnapshot struct {
|
||||
|
||||
@@ -119,6 +119,10 @@ var specializationCodes = []SpecializationCode{
|
||||
// IsKnown reports whether code is a specialization of the catalog.
|
||||
func (code SpecializationCode) IsKnown() bool { return slices.Contains(specializationCodes, code) }
|
||||
|
||||
// SpecializationCatalog returns the specializations in catalog order. The
|
||||
// result is a copy that the caller may change.
|
||||
func SpecializationCatalog() []SpecializationCode { return slices.Clone(specializationCodes) }
|
||||
|
||||
// GradeCode is a grade of the MVP scale. The same codes describe a
|
||||
// self-assessed grade, which the candidate states, and a confirmed grade,
|
||||
// which only an assessment result establishes; a profile stores only the
|
||||
|
||||
@@ -176,6 +176,9 @@ type CandidateViewConfirmedCategoryInput struct {
|
||||
Specialization SpecializationCode
|
||||
Grade GradeCode
|
||||
Strength CandidateViewConfirmationStrength
|
||||
// Basis says what the grade rests on. It is required: a category without
|
||||
// a basis would read as a real confirmation.
|
||||
Basis AssessmentCategorySource
|
||||
}
|
||||
|
||||
type candidateViewStackClaim struct {
|
||||
@@ -228,12 +231,15 @@ func CandidateViewProfileFromContent(content CandidateProfileContent) CandidateV
|
||||
return profile
|
||||
}
|
||||
|
||||
// CandidateViewCategory is the category and coarse strength shown only when
|
||||
// categories were explicitly included in the publication.
|
||||
// CandidateViewCategory is the category, its coarse strength, and its basis,
|
||||
// shown only when categories were explicitly included in the publication.
|
||||
// The field order matches CandidateViewConfirmedCategoryInput so that the two
|
||||
// convert into each other.
|
||||
type CandidateViewCategory struct {
|
||||
Specialization SpecializationCode `json:"specialization"`
|
||||
Grade GradeCode `json:"grade"`
|
||||
Strength CandidateViewConfirmationStrength `json:"strength"`
|
||||
Basis AssessmentCategorySource `json:"basis"`
|
||||
}
|
||||
|
||||
// CandidateViewSelfAssessment is a candidate-declared specialization and
|
||||
@@ -381,7 +387,8 @@ func IsCandidateViewPseudonym(value string) bool {
|
||||
func validateCandidateViewConfirmations(confirmations []CandidateViewConfirmedCategoryInput) error {
|
||||
seen := make(map[SpecializationCode]struct{}, len(confirmations))
|
||||
for _, confirmation := range confirmations {
|
||||
if !confirmation.Specialization.IsKnown() || !confirmation.Grade.IsKnown() || !confirmation.Strength.IsKnown() {
|
||||
if !confirmation.Specialization.IsKnown() || !confirmation.Grade.IsKnown() || !confirmation.Strength.IsKnown() ||
|
||||
!confirmation.Basis.IsKnown() {
|
||||
return ErrInvalidAnonymousCandidateView
|
||||
}
|
||||
if _, duplicate := seen[confirmation.Specialization]; duplicate {
|
||||
|
||||
@@ -144,6 +144,7 @@ func TestAnonymousCandidateViewUsesPublishedAllowlist(t *testing.T) {
|
||||
AsOf: time.Date(2026, 10, 6, 0, 0, 0, 0, time.UTC),
|
||||
ConfirmedCategories: []CandidateViewConfirmedCategoryInput{{
|
||||
Specialization: SpecializationBackend, Grade: GradeMiddle, Strength: CandidateViewStrengthStrong,
|
||||
Basis: AssessmentCategorySourceSyntheticDemo,
|
||||
}},
|
||||
WorkFormats: []QuestionnaireWorkFormat{QuestionnaireWorkFormatRemote, QuestionnaireWorkFormatHybrid},
|
||||
})
|
||||
@@ -250,6 +251,7 @@ func TestAnonymousCandidateViewKeepsCategoriesSeparateFromSelfAssessment(t *test
|
||||
}
|
||||
category := CandidateViewConfirmedCategoryInput{
|
||||
Specialization: SpecializationBackend, Grade: GradeMiddle, Strength: CandidateViewStrengthStandard,
|
||||
Basis: AssessmentCategorySourceSyntheticDemo,
|
||||
}
|
||||
newView := func(field CardField) AnonymousCandidateViewDTO {
|
||||
t.Helper()
|
||||
@@ -417,3 +419,24 @@ func containsCandidateViewSkill(skills []CandidateViewSkillCode, wanted Candidat
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
// A category without a known basis would read as a real confirmation, so the
|
||||
// anonymous view refuses it instead of defaulting the basis.
|
||||
func TestAnonymousCandidateViewRequiresTheBasisOfEveryCategory(t *testing.T) {
|
||||
fields, err := NewCardFieldSet([]CardField{CardFieldCategories})
|
||||
if err != nil {
|
||||
t.Fatalf("NewCardFieldSet() error = %v", err)
|
||||
}
|
||||
for _, basis := range []AssessmentCategorySource{"", "real"} {
|
||||
_, err := NewAnonymousCandidateView(CandidateViewInput{
|
||||
Pseudonym: candidateViewTestPseudonym(t, uuid.New(), uuid.New()), PublishedFields: fields,
|
||||
AsOf: time.Date(2026, 10, 6, 0, 0, 0, 0, time.UTC),
|
||||
ConfirmedCategories: []CandidateViewConfirmedCategoryInput{{
|
||||
Specialization: SpecializationBackend, Grade: GradeJunior, Strength: CandidateViewStrengthStandard, Basis: basis,
|
||||
}},
|
||||
})
|
||||
if err == nil {
|
||||
t.Fatalf("NewAnonymousCandidateView(basis %q) error = nil, want rejection", basis)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -273,6 +273,11 @@ type AssessmentAttemptRepository interface {
|
||||
specialization domain.SpecializationCode,
|
||||
) (domain.CandidateAssessmentCategory, bool, error)
|
||||
|
||||
// ListCandidateCategories returns the current category of each
|
||||
// specialization the candidate holds, ordered by specialization code.
|
||||
// Callers that need catalog order sort the result themselves. It is a read.
|
||||
ListCandidateCategories(ctx context.Context, candidateID uuid.UUID) ([]domain.CandidateAssessmentCategory, error)
|
||||
|
||||
// GetSyntheticCategoryReview requires the complete immutable opening and
|
||||
// product-policy pins; gradingPolicyID must match the opening's policy.
|
||||
GetSyntheticCategoryReview(
|
||||
|
||||
@@ -29,8 +29,12 @@ type AssessmentAvailability struct {
|
||||
}
|
||||
|
||||
type SpecializationAvailability struct {
|
||||
Specialization domain.SpecializationCode
|
||||
Specialization domain.SpecializationCode
|
||||
// ConfirmedGrade and ConfirmedBasis are set together from the current
|
||||
// category of the specialization, or both are nil. The basis keeps a
|
||||
// demonstration grade from reading as a real confirmation.
|
||||
ConfirmedGrade *domain.GradeCode
|
||||
ConfirmedBasis *domain.AssessmentCategorySource
|
||||
ActiveAttemptID *domain.AssessmentAttemptID
|
||||
Grades []GradeAvailability
|
||||
}
|
||||
@@ -108,6 +112,7 @@ type assessmentAvailabilityReads struct {
|
||||
selections []outbound.AssessmentAvailabilitySelection
|
||||
active map[domain.SpecializationCode]outbound.AssessmentActiveAttemptSummary
|
||||
rootHistory map[domain.SpecializationCode][]outbound.AssessmentRootAvailabilitySummary
|
||||
categories map[domain.SpecializationCode]domain.CandidateAssessmentCategory
|
||||
quota outbound.AssessmentRootQuotaSnapshot
|
||||
seen map[domain.AssessmentFamilyKey]struct{}
|
||||
}
|
||||
@@ -164,6 +169,14 @@ func readAssessmentAvailability(
|
||||
if err != nil {
|
||||
return assessmentAvailabilityReads{}, fmt.Errorf("%s - read active attempts: %w", location, err)
|
||||
}
|
||||
categories, err := unit.AssessmentAttempts().ListCandidateCategories(ctx, userID)
|
||||
if err != nil {
|
||||
return assessmentAvailabilityReads{}, fmt.Errorf("%s - read confirmed categories: %w", location, err)
|
||||
}
|
||||
reads.categories = make(map[domain.SpecializationCode]domain.CandidateAssessmentCategory, len(categories))
|
||||
for _, category := range categories {
|
||||
reads.categories[category.Snapshot().Specialization] = category
|
||||
}
|
||||
window := policy.AttemptWindow.Duration()
|
||||
reads.quota, err = unit.AssessmentAttempts().GetRootQuotaSnapshot(
|
||||
ctx, userID, now.Add(-window), now, window, policy.MaxAttemptsPerWindow,
|
||||
@@ -245,6 +258,12 @@ func buildSpecializationAvailability(
|
||||
id := active.ID
|
||||
result.ActiveAttemptID = &id
|
||||
}
|
||||
if category, confirmed := reads.categories[answer.Specialization]; confirmed {
|
||||
snapshot := category.Snapshot()
|
||||
grade, basis := snapshot.Grade, snapshot.Source
|
||||
result.ConfirmedGrade = &grade
|
||||
result.ConfirmedBasis = &basis
|
||||
}
|
||||
for _, grade := range availabilityGrades {
|
||||
result.Grades = append(result.Grades, buildGradeAvailability(
|
||||
answer, grade, reads, policy, now, seconds, itemCount, hasActive,
|
||||
|
||||
@@ -4,6 +4,8 @@ import (
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/google/uuid"
|
||||
|
||||
"lincodex/backend/internal/domain"
|
||||
"lincodex/backend/internal/port/outbound"
|
||||
)
|
||||
@@ -98,3 +100,39 @@ func TestPlatformFailureDoesNotAddPromotionCooldown(t *testing.T) {
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
// The confirmed grade of a specialization and its basis come from the same
|
||||
// stored category, so a demonstration grade is never returned without its basis.
|
||||
func TestAvailabilityCarriesTheConfirmedGradeWithItsBasis(t *testing.T) {
|
||||
now := time.Date(2026, time.October, 9, 12, 0, 0, 0, time.UTC)
|
||||
policy := domain.AssessmentPolicy{Attempt: &domain.AssessmentAttemptPolicy{RealMode: domain.AssessmentRealModeDemoBasic}}
|
||||
category, err := domain.RestoreCandidateAssessmentCategory(domain.CandidateAssessmentCategorySnapshot{
|
||||
CandidateID: uuid.New(), Specialization: domain.SpecializationBackend, Grade: domain.GradeJunior,
|
||||
SourceAttemptID: domain.AssessmentAttemptID(uuid.New()), SourceReviewID: uuid.New(),
|
||||
ProductPolicyVersionID: domain.PolicyVersionID(uuid.New()), ProductPolicyVersion: 1,
|
||||
OpeningID: uuid.New(), OpeningManifestHash: [32]byte{1},
|
||||
Source: domain.AssessmentCategorySourceSyntheticDemo, CalibrationStatus: domain.AssessmentCategoryCalibrationUncalibrated,
|
||||
AssignedAt: now,
|
||||
})
|
||||
if err != nil {
|
||||
t.Fatalf("RestoreCandidateAssessmentCategory() error = %v", err)
|
||||
}
|
||||
reads := assessmentAvailabilityReads{categories: map[domain.SpecializationCode]domain.CandidateAssessmentCategory{
|
||||
domain.SpecializationBackend: category,
|
||||
}}
|
||||
|
||||
confirmed := buildSpecializationAvailability(
|
||||
domain.QuestionnaireSpecialization{Specialization: domain.SpecializationBackend}, reads, policy, now, 60, 12)
|
||||
if confirmed.ConfirmedGrade == nil || *confirmed.ConfirmedGrade != domain.GradeJunior {
|
||||
t.Fatalf("ConfirmedGrade = %v, want junior", confirmed.ConfirmedGrade)
|
||||
}
|
||||
if confirmed.ConfirmedBasis == nil || *confirmed.ConfirmedBasis != domain.AssessmentCategorySourceSyntheticDemo {
|
||||
t.Fatalf("ConfirmedBasis = %v, want synthetic_demo", confirmed.ConfirmedBasis)
|
||||
}
|
||||
|
||||
unconfirmed := buildSpecializationAvailability(
|
||||
domain.QuestionnaireSpecialization{Specialization: domain.SpecializationFrontend}, reads, policy, now, 60, 12)
|
||||
if unconfirmed.ConfirmedGrade != nil || unconfirmed.ConfirmedBasis != nil {
|
||||
t.Fatalf("unconfirmed specialization reports grade %v and basis %v, want none", unconfirmed.ConfirmedGrade, unconfirmed.ConfirmedBasis)
|
||||
}
|
||||
}
|
||||
@@ -639,10 +639,10 @@ func (seeder *Seeder) ensureProfile(ctx context.Context, spec accountSpec, userI
|
||||
if err != nil {
|
||||
return false, fmt.Errorf("read profile: %w", err)
|
||||
}
|
||||
if current.Version() > 0 {
|
||||
if current.Profile.Version() > 0 {
|
||||
return false, nil
|
||||
}
|
||||
if _, err := seeder.deps.Profiles.SaveMyProfile(ctx, userID, current.Version(), profileInput(spec)); err != nil {
|
||||
if _, err := seeder.deps.Profiles.SaveMyProfile(ctx, userID, current.Profile.Version(), profileInput(spec)); err != nil {
|
||||
return false, fmt.Errorf("save profile: %w", err)
|
||||
}
|
||||
return true, nil
|
||||
|
||||
@@ -2,9 +2,11 @@
|
||||
package profile
|
||||
|
||||
import (
|
||||
"cmp"
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
"slices"
|
||||
"time"
|
||||
|
||||
"github.com/google/uuid"
|
||||
@@ -21,6 +23,16 @@ var (
|
||||
ErrEmailNotVerified = errors.New("candidate profile requires a confirmed email")
|
||||
)
|
||||
|
||||
// View is the profile as the candidate reads it: the saved document and the
|
||||
// categories that assessment results confirmed. The categories are derived by
|
||||
// the server, are read-only, and are never part of the saved document.
|
||||
type View struct {
|
||||
Profile domain.CandidateProfile
|
||||
// ConfirmedCategories holds at most one category per specialization, in
|
||||
// catalog order.
|
||||
ConfirmedCategories []domain.CandidateAssessmentCategory
|
||||
}
|
||||
|
||||
// Service is stateless between calls. Profile data, its history, and onboarding
|
||||
// movement are written through one transaction.
|
||||
type Service struct {
|
||||
@@ -40,27 +52,28 @@ func NewService(transactor outbound.Transactor, clock func() time.Time) *Service
|
||||
return &Service{transactor: transactor, clock: clock}
|
||||
}
|
||||
|
||||
// GetMyProfile reads only the profile owned by userID. Version zero means the
|
||||
// GetMyProfile reads only the profile owned by userID, with the categories
|
||||
// that the candidate's assessment results confirmed. Version zero means the
|
||||
// candidate has not saved a profile yet.
|
||||
func (service *Service) GetMyProfile(ctx context.Context, userID uuid.UUID) (domain.CandidateProfile, error) {
|
||||
func (service *Service) GetMyProfile(ctx context.Context, userID uuid.UUID) (View, error) {
|
||||
const location = "Service.GetMyProfile"
|
||||
if userID == uuid.Nil {
|
||||
return domain.CandidateProfile{}, fmt.Errorf("%s - user ID must be set: %w", location, domain.ErrInvalidCandidateProfile)
|
||||
return View{}, fmt.Errorf("%s - user ID must be set: %w", location, domain.ErrInvalidCandidateProfile)
|
||||
}
|
||||
var result domain.CandidateProfile
|
||||
var result View
|
||||
err := service.transactor.WithinTransaction(ctx, func(ctx context.Context, unit outbound.UnitOfWork) error {
|
||||
if err := requireCandidate(ctx, unit, userID, location); err != nil {
|
||||
return err
|
||||
}
|
||||
var err error
|
||||
result, err = unit.CandidateProfiles().Get(ctx, userID)
|
||||
profile, err := unit.CandidateProfiles().Get(ctx, userID)
|
||||
if err != nil {
|
||||
return fmt.Errorf("%s - read profile: %w", location, err)
|
||||
}
|
||||
return nil
|
||||
result, err = readView(ctx, unit, userID, profile, location)
|
||||
return err
|
||||
})
|
||||
if err != nil {
|
||||
return domain.CandidateProfile{}, fmt.Errorf("%s - transaction: %w", location, err)
|
||||
return View{}, fmt.Errorf("%s - transaction: %w", location, err)
|
||||
}
|
||||
return result, nil
|
||||
}
|
||||
@@ -73,16 +86,16 @@ func (service *Service) SaveMyProfile(
|
||||
userID uuid.UUID,
|
||||
expectedVersion int64,
|
||||
input domain.CandidateProfileInput,
|
||||
) (domain.CandidateProfile, error) {
|
||||
) (View, error) {
|
||||
const location = "Service.SaveMyProfile"
|
||||
if userID == uuid.Nil {
|
||||
return domain.CandidateProfile{}, fmt.Errorf("%s - user ID must be set: %w", location, domain.ErrInvalidCandidateProfile)
|
||||
return View{}, fmt.Errorf("%s - user ID must be set: %w", location, domain.ErrInvalidCandidateProfile)
|
||||
}
|
||||
at := service.clock().UTC()
|
||||
if at.IsZero() {
|
||||
return domain.CandidateProfile{}, fmt.Errorf("%s - application clock returned zero: %w", location, domain.ErrInvalidCandidateProfile)
|
||||
return View{}, fmt.Errorf("%s - application clock returned zero: %w", location, domain.ErrInvalidCandidateProfile)
|
||||
}
|
||||
var result domain.CandidateProfile
|
||||
var result View
|
||||
err := service.transactor.WithinTransaction(ctx, func(ctx context.Context, unit outbound.UnitOfWork) error {
|
||||
if err := requireCandidate(ctx, unit, userID, location); err != nil {
|
||||
return err
|
||||
@@ -105,18 +118,56 @@ func (service *Service) SaveMyProfile(
|
||||
if err := repository.AdvanceOnboarding(ctx, userID, at); err != nil {
|
||||
return fmt.Errorf("%s - advance onboarding: %w", location, err)
|
||||
}
|
||||
result = updated
|
||||
return nil
|
||||
result, err = readView(ctx, unit, userID, updated, location)
|
||||
return err
|
||||
})
|
||||
if err != nil {
|
||||
if errors.Is(err, outbound.ErrCandidateProfileVersionConflict) || errors.Is(err, domain.ErrCandidateProfileVersionConflict) {
|
||||
return domain.CandidateProfile{}, fmt.Errorf("%s - transaction: %w", location, domain.ErrCandidateProfileVersionConflict)
|
||||
return View{}, fmt.Errorf("%s - transaction: %w", location, domain.ErrCandidateProfileVersionConflict)
|
||||
}
|
||||
return domain.CandidateProfile{}, fmt.Errorf("%s - transaction: %w", location, err)
|
||||
return View{}, fmt.Errorf("%s - transaction: %w", location, err)
|
||||
}
|
||||
return result, nil
|
||||
}
|
||||
|
||||
// readView attaches the confirmed categories of the candidate to a profile
|
||||
// that was read or written in the same transaction.
|
||||
func readView(
|
||||
ctx context.Context,
|
||||
unit outbound.UnitOfWork,
|
||||
userID uuid.UUID,
|
||||
profile domain.CandidateProfile,
|
||||
location string,
|
||||
) (View, error) {
|
||||
categories, err := unit.AssessmentAttempts().ListCandidateCategories(ctx, userID)
|
||||
if err != nil {
|
||||
return View{}, fmt.Errorf("%s - read confirmed categories: %w", location, err)
|
||||
}
|
||||
return View{Profile: profile, ConfirmedCategories: inCatalogOrder(categories)}, nil
|
||||
}
|
||||
|
||||
// inCatalogOrder sorts the categories by their place in the catalog. A
|
||||
// category outside the catalog cannot exist (the storage constraint and the
|
||||
// domain both reject it), so it sorts last instead of being dropped silently.
|
||||
func inCatalogOrder(categories []domain.CandidateAssessmentCategory) []domain.CandidateAssessmentCategory {
|
||||
position := make(map[domain.SpecializationCode]int, len(domain.SpecializationCatalog()))
|
||||
for index, code := range domain.SpecializationCatalog() {
|
||||
position[code] = index
|
||||
}
|
||||
sorted := slices.Clone(categories)
|
||||
slices.SortStableFunc(sorted, func(left, right domain.CandidateAssessmentCategory) int {
|
||||
return cmp.Compare(catalogPosition(position, left), catalogPosition(position, right))
|
||||
})
|
||||
return sorted
|
||||
}
|
||||
|
||||
func catalogPosition(position map[domain.SpecializationCode]int, category domain.CandidateAssessmentCategory) int {
|
||||
if index, known := position[category.Snapshot().Specialization]; known {
|
||||
return index
|
||||
}
|
||||
return len(position)
|
||||
}
|
||||
|
||||
func requireCandidate(ctx context.Context, unit outbound.UnitOfWork, userID uuid.UUID, location string) error {
|
||||
user, err := unit.Users().GetByID(ctx, userID)
|
||||
if err != nil {
|
||||
|
||||
@@ -3,6 +3,7 @@ package profile
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
@@ -28,6 +29,8 @@ type profileTestUnit struct {
|
||||
|
||||
users outbound.UserRepository
|
||||
profiles outbound.CandidateProfileRepository
|
||||
// attempts is the zero value by default: a candidate without categories.
|
||||
attempts profileTestAttempts
|
||||
}
|
||||
|
||||
func (unit profileTestUnit) Users() outbound.UserRepository { return unit.users }
|
||||
@@ -36,6 +39,48 @@ func (unit profileTestUnit) CandidateProfiles() outbound.CandidateProfileReposit
|
||||
return unit.profiles
|
||||
}
|
||||
|
||||
func (unit profileTestUnit) AssessmentAttempts() outbound.AssessmentAttemptRepository {
|
||||
return unit.attempts
|
||||
}
|
||||
|
||||
type profileTestAttempts struct {
|
||||
outbound.AssessmentAttemptRepository
|
||||
|
||||
categories []domain.CandidateAssessmentCategory
|
||||
err error
|
||||
}
|
||||
|
||||
func (attempts profileTestAttempts) ListCandidateCategories(
|
||||
_ context.Context,
|
||||
_ uuid.UUID,
|
||||
) ([]domain.CandidateAssessmentCategory, error) {
|
||||
return attempts.categories, attempts.err
|
||||
}
|
||||
|
||||
// profileTestCategory is a stored synthetic demonstration category of the
|
||||
// candidate, as the assessment result that assigned it left it.
|
||||
func profileTestCategory(
|
||||
t *testing.T,
|
||||
candidateID uuid.UUID,
|
||||
specialization domain.SpecializationCode,
|
||||
grade domain.GradeCode,
|
||||
assignedAt time.Time,
|
||||
) domain.CandidateAssessmentCategory {
|
||||
t.Helper()
|
||||
category, err := domain.RestoreCandidateAssessmentCategory(domain.CandidateAssessmentCategorySnapshot{
|
||||
CandidateID: candidateID, Specialization: specialization, Grade: grade,
|
||||
SourceAttemptID: domain.AssessmentAttemptID(uuid.Must(uuid.NewV7())), SourceReviewID: uuid.Must(uuid.NewV7()),
|
||||
ProductPolicyVersionID: domain.PolicyVersionID(uuid.Must(uuid.NewV7())), ProductPolicyVersion: 1,
|
||||
OpeningID: uuid.Must(uuid.NewV7()), OpeningManifestHash: [32]byte{1},
|
||||
Source: domain.AssessmentCategorySourceSyntheticDemo, CalibrationStatus: domain.AssessmentCategoryCalibrationUncalibrated,
|
||||
AssignedAt: assignedAt,
|
||||
})
|
||||
if err != nil {
|
||||
t.Fatalf("RestoreCandidateAssessmentCategory() error = %v", err)
|
||||
}
|
||||
return category
|
||||
}
|
||||
|
||||
type profileTestUsers struct {
|
||||
outbound.UserRepository
|
||||
|
||||
@@ -182,3 +227,93 @@ func TestSaveMyProfileDoesNotAdvanceAfterProfileWriteFailure(t *testing.T) {
|
||||
t.Fatalf("onboarding advances %d times after a failed write, want 0", profiles.advanceCalls)
|
||||
}
|
||||
}
|
||||
|
||||
func TestGetMyProfileReturnsConfirmedCategoriesInCatalogOrder(t *testing.T) {
|
||||
now := time.Date(2026, 10, 7, 12, 0, 0, 0, time.UTC)
|
||||
id := uuid.Must(uuid.NewV7())
|
||||
user := domain.User{ID: id, Scenario: domain.ScenarioCandidate, EmailVerifiedAt: &now}
|
||||
users := &profileTestUsers{user: user}
|
||||
profiles := &profileTestRepository{}
|
||||
profiles.profile, _ = domain.EmptyCandidateProfile(id)
|
||||
// The storage returns codes in alphabetical order; the catalog starts with backend.
|
||||
categories := []domain.CandidateAssessmentCategory{
|
||||
profileTestCategory(t, id, domain.SpecializationQA, domain.GradeIntern, now),
|
||||
profileTestCategory(t, id, domain.SpecializationBackend, domain.GradeJunior, now),
|
||||
profileTestCategory(t, id, domain.SpecializationFrontend, domain.GradeMiddle, now),
|
||||
}
|
||||
attempts := profileTestAttempts{categories: categories}
|
||||
service := NewService(profileTestTransactor{unit: profileTestUnit{users: users, profiles: profiles, attempts: attempts}}, func() time.Time { return now })
|
||||
|
||||
view, err := service.GetMyProfile(context.Background(), id)
|
||||
if err != nil {
|
||||
t.Fatalf("GetMyProfile() error = %v", err)
|
||||
}
|
||||
got := make([]domain.SpecializationCode, 0, len(view.ConfirmedCategories))
|
||||
for _, category := range view.ConfirmedCategories {
|
||||
got = append(got, category.Snapshot().Specialization)
|
||||
}
|
||||
want := []domain.SpecializationCode{domain.SpecializationBackend, domain.SpecializationFrontend, domain.SpecializationQA}
|
||||
if fmt.Sprint(got) != fmt.Sprint(want) {
|
||||
t.Fatalf("confirmed categories = %v, want catalog order %v", got, want)
|
||||
}
|
||||
if snapshot := view.ConfirmedCategories[0].Snapshot(); snapshot.Source != domain.AssessmentCategorySourceSyntheticDemo || snapshot.Grade != domain.GradeJunior {
|
||||
t.Fatalf("first category = %+v, want the synthetic junior category", snapshot)
|
||||
}
|
||||
if view.Profile.UserID() != id {
|
||||
t.Fatalf("profile owner = %s, want %s", view.Profile.UserID(), id)
|
||||
}
|
||||
}
|
||||
|
||||
func TestGetMyProfileWithoutCategoriesReturnsAnEmptyList(t *testing.T) {
|
||||
now := time.Date(2026, 10, 7, 12, 0, 0, 0, time.UTC)
|
||||
id := uuid.Must(uuid.NewV7())
|
||||
users := &profileTestUsers{user: domain.User{ID: id, Scenario: domain.ScenarioCandidate, EmailVerifiedAt: &now}}
|
||||
profiles := &profileTestRepository{}
|
||||
profiles.profile, _ = domain.EmptyCandidateProfile(id)
|
||||
service := NewService(profileTestTransactor{unit: profileTestUnit{users: users, profiles: profiles}}, func() time.Time { return now })
|
||||
|
||||
view, err := service.GetMyProfile(context.Background(), id)
|
||||
if err != nil {
|
||||
t.Fatalf("GetMyProfile() error = %v", err)
|
||||
}
|
||||
if len(view.ConfirmedCategories) != 0 {
|
||||
t.Fatalf("confirmed categories = %d, want none", len(view.ConfirmedCategories))
|
||||
}
|
||||
}
|
||||
|
||||
func TestGetMyProfileFailsWhenCategoriesCannotBeRead(t *testing.T) {
|
||||
now := time.Date(2026, 10, 7, 12, 0, 0, 0, time.UTC)
|
||||
id := uuid.Must(uuid.NewV7())
|
||||
users := &profileTestUsers{user: domain.User{ID: id, Scenario: domain.ScenarioCandidate, EmailVerifiedAt: &now}}
|
||||
profiles := &profileTestRepository{}
|
||||
profiles.profile, _ = domain.EmptyCandidateProfile(id)
|
||||
readErr := errors.New("categories unavailable")
|
||||
attempts := profileTestAttempts{err: readErr}
|
||||
service := NewService(profileTestTransactor{unit: profileTestUnit{users: users, profiles: profiles, attempts: attempts}}, func() time.Time { return now })
|
||||
|
||||
if _, err := service.GetMyProfile(context.Background(), id); !errors.Is(err, readErr) {
|
||||
t.Fatalf("GetMyProfile() error = %v, want the category read failure", err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestSaveMyProfileReturnsTheConfirmedCategoriesAsWell(t *testing.T) {
|
||||
now := time.Date(2026, 10, 7, 12, 0, 0, 0, time.UTC)
|
||||
id := uuid.Must(uuid.NewV7())
|
||||
users := &profileTestUsers{user: domain.User{ID: id, Scenario: domain.ScenarioCandidate, EmailVerifiedAt: &now}}
|
||||
profiles := &profileTestRepository{}
|
||||
profiles.profile, _ = domain.EmptyCandidateProfile(id)
|
||||
attempts := profileTestAttempts{categories: []domain.CandidateAssessmentCategory{
|
||||
profileTestCategory(t, id, domain.SpecializationDSML, domain.GradeMiddle, now),
|
||||
}}
|
||||
service := NewService(profileTestTransactor{unit: profileTestUnit{users: users, profiles: profiles, attempts: attempts}}, func() time.Time { return now })
|
||||
input := domain.CandidateProfileInput{FullName: &domain.ProfileClaimInput[string]{Value: "Anna Sokolova", Status: domain.ProfileClaimConfirmed}}
|
||||
|
||||
view, err := service.SaveMyProfile(context.Background(), id, 0, input)
|
||||
if err != nil {
|
||||
t.Fatalf("SaveMyProfile() error = %v", err)
|
||||
}
|
||||
if view.Profile.Version() != 1 || len(view.ConfirmedCategories) != 1 ||
|
||||
view.ConfirmedCategories[0].Snapshot().Specialization != domain.SpecializationDSML {
|
||||
t.Fatalf("saved view = version %d with categories %v, want version 1 with the ds_ml category", view.Profile.Version(), view.ConfirmedCategories)
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user