(new): rich message support
(fix): runtime reliability (tests): regression coverage (doc): v1.1 release notes
This commit is contained in:
@@ -83,3 +83,50 @@ func TestGatherCommandsForPluginReturnsSortedCommands(t *testing.T) {
|
||||
t.Fatalf("unexpected command order: got %v want %v", got, want)
|
||||
}
|
||||
}
|
||||
|
||||
func TestAutoGenerateCommandsForNilScopeUsesSingleAtomicReplacement(t *testing.T) {
|
||||
var methods []string
|
||||
client := &http.Client{
|
||||
Transport: roundTripFunc(func(req *http.Request) (*http.Response, error) {
|
||||
methods = append(methods, req.URL.Path)
|
||||
return &http.Response{
|
||||
StatusCode: http.StatusOK,
|
||||
Header: http.Header{"Content-Type": []string{"application/json"}},
|
||||
Body: io.NopCloser(strings.NewReader(`{"ok":true,"result":true}`)),
|
||||
}, nil
|
||||
}),
|
||||
}
|
||||
api := tgapi.NewAPI(
|
||||
tgapi.NewAPIOpts("token").
|
||||
SetAPIURL("https://example.test").
|
||||
SetHTTPClient(client),
|
||||
)
|
||||
defer func() {
|
||||
if err := api.Close(); err != nil {
|
||||
t.Fatalf("Close returned error: %v", err)
|
||||
}
|
||||
}()
|
||||
|
||||
plugin := NewPlugin[NoData]("commands")
|
||||
plugin.Command("start", func(ctx *MessageContext, db NoData) error { return nil })
|
||||
bot := &Bot[NoData]{
|
||||
api: api,
|
||||
logger: sneklog.NewLogger(),
|
||||
plugins: []Plugin[NoData]{*plugin},
|
||||
}
|
||||
defer func() {
|
||||
if err := bot.logger.Close(); err != nil {
|
||||
t.Fatalf("Close logger returned error: %v", err)
|
||||
}
|
||||
}()
|
||||
|
||||
if err := bot.AutoGenerateCommandsForScope(nil); err != nil {
|
||||
t.Fatalf("AutoGenerateCommandsForScope returned error: %v", err)
|
||||
}
|
||||
if len(methods) != 1 {
|
||||
t.Fatalf("expected one request, got %d", len(methods))
|
||||
}
|
||||
if !strings.HasSuffix(methods[0], "/setMyCommands") {
|
||||
t.Fatalf("expected setMyCommands request, got %v", methods[0])
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user