package bell_event_test import ( "testing" "github.com/gin-gonic/gin" jwt "github.com/go-admin-team/go-admin-core/sdk/pkg/jwtauth" "go-admin/app/bell/synthetic" ) func TestSyntheticEnabledRequiresExplicitNonProductionOptIn(t *testing.T) { getenv := func(name string) string { if name == synthetic.EnabledEnv { return "true" } return "" } if synthetic.Enabled("prod", getenv) || synthetic.Enabled("production", getenv) { t.Fatal("synthetic route must stay disabled in production even when the flag is set") } if !synthetic.Enabled("dev", getenv) { t.Fatal("explicit development opt-in should enable the synthetic route") } if synthetic.Enabled("dev", func(string) string { return "" }) { t.Fatal("synthetic route must default to disabled") } } func TestSyntheticAdministratorCheckUsesJWTClaims(t *testing.T) { gin.SetMode(gin.TestMode) admin, _ := gin.CreateTestContext(nil) admin.Set(jwt.JwtPayloadKey, jwt.MapClaims{jwt.RoleKey: "admin"}) if !synthetic.IsAdministrator(admin) { t.Fatal("admin role should be authorized") } operator, _ := gin.CreateTestContext(nil) operator.Set(jwt.JwtPayloadKey, jwt.MapClaims{jwt.RoleKey: "operator"}) if synthetic.IsAdministrator(operator) { t.Fatal("non-admin role must be rejected") } }