mirror of
https://github.com/Rain-kl/OpenFlare.git
synced 2026-10-04 23:16:37 +08:00
299ac30ee4
- Purify core micro-kernel by removing context hardcoded helpers and reverse dependencies - Eliminate init() side effects in infra plugins with reversible lifecycle disposal - Completely isolate plugins by removing cross-plugin imports and using core/contracts - Introduce TaskService and RiskControlService contracts for unified cross-plugin APIs - Regenerate Swagger documentation and update developer guide matrix - Achieve 0 violations in check_cordis_architecture.sh and 100% test pass
58 lines
1.3 KiB
Go
58 lines
1.3 KiB
Go
// Copyright 2026 Arctel.net
|
|
// SPDX-License-Identifier: Apache-2.0
|
|
|
|
package telegram
|
|
|
|
import (
|
|
"context"
|
|
"testing"
|
|
|
|
tele "gopkg.in/telebot.v4"
|
|
|
|
"Wavelet/plugins/domain/message_gateway"
|
|
)
|
|
|
|
func TestHandleUpdate_DropsGroups(t *testing.T) {
|
|
var got int
|
|
a := &Adapter{onInbound: func(ctx context.Context, msg message_gateway.InboundMessage) error {
|
|
got++
|
|
return nil
|
|
}}
|
|
a.handleTeleMessage(context.Background(), &tele.Message{
|
|
ID: 1,
|
|
Text: "hi",
|
|
Chat: &tele.Chat{ID: -100, Type: tele.ChatGroup},
|
|
Sender: &tele.User{ID: 1},
|
|
})
|
|
if got != 0 {
|
|
t.Fatalf("group must be ignored")
|
|
}
|
|
}
|
|
|
|
func TestHandleUpdate_PrivateText(t *testing.T) {
|
|
var got message_gateway.InboundMessage
|
|
a := &Adapter{
|
|
cfg: message_gateway.ChannelConfig{ID: 7, Type: "telegram"},
|
|
onInbound: func(ctx context.Context, msg message_gateway.InboundMessage) error {
|
|
got = msg
|
|
return nil
|
|
},
|
|
}
|
|
a.handleTeleMessage(context.Background(), &tele.Message{
|
|
ID: 9,
|
|
Text: "hi",
|
|
Chat: &tele.Chat{ID: 42, Type: tele.ChatPrivate},
|
|
Sender: &tele.User{ID: 42},
|
|
})
|
|
if got.Text != "hi" || got.PlatformUserID != "42" || got.ChannelID != 7 {
|
|
t.Fatalf("%+v", got)
|
|
}
|
|
}
|
|
|
|
func TestNew_RequiresToken(t *testing.T) {
|
|
_, err := New(message_gateway.ChannelConfig{}, nil)
|
|
if err == nil {
|
|
t.Fatal("expected error")
|
|
}
|
|
}
|