Files
lincodex/backend/internal/adapter/secondary/postgres/privacy_cohort_test.go
T

36 lines
1.5 KiB
Go

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)
}
})
}
}