package pub import ( "context" "testing" "perms-system-server/internal/config" "perms-system-server/internal/svc" "perms-system-server/internal/testutil" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" ) // TC-1211: cap.js 已启用 func TestCapEndpoint_Enabled(t *testing.T) { cfg := testutil.GetTestConfig() cfg.Capjs = config.CapjsConf{ Enable: 1, EndpointURL: "https://cap.example.com", Key: "site-key-123", Secret: "secret", } svcCtx := svc.NewServiceContext(cfg) logic := NewCapEndpointLogic(context.Background(), svcCtx) resp, err := logic.CapEndpoint() require.NoError(t, err) require.NotNil(t, resp) assert.Equal(t, "https://cap.example.com/site-key-123/", resp.Data) } // TC-1212: cap.js 未启用(Enable=0) func TestCapEndpoint_Disabled(t *testing.T) { cfg := testutil.GetTestConfig() cfg.Capjs = config.CapjsConf{Enable: 0} svcCtx := svc.NewServiceContext(cfg) logic := NewCapEndpointLogic(context.Background(), svcCtx) resp, err := logic.CapEndpoint() require.NoError(t, err) require.NotNil(t, resp) assert.Equal(t, "", resp.Data) } // TC-1255: cap.js 启用但 EndpointURL 为空 func TestCapEndpoint_EnabledButNoURL(t *testing.T) { cfg := testutil.GetTestConfig() cfg.Capjs = config.CapjsConf{Enable: 1, EndpointURL: "", Key: "k"} svcCtx := svc.NewServiceContext(cfg) logic := NewCapEndpointLogic(context.Background(), svcCtx) resp, err := logic.CapEndpoint() require.NoError(t, err) assert.Equal(t, "", resp.Data) } // TC-1256: cap.js 启用但 Key 为空 func TestCapEndpoint_EnabledButNoKey(t *testing.T) { cfg := testutil.GetTestConfig() cfg.Capjs = config.CapjsConf{Enable: 1, EndpointURL: "https://cap.example.com", Key: ""} svcCtx := svc.NewServiceContext(cfg) logic := NewCapEndpointLogic(context.Background(), svcCtx) resp, err := logic.CapEndpoint() require.NoError(t, err) assert.Equal(t, "", resp.Data) }