118 lines
3.8 KiB
Go
118 lines
3.8 KiB
Go
package demoseed
|
|
|
|
import (
|
|
"Rezina-Backend/internal/domain"
|
|
"os"
|
|
"strings"
|
|
"testing"
|
|
)
|
|
|
|
func TestEnvironmentGuard(t *testing.T) {
|
|
for _, tc := range []struct {
|
|
target, setting string
|
|
allowed bool
|
|
}{
|
|
{"development", "", true}, {"test", "test", true}, {"staging", "staging", true},
|
|
{"", "", false}, {"production", "", false}, {"development", "PRODUCTION", false}, {"test", "prod", false},
|
|
} {
|
|
err := ValidateEnvironment(tc.target, tc.setting)
|
|
if (err == nil) != tc.allowed {
|
|
t.Errorf("target=%q setting=%q err=%v", tc.target, tc.setting, err)
|
|
}
|
|
}
|
|
}
|
|
|
|
func TestAccountsCoverSupportedRoles(t *testing.T) {
|
|
roles := map[string]bool{}
|
|
emails := map[string]bool{}
|
|
for _, a := range Accounts {
|
|
if emails[a.Email] {
|
|
t.Fatalf("duplicate email %s", a.Email)
|
|
}
|
|
emails[a.Email] = true
|
|
roles[a.Role] = true
|
|
if a.Audience == "staff" && !domain.IsAssignableStaffTeamRole(domain.TeamRole(a.Role)) {
|
|
t.Errorf("unsupported staff role %s", a.Role)
|
|
}
|
|
if a.Audience == "customer" && !domain.Role(a.Role).IsCustomerLearnerRole() {
|
|
t.Errorf("unsupported customer role %s", a.Role)
|
|
}
|
|
}
|
|
for _, r := range []string{"SUPER_ADMIN", "ADMIN", "CONTENT_MANAGER", "STUDENT", "OPEN_LEARNER"} {
|
|
if !roles[r] {
|
|
t.Errorf("missing %s", r)
|
|
}
|
|
}
|
|
}
|
|
|
|
func TestMakeupCurriculum(t *testing.T) {
|
|
if err := validateCurriculum(Courses); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
chapters, lessons := 0, 0
|
|
tiers := map[string]bool{}
|
|
answers := map[int]bool{}
|
|
expected := map[string]bool{"makeup-foundations": false, "makeup-bridal": false, "makeup-editorial": false}
|
|
for _, course := range Courses {
|
|
if _, ok := expected[course.Key]; !ok {
|
|
t.Fatalf("unexpected course %s", course.Key)
|
|
}
|
|
expected[course.Key] = true
|
|
tiers[course.Tier] = true
|
|
for _, chapter := range course.Chapters {
|
|
chapters++
|
|
for _, lesson := range chapter.Lessons {
|
|
lessons++
|
|
answers[lesson.CorrectIndex] = true
|
|
if len(lesson.Options) != 3 {
|
|
t.Errorf("%s must have three choices", lesson.Title)
|
|
}
|
|
if strings.Contains(lesson.Question, "best way to improve") {
|
|
t.Errorf("generic quiz content remains in %s", lesson.Title)
|
|
}
|
|
}
|
|
}
|
|
}
|
|
if len(Courses) != 3 || chapters != 6 || lessons != 18 || !tiers["FREE"] || !tiers["PREMIUM"] || len(answers) != 3 {
|
|
t.Fatalf("incomplete makeup fixture: courses=%d chapters=%d lessons=%d answer positions=%v", len(Courses), chapters, lessons, answers)
|
|
}
|
|
for key, present := range expected {
|
|
if !present {
|
|
t.Errorf("missing %s", key)
|
|
}
|
|
}
|
|
}
|
|
|
|
func TestCurriculumRejectsInvalidKnowledgeChecks(t *testing.T) {
|
|
for _, bad := range []Lesson{
|
|
{Title: "Test", Description: "Demo", Question: "Question", Explanation: "Why", Options: []string{"A", "B"}, CorrectIndex: 2},
|
|
{Title: "Test", Description: "Demo", Question: "Question", Explanation: "Why", Options: []string{"A", " a "}, CorrectIndex: 0},
|
|
{Title: "Test", Description: "Demo", Question: "Question", Options: []string{"A", "B"}, CorrectIndex: 0},
|
|
} {
|
|
course := Course{Key: "test", Name: "Test", Description: "Demo", Tier: "FREE", Chapters: []Chapter{{Name: "Chapter", Description: "Demo", Lessons: []Lesson{bad}}}}
|
|
if validateCurriculum([]Course{course}) == nil {
|
|
t.Errorf("accepted invalid lesson %+v", bad)
|
|
}
|
|
}
|
|
}
|
|
|
|
func TestDemoAndMigrationProfileOptionsMatch(t *testing.T) {
|
|
data, err := os.ReadFile("../../db/migrations/000004_makeup_artistry_profiles.up.sql")
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if string(data) != makeupProfileOptionsSQL {
|
|
t.Fatal("standalone seed and deployed profile options differ")
|
|
}
|
|
}
|
|
|
|
func TestMakeupFocusOptionsMatchMigration(t *testing.T) {
|
|
migration, err := os.ReadFile("../../db/migrations/000005_makeup_artistry_focus.up.sql")
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if !strings.Contains(string(migration), strings.TrimSpace(makeupFocusOptionsSQL)) {
|
|
t.Fatal("demo focus choices must match the database migration")
|
|
}
|
|
}
|