45 lines
1.2 KiB
Go
45 lines
1.2 KiB
Go
package demoseed
|
|
|
|
import (
|
|
"Rezina-Backend/internal/domain"
|
|
"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)
|
|
}
|
|
}
|
|
}
|