test(telegram): dedupe reply-context handleMessage tests
This commit is contained in:
parent
5f07db934b
commit
97adf57cc0
1 changed files with 36 additions and 95 deletions
|
|
@ -674,7 +674,14 @@ func TestHandleMessage_EmptyContent_Ignored(t *testing.T) {
|
|||
}
|
||||
}
|
||||
|
||||
func TestHandleMessage_ReplyCarriesMetadataAndQuotedContext(t *testing.T) {
|
||||
func handleReplyMessageAndGetInbound(
|
||||
t *testing.T,
|
||||
userText string,
|
||||
messageID int,
|
||||
replyToMessage *telego.Message,
|
||||
) bus.InboundMessage {
|
||||
t.Helper()
|
||||
|
||||
messageBus := bus.NewMessageBus()
|
||||
ch := &TelegramChannel{
|
||||
BaseChannel: channels.NewBaseChannel("telegram", nil, messageBus, nil),
|
||||
|
|
@ -683,8 +690,8 @@ func TestHandleMessage_ReplyCarriesMetadataAndQuotedContext(t *testing.T) {
|
|||
}
|
||||
|
||||
msg := &telego.Message{
|
||||
Text: "what do you think?",
|
||||
MessageID: 21,
|
||||
Text: userText,
|
||||
MessageID: messageID,
|
||||
Chat: telego.Chat{
|
||||
ID: 12345,
|
||||
Type: "private",
|
||||
|
|
@ -693,13 +700,7 @@ func TestHandleMessage_ReplyCarriesMetadataAndQuotedContext(t *testing.T) {
|
|||
ID: 10,
|
||||
FirstName: "Bob",
|
||||
},
|
||||
ReplyToMessage: &telego.Message{
|
||||
MessageID: 99,
|
||||
Text: "this is the old message",
|
||||
From: &telego.User{
|
||||
Username: "alice",
|
||||
},
|
||||
},
|
||||
ReplyToMessage: replyToMessage,
|
||||
}
|
||||
|
||||
err := ch.handleMessage(context.Background(), msg)
|
||||
|
|
@ -707,6 +708,18 @@ func TestHandleMessage_ReplyCarriesMetadataAndQuotedContext(t *testing.T) {
|
|||
|
||||
inbound, ok := <-messageBus.InboundChan()
|
||||
require.True(t, ok)
|
||||
return inbound
|
||||
}
|
||||
|
||||
func TestHandleMessage_ReplyCarriesMetadataAndQuotedContext(t *testing.T) {
|
||||
inbound := handleReplyMessageAndGetInbound(t, "what do you think?", 21, &telego.Message{
|
||||
MessageID: 99,
|
||||
Text: "this is the old message",
|
||||
From: &telego.User{
|
||||
Username: "alice",
|
||||
},
|
||||
})
|
||||
|
||||
assert.Equal(t, "99", inbound.Metadata["reply_to_message_id"])
|
||||
assert.Equal(
|
||||
t,
|
||||
|
|
@ -716,108 +729,36 @@ func TestHandleMessage_ReplyCarriesMetadataAndQuotedContext(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestHandleMessage_ReplyWithoutTextOnlySetsReplyMetadata(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: "ping",
|
||||
MessageID: 22,
|
||||
Chat: telego.Chat{
|
||||
ID: 12345,
|
||||
Type: "private",
|
||||
},
|
||||
From: &telego.User{
|
||||
ID: 10,
|
||||
FirstName: "Bob",
|
||||
},
|
||||
ReplyToMessage: &telego.Message{
|
||||
inbound := handleReplyMessageAndGetInbound(t, "ping", 22, &telego.Message{
|
||||
MessageID: 100,
|
||||
},
|
||||
}
|
||||
})
|
||||
|
||||
err := ch.handleMessage(context.Background(), msg)
|
||||
require.NoError(t, err)
|
||||
|
||||
inbound, ok := <-messageBus.InboundChan()
|
||||
require.True(t, ok)
|
||||
assert.Equal(t, "100", inbound.Metadata["reply_to_message_id"])
|
||||
assert.Equal(t, "ping", inbound.Content)
|
||||
}
|
||||
|
||||
func TestHandleMessage_ReplyCommandKeepsCommandPrefix(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: 23,
|
||||
Chat: telego.Chat{
|
||||
ID: 12345,
|
||||
Type: "private",
|
||||
},
|
||||
From: &telego.User{
|
||||
ID: 10,
|
||||
FirstName: "Bob",
|
||||
},
|
||||
ReplyToMessage: &telego.Message{
|
||||
inbound := handleReplyMessageAndGetInbound(t, "/new", 23, &telego.Message{
|
||||
MessageID: 101,
|
||||
Text: "old context text",
|
||||
From: &telego.User{
|
||||
Username: "alice",
|
||||
},
|
||||
},
|
||||
}
|
||||
})
|
||||
|
||||
err := ch.handleMessage(context.Background(), msg)
|
||||
require.NoError(t, err)
|
||||
|
||||
inbound, ok := <-messageBus.InboundChan()
|
||||
require.True(t, ok)
|
||||
assert.Equal(t, "101", inbound.Metadata["reply_to_message_id"])
|
||||
assert.Equal(t, "/new", inbound.Content)
|
||||
}
|
||||
|
||||
func TestHandleMessage_ReplyBangCommandKeepsCommandPrefix(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: 24,
|
||||
Chat: telego.Chat{
|
||||
ID: 12345,
|
||||
Type: "private",
|
||||
},
|
||||
From: &telego.User{
|
||||
ID: 10,
|
||||
FirstName: "Bob",
|
||||
},
|
||||
ReplyToMessage: &telego.Message{
|
||||
inbound := handleReplyMessageAndGetInbound(t, "!new", 24, &telego.Message{
|
||||
MessageID: 102,
|
||||
Text: "old context text",
|
||||
From: &telego.User{
|
||||
Username: "alice",
|
||||
},
|
||||
},
|
||||
}
|
||||
})
|
||||
|
||||
err := ch.handleMessage(context.Background(), msg)
|
||||
require.NoError(t, err)
|
||||
|
||||
inbound, ok := <-messageBus.InboundChan()
|
||||
require.True(t, ok)
|
||||
assert.Equal(t, "102", inbound.Metadata["reply_to_message_id"])
|
||||
assert.Equal(t, "!new", inbound.Content)
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue