Files
miti99bot/internal/modules/gold/handlers_validation_test.go
T
tiennm99 254bf47dc1 feat(gold): add gold paper trading module
Opt-in module for gold paper trading with VND currency.
Commands: /gold_topup, /gold_buy, /gold_sell, /gold_stats.
Pricing: spot XAU USD converted to VND per luong via GoldPrice.org + ExchangeRate-API.
Features: FX caching, dust normalization (1e-9), HTTPS-only URL validation,
per-user key locking, namespace isolation from trading module.
2026-06-11 17:13:02 +07:00

59 lines
1.6 KiB
Go

package gold
import (
"context"
"strings"
"testing"
"github.com/tiennm99/miti99bot/internal/testutil"
)
func TestHandlersRejectExtraArgs(t *testing.T) {
ctx := context.Background()
s := newTestState(2_000_000, nil)
rb := testutil.NewRecordingBot(t)
cases := []struct {
name string
text string
want string
}{
{name: "topup currency", text: "/gold_topup 100 USD", want: "Usage: /gold_topup <amount>"},
{name: "buy unit", text: "/gold_buy 1 oz", want: "Usage: /gold_buy <luong>"},
{name: "sell symbol", text: "/gold_sell 1 SJC", want: "Usage: /gold_sell <luong>"},
}
for _, tc := range cases {
t.Run(tc.name, func(t *testing.T) {
rb.Reset()
update := testutil.NewPrivateMessage(7, tc.text)
var err error
switch {
case strings.HasPrefix(tc.text, "/gold_topup"):
err = s.handleTopup(ctx, rb.Bot, update)
case strings.HasPrefix(tc.text, "/gold_buy"):
err = s.handleBuy(ctx, rb.Bot, update)
case strings.HasPrefix(tc.text, "/gold_sell"):
err = s.handleSell(ctx, rb.Bot, update)
}
if err != nil {
t.Fatalf("handler: %v", err)
}
rb.AssertSentText(t, tc.want)
})
}
}
func TestHandlersRejectTooLargeValues(t *testing.T) {
ctx := context.Background()
s := newTestState(1e308, nil)
rb := testutil.NewRecordingBot(t)
if err := s.handleTopup(ctx, rb.Bot, testutil.NewPrivateMessage(7, "/gold_topup 1e308")); err != nil {
t.Fatalf("topup: %v", err)
}
rb.AssertSentText(t, "supported range")
rb.Reset()
if err := s.handleBuy(ctx, rb.Bot, testutil.NewPrivateMessage(7, "/gold_buy 2")); err != nil {
t.Fatalf("buy: %v", err)
}
rb.AssertSentText(t, "Trade value is too large")
}