108 lines
4.4 KiB
Go
108 lines
4.4 KiB
Go
package demoseed
|
|
|
|
import (
|
|
"strings"
|
|
"testing"
|
|
|
|
"lincodex/backend/internal/domain"
|
|
"lincodex/backend/internal/port/outbound"
|
|
)
|
|
|
|
func TestDecideResetAllowsOnlyEmptyOrSyntheticStands(t *testing.T) {
|
|
for _, test := range []struct {
|
|
census outbound.DemoAccountCensus
|
|
want ResetVerdict
|
|
}{
|
|
{outbound.DemoAccountCensus{}, ResetAllowedEmpty},
|
|
{outbound.DemoAccountCensus{Total: 9, Synthetic: 9}, ResetAllowedSynthetic},
|
|
{outbound.DemoAccountCensus{Total: 10, Synthetic: 9}, ResetRefusedOrdinary},
|
|
{outbound.DemoAccountCensus{Total: 1}, ResetRefusedOrdinary},
|
|
} {
|
|
if got := DecideReset(test.census); got != test.want || got.Allowed() == (test.want == ResetRefusedOrdinary) {
|
|
t.Errorf("DecideReset(%+v) = %s, want %s", test.census, got, test.want)
|
|
}
|
|
}
|
|
}
|
|
|
|
func TestSyntheticBundlesAreValidAndStable(t *testing.T) {
|
|
required, err := domain.RequiredPublishedAssessmentFamilies(seedPolicy())
|
|
if err != nil {
|
|
t.Fatalf("RequiredPublishedAssessmentFamilies() error = %v", err)
|
|
}
|
|
full, err := syntheticBundle(fullBundleName, string(FullCategory), fullFamilyStem, int(required))
|
|
if err != nil || len(full.Families) != int(required) {
|
|
t.Fatalf("full bundle = %d families, %v; want %d", len(full.Families), err, required)
|
|
}
|
|
again, err := syntheticBundle(fullBundleName, string(FullCategory), fullFamilyStem, int(required))
|
|
if err != nil || again.Families[len(again.Families)-1].Key != full.Families[len(full.Families)-1].Key ||
|
|
again.Review != full.Review {
|
|
t.Fatal("the bundle differs between two builds, so a repeated import would conflict")
|
|
}
|
|
for _, family := range full.Families {
|
|
if family.AnswerKey.AnswerFormat != domain.AnswerFormatInteger || !strings.Contains(family.Title, "synthetic demo") {
|
|
t.Errorf("family %s has format %q and title %q", family.Key, family.AnswerKey.AnswerFormat, family.Title)
|
|
}
|
|
}
|
|
training := seedPolicy().Assessment.Training
|
|
if training == nil || seedPolicy().Assessment.Attempt == nil || seedPolicy().Assessment.Attempt.RealMode != domain.AssessmentRealModeDemoBasic {
|
|
t.Fatal("the seed policy lacks the express mode or the demo_basic attempt settings")
|
|
}
|
|
if _, err := syntheticBundle(trainingBundleName, TrainingCategory, trainingFamilyStem, int(training.DemoExpressItemCount)); err != nil {
|
|
t.Fatalf("training bundle error = %v", err)
|
|
}
|
|
if _, err := syntheticBundle(fullBundleName, string(FullCategory), fullFamilyStem, 0); err == nil {
|
|
t.Fatal("an empty bundle was accepted")
|
|
}
|
|
}
|
|
|
|
func TestIntegerAnswerHasTheIntendedCorrectness(t *testing.T) {
|
|
variant := domain.AssessmentVariant{AnswerFormat: domain.AnswerFormatInteger, ReferenceAnswer: "7"}
|
|
for _, correct := range []bool{true, false} {
|
|
answer, err := integerAnswer(variant, correct)
|
|
if err != nil {
|
|
t.Fatalf("integerAnswer(%v) error = %v", correct, err)
|
|
}
|
|
_, matches, err := domain.CanonicalAssessmentAnswerForVariant(answer, variant)
|
|
if err != nil || matches != correct {
|
|
t.Errorf("integerAnswer(%v) = %s, matches %v, %v", correct, answer, matches, err)
|
|
}
|
|
}
|
|
for _, variant := range []domain.AssessmentVariant{
|
|
{AnswerFormat: domain.AnswerFormatIntegerSequence, ReferenceAnswer: "1 2"},
|
|
{AnswerFormat: domain.AnswerFormatInteger, ReferenceAnswer: "seven"},
|
|
} {
|
|
if _, err := integerAnswer(variant, true); err == nil {
|
|
t.Errorf("integerAnswer(%+v) answered an unsupported variant", variant)
|
|
}
|
|
}
|
|
}
|
|
|
|
func TestDatasetHasTwoRolesOnTheSyntheticDomainAndACohortOfAtLeastFive(t *testing.T) {
|
|
prepared, employers, selfService := 0, 0, 0
|
|
seen := map[string]bool{}
|
|
for _, spec := range accounts() {
|
|
if seen[spec.email()] || !strings.HasSuffix(spec.email(), "@"+SyntheticDomain) {
|
|
t.Fatalf("account %s is repeated or outside the synthetic domain", spec.email())
|
|
}
|
|
seen[spec.email()] = true
|
|
switch spec.role {
|
|
case roleEmployer:
|
|
employers++
|
|
case rolePrepared:
|
|
prepared++
|
|
case roleSelfService:
|
|
selfService++
|
|
}
|
|
if spec.role != roleEmployer && !strings.Contains(spec.fullName, "синтетический профиль") {
|
|
t.Errorf("candidate %s has no synthetic marker in the name", spec.email())
|
|
}
|
|
}
|
|
if employers != 2 || selfService != 1 || prepared < 5 {
|
|
t.Fatalf("dataset has %d employers, %d self-service and %d prepared candidates", employers, selfService, prepared)
|
|
}
|
|
specs := organizations()
|
|
if len(specs) != 2 || specs[0].ownerLocal == specs[1].ownerLocal || specs[1].memberRole.CanManageOrganization() {
|
|
t.Fatal("the organizations do not show two owners and a non-managing second role")
|
|
}
|
|
}
|