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