53 lines
1.1 KiB
Go
53 lines
1.1 KiB
Go
|
|
package telegram
|
||
|
|
|
||
|
|
import (
|
||
|
|
"context"
|
||
|
|
"testing"
|
||
|
|
"time"
|
||
|
|
|
||
|
|
"github.com/mymmrac/telego"
|
||
|
|
|
||
|
|
"github.com/sipeed/picoclaw/pkg/bus"
|
||
|
|
"github.com/sipeed/picoclaw/pkg/channels"
|
||
|
|
)
|
||
|
|
|
||
|
|
func TestHandleMessage_DoesNotConsumeGenericCommandsLocally(t *testing.T) {
|
||
|
|
messageBus := bus.NewMessageBus()
|
||
|
|
ch := &TelegramChannel{
|
||
|
|
BaseChannel: channels.NewBaseChannel("telegram", nil, messageBus, nil),
|
||
|
|
chatIDs: make(map[string]int64),
|
||
|
|
ctx: context.Background(),
|
||
|
|
}
|
||
|
|
|
||
|
|
msg := &telego.Message{
|
||
|
|
Text: "/new",
|
||
|
|
MessageID: 9,
|
||
|
|
Chat: telego.Chat{
|
||
|
|
ID: 123,
|
||
|
|
Type: "private",
|
||
|
|
},
|
||
|
|
From: &telego.User{
|
||
|
|
ID: 42,
|
||
|
|
FirstName: "Alice",
|
||
|
|
},
|
||
|
|
}
|
||
|
|
|
||
|
|
if err := ch.handleMessage(context.Background(), msg); err != nil {
|
||
|
|
t.Fatalf("handleMessage error: %v", err)
|
||
|
|
}
|
||
|
|
|
||
|
|
ctx, cancel := context.WithTimeout(context.Background(), time.Second)
|
||
|
|
defer cancel()
|
||
|
|
|
||
|
|
inbound, ok := messageBus.ConsumeInbound(ctx)
|
||
|
|
if !ok {
|
||
|
|
t.Fatal("expected inbound message to be forwarded")
|
||
|
|
}
|
||
|
|
if inbound.Channel != "telegram" {
|
||
|
|
t.Fatalf("channel=%q", inbound.Channel)
|
||
|
|
}
|
||
|
|
if inbound.Content != "/new" {
|
||
|
|
t.Fatalf("content=%q", inbound.Content)
|
||
|
|
}
|
||
|
|
}
|