feat: keep table binding messages out of QA
This commit is contained in:
@@ -2,6 +2,7 @@ package settings
|
||||
|
||||
import (
|
||||
"context"
|
||||
"strings"
|
||||
"testing"
|
||||
"time"
|
||||
)
|
||||
@@ -11,10 +12,11 @@ type memoryRepo struct {
|
||||
prefs map[string]string
|
||||
bindings map[string]ResourceBinding
|
||||
candidate BootstrapCandidate
|
||||
sessions map[string]SettingSession
|
||||
}
|
||||
|
||||
func newMemoryRepo() *memoryRepo {
|
||||
return &memoryRepo{admins: map[string]bool{}, prefs: map[string]string{}, bindings: map[string]ResourceBinding{}}
|
||||
return &memoryRepo{admins: map[string]bool{}, prefs: map[string]string{}, bindings: map[string]ResourceBinding{}, sessions: map[string]SettingSession{}}
|
||||
}
|
||||
func (r *memoryRepo) IsAdministrator(_ context.Context, tenant, staff string) (bool, error) {
|
||||
return r.admins[tenant+"/"+staff], nil
|
||||
@@ -31,6 +33,19 @@ func (r *memoryRepo) DetectBootstrapCandidate(_ context.Context, c BootstrapCand
|
||||
r.candidate = c
|
||||
return nil
|
||||
}
|
||||
func (r *memoryRepo) GetSettingSession(_ context.Context, tenant, staff string) (SettingSession, bool, error) {
|
||||
s, ok := r.sessions[tenant+"/"+staff]
|
||||
return s, ok, nil
|
||||
}
|
||||
func (r *memoryRepo) SaveSettingSession(_ context.Context, s SettingSession) error {
|
||||
r.sessions[s.TenantKey+"/"+s.StaffID] = s
|
||||
return nil
|
||||
}
|
||||
func (r *memoryRepo) DeleteSettingSession(_ context.Context, tenant, staff string) error {
|
||||
delete(r.sessions, tenant+"/"+staff)
|
||||
return nil
|
||||
}
|
||||
|
||||
func TestControllerLanguageForOrdinaryUser(t *testing.T) {
|
||||
r := newMemoryRepo()
|
||||
c := NewController(r)
|
||||
@@ -77,6 +92,28 @@ func TestControllerParsesAdminQuestionTable(t *testing.T) {
|
||||
t.Fatalf("binding=%+v", r.bindings)
|
||||
}
|
||||
}
|
||||
func TestControllerAcceptsTableLinkInNextMessage(t *testing.T) {
|
||||
r := newMemoryRepo()
|
||||
r.admins["t/a"] = true
|
||||
c := NewController(r)
|
||||
out, err := c.Handle(context.Background(), SettingInput{TenantKey: "t", Channel: "dingtalk", StaffID: "a", Text: "/setting question", ConversationType: "direct"})
|
||||
if err != nil || !strings.Contains(out, "链接") {
|
||||
t.Fatalf("out=%q err=%v", out, err)
|
||||
}
|
||||
if !c.ShouldHandle(context.Background(), "t", "a", "https://alidocs.dingtalk.com/i/nodes/base?sheetId=sheet&viewId=view") {
|
||||
t.Fatal("active setting session must intercept next message")
|
||||
}
|
||||
_, err = c.Handle(context.Background(), SettingInput{TenantKey: "t", Channel: "dingtalk", StaffID: "a", UnionID: "union", Text: "https://alidocs.dingtalk.com/i/nodes/base?sheetId=sheet&viewId=view", ConversationType: "direct"})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if r.bindings["question_table"].BaseID != "base" {
|
||||
t.Fatalf("binding=%+v", r.bindings)
|
||||
}
|
||||
if _, ok := r.sessions["t/a"]; ok {
|
||||
t.Fatal("setting session must be cleared")
|
||||
}
|
||||
}
|
||||
func TestControllerDetectsBootstrapCandidate(t *testing.T) {
|
||||
r := newMemoryRepo()
|
||||
c := NewController(r)
|
||||
|
||||
Reference in New Issue
Block a user