package dingtalk import ( "context" "testing" ) type fakeSettingsRouter struct { called bool handled bool reply string } func (f *fakeSettingsRouter) Handle(_ context.Context, in SettingsMessage) (bool, string, error) { f.called = true if in.StaffID != "staff-123" { panic("wrong identity") } return f.handled, f.reply, nil } func TestSettingsCommandBypassesQA(t *testing.T) { qa := &fakeQA{} reply := &fakeReply{} router := &fakeSettingsRouter{handled: true, reply: "settings menu"} h, err := NewHandlerWithOptions(TenantConfig{TenantKey: "tenant-a", Channel: "dingtalk"}, qa, reply, HandlerOptions{SettingsRouter: router}) if err != nil { t.Fatal(err) } cb := directTextCallback() cb.Text = "/setting" if err = h.Handle(context.Background(), cb); err != nil { t.Fatal(err) } if !router.called { t.Fatal("router not called") } if qa.called { t.Fatal("settings must bypass QA") } if !reply.called || reply.lastText != "settings menu" { t.Fatalf("reply=%+v", reply) } } func TestOrdinaryQuestionStillCallsQA(t *testing.T) { qa := &fakeQA{} reply := &fakeReply{} router := &fakeSettingsRouter{} h, _ := NewHandlerWithOptions(TenantConfig{TenantKey: "tenant-a", Channel: "dingtalk"}, qa, reply, HandlerOptions{SettingsRouter: router}) if err := h.Handle(context.Background(), directTextCallback()); err != nil { t.Fatal(err) } if !qa.called { t.Fatal("ordinary question must call QA") } }