feat(integrations): polish embed/IM channel editors and agent rebind
Align embed channel setup with a step wizard, simplify deploy layout, and allow changing bound agents on update for embed and IM channels.
This commit is contained in:
@@ -177,6 +177,12 @@ func (s *embedChannelService) Update(
|
||||
ch.AllowedOrigins = req.AllowedOrigins
|
||||
}
|
||||
}
|
||||
if trimmed := strings.TrimSpace(req.AgentID); trimmed != "" && trimmed != ch.AgentID {
|
||||
if _, err := s.ensureAgentOwned(ctx, tenantID, trimmed); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
ch.AgentID = trimmed
|
||||
}
|
||||
if err := s.repo.Update(ctx, ch); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
@@ -0,0 +1,62 @@
|
||||
package service
|
||||
|
||||
import (
|
||||
"context"
|
||||
"testing"
|
||||
|
||||
"github.com/Tencent/WeKnora/internal/types"
|
||||
"github.com/Tencent/WeKnora/internal/types/interfaces"
|
||||
)
|
||||
|
||||
type stubEmbedChannelRepo struct {
|
||||
interfaces.EmbedChannelRepository
|
||||
ch *types.EmbedChannel
|
||||
}
|
||||
|
||||
func (r *stubEmbedChannelRepo) GetByID(_ context.Context, id string) (*types.EmbedChannel, error) {
|
||||
if r.ch == nil || r.ch.ID != id {
|
||||
return nil, nil
|
||||
}
|
||||
cp := *r.ch
|
||||
return &cp, nil
|
||||
}
|
||||
|
||||
func (r *stubEmbedChannelRepo) Update(_ context.Context, ch *types.EmbedChannel) error {
|
||||
cp := *ch
|
||||
r.ch = &cp
|
||||
return nil
|
||||
}
|
||||
|
||||
func TestEmbedChannelUpdateAgentID(t *testing.T) {
|
||||
repo := &stubEmbedChannelRepo{
|
||||
ch: &types.EmbedChannel{
|
||||
ID: "ch-1",
|
||||
TenantID: 42,
|
||||
AgentID: "agent-old",
|
||||
Name: "Support",
|
||||
},
|
||||
}
|
||||
svc := &embedChannelService{
|
||||
repo: repo,
|
||||
agentService: &stubAgentForEmbed{
|
||||
agent: &types.CustomAgent{ID: "agent-new", TenantID: 42},
|
||||
},
|
||||
}
|
||||
enabled := true
|
||||
updated, err := svc.Update(
|
||||
context.Background(),
|
||||
42,
|
||||
"ch-1",
|
||||
&types.EmbedChannel{AgentID: "agent-new"},
|
||||
&enabled, nil, nil, nil, nil, nil, nil, nil,
|
||||
)
|
||||
if err != nil {
|
||||
t.Fatalf("Update() error = %v", err)
|
||||
}
|
||||
if updated.AgentID != "agent-new" {
|
||||
t.Fatalf("updated.AgentID = %q, want agent-new", updated.AgentID)
|
||||
}
|
||||
if repo.ch.AgentID != "agent-new" {
|
||||
t.Fatalf("persisted AgentID = %q, want agent-new", repo.ch.AgentID)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user