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