RezinaLMS-BackEnd/internal/domain/team_roles_test.go
Yared Yemane d276e3060f Accept display-style labels when resolving team invite roles.
Map inputs like Super Admin to built-in SUPER_ADMIN during team_role validation so invite API matches RBAC role keys.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-07-30 00:33:57 -07:00

46 lines
1.3 KiB
Go

package domain
import "testing"
func TestTeamRole_IsBuiltinTeamRole(t *testing.T) {
if !TeamRoleAdmin.IsBuiltinTeamRole() {
t.Fatal("ADMIN should be builtin")
}
if TeamRole("CONTENT_MANAGER_NEW").IsBuiltinTeamRole() {
t.Fatal("custom role should not be builtin")
}
}
func TestTeamRole_RBACRoleForJWT(t *testing.T) {
if got := TeamRoleContentManager.RBACRoleForJWT(); got != RoleAdmin {
t.Fatalf("CONTENT_MANAGER JWT role = %q, want ADMIN", got)
}
if got := TeamRole("CONTENT_MANAGER_NEW").RBACRoleForJWT(); got != Role("CONTENT_MANAGER_NEW") {
t.Fatalf("custom JWT role = %q", got)
}
}
func TestIsForbiddenTeamMemberRole(t *testing.T) {
if !IsForbiddenTeamMemberRole("STUDENT") {
t.Fatal("STUDENT should be forbidden for team members")
}
if IsForbiddenTeamMemberRole("CONTENT_MANAGER_NEW") {
t.Fatal("custom staff role should be allowed")
}
}
func TestCanonicalTeamRoleKey(t *testing.T) {
cases := map[string]string{
"Super Admin": "SUPER_ADMIN",
"super-admin": "SUPER_ADMIN",
"SUPER_ADMIN": "SUPER_ADMIN",
" admin ": "ADMIN",
"Content Manager New": "CONTENT_MANAGER_NEW",
}
for in, want := range cases {
if got := CanonicalTeamRoleKey(in); got != want {
t.Fatalf("CanonicalTeamRoleKey(%q) = %q, want %q", in, got, want)
}
}
}