feat(im): add proactive support reply delivery
This commit is contained in:
@@ -0,0 +1,58 @@
|
||||
package im
|
||||
|
||||
import (
|
||||
"context"
|
||||
"testing"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
)
|
||||
|
||||
type recordingReplyAdapter struct {
|
||||
incoming *IncomingMessage
|
||||
reply *ReplyMessage
|
||||
}
|
||||
|
||||
func (a *recordingReplyAdapter) Platform() Platform { return PlatformDingtalk }
|
||||
func (a *recordingReplyAdapter) VerifyCallback(*gin.Context) error { return nil }
|
||||
func (a *recordingReplyAdapter) ParseCallback(*gin.Context) (*IncomingMessage, error) {
|
||||
return nil, nil
|
||||
}
|
||||
func (a *recordingReplyAdapter) SendReply(_ context.Context, incoming *IncomingMessage, reply *ReplyMessage) error {
|
||||
a.incoming = incoming
|
||||
a.reply = reply
|
||||
return nil
|
||||
}
|
||||
func (a *recordingReplyAdapter) HandleURLVerification(*gin.Context) bool { return false }
|
||||
|
||||
func TestSendReplyToSource(t *testing.T) {
|
||||
adapter := &recordingReplyAdapter{}
|
||||
service := &Service{channels: map[string]*channelState{
|
||||
"channel-1": {
|
||||
Adapter: adapter,
|
||||
Channel: &IMChannel{ID: "channel-1", Platform: "dingtalk", Enabled: true},
|
||||
},
|
||||
}}
|
||||
|
||||
err := service.SendReplyToSource(context.Background(), ReplyTarget{
|
||||
ChannelID: "channel-1",
|
||||
UserID: "staff-1",
|
||||
ChatID: "conversation-1",
|
||||
ChatType: ChatTypeGroup,
|
||||
}, "技术支持回复内容")
|
||||
if err != nil {
|
||||
t.Fatalf("SendReplyToSource: %v", err)
|
||||
}
|
||||
if adapter.incoming == nil || adapter.incoming.UserID != "staff-1" || adapter.incoming.ChatID != "conversation-1" || adapter.incoming.ChatType != ChatTypeGroup {
|
||||
t.Fatalf("incoming = %#v", adapter.incoming)
|
||||
}
|
||||
if adapter.reply == nil || adapter.reply.Content != "技术支持回复内容" || !adapter.reply.IsFinal {
|
||||
t.Fatalf("reply = %#v", adapter.reply)
|
||||
}
|
||||
}
|
||||
|
||||
func TestSendReplyToSourceRejectsUnavailableChannel(t *testing.T) {
|
||||
service := &Service{channels: map[string]*channelState{}}
|
||||
if err := service.SendReplyToSource(context.Background(), ReplyTarget{ChannelID: "missing"}, "reply"); err == nil {
|
||||
t.Fatal("expected missing channel error")
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user