feat: verify and activate support group binding

This commit is contained in:
姚章浩
2026-08-13 18:22:43 +08:00
parent 4dbc20ee74
commit 6f24743be2
10 changed files with 239 additions and 10 deletions
+30 -3
View File
@@ -29,6 +29,12 @@ func (r *memoryRepo) SaveBinding(_ context.Context, b ResourceBinding) error {
r.bindings[b.Kind] = b
return nil
}
func (r *memoryRepo) TestAndActivateSupportGroup(_ context.Context, b ResourceBinding) error {
b.Activate = true
b.ValidationCode = "support_test_ok"
r.bindings[b.Kind] = b
return nil
}
func (r *memoryRepo) DetectBootstrapCandidate(_ context.Context, c BootstrapCandidate) error {
r.candidate = c
return nil
@@ -72,12 +78,33 @@ func TestControllerBindsAdminSupportGroup(t *testing.T) {
r := newMemoryRepo()
r.admins["t/a"] = true
c := NewController(r)
_, err := c.Handle(context.Background(), SettingInput{TenantKey: "t", StaffID: "a", Text: "/setting support", ConversationType: "group", ConversationID: "g", ConversationTitle: "技术支持"})
out, err := c.Handle(context.Background(), SettingInput{TenantKey: "t", StaffID: "a", Text: "/setting support", ConversationType: "group", ConversationID: "g", ConversationTitle: "技术支持"})
if err != nil {
t.Fatal(err)
}
if r.bindings["support_group"].ConversationID != "g" {
t.Fatalf("binding=%+v", r.bindings)
binding := r.bindings["support_group"]
if binding.ConversationID != "g" || binding.Activate {
t.Fatalf("binding=%+v", binding)
}
if !strings.Contains(out, "support test") {
t.Fatalf("reply=%q must explain explicit test command", out)
}
}
func TestControllerExplicitlyTestsAndActivatesSupportGroup(t *testing.T) {
r := newMemoryRepo()
r.admins["t/a"] = true
c := NewController(r)
out, err := c.Handle(context.Background(), SettingInput{TenantKey: "t", StaffID: "a", Text: "/setting support test", ConversationType: "group", ConversationID: "g", ConversationTitle: "技术支持"})
if err != nil {
t.Fatal(err)
}
binding := r.bindings["support_group"]
if binding.ConversationID != "g" || !binding.Activate {
t.Fatalf("binding=%+v", binding)
}
if !strings.Contains(out, "测试成功") || !strings.Contains(out, "已激活") {
t.Fatalf("reply=%q", out)
}
}
func TestControllerHelpIsHandledLocally(t *testing.T) {