fix(stock): retire dividend command and migrate stats

This commit is contained in:
tiennm99 committed 2026-07-22 18:55:57 +07:00
1 parent e46d10cc36
commit f9d1e52f6d
10 files changed
+331 -194

No files matched your search

+4 -2
View File
@@ -75,7 +75,6 @@ func TestCommandDiscovery_AllPublicCommandsHaveSafeMetadata(t *testing.T) {
"stock_sell": "<quantity> <ticker>",
"stock_cash_dividend": "<vnd_per_share> <ticker>",
"stock_share_dividend": "<ratio(owned:new)> <ticker>",
"stock_dividend": "<vnd_per_share> <ratio(owned:new)> <ticker>",
"trongtruonghop": "[target...]",
"tth": "[target...]",
"wheelofnames": "<option,...>",
@@ -125,11 +124,14 @@ func TestBotCommandMenu_StockDividendContracts(t *testing.T) {
t.Fatalf("description for %s exceeds Telegram limit", command.Command)
}
}
for _, name := range []string{"stock_cash_dividend", "stock_share_dividend", "stock_dividend"} {
for _, name := range []string{"stock_cash_dividend", "stock_share_dividend"} {
if commands[name] == "" {
t.Fatalf("stock menu missing %s: %v", name, commands)
}
}
if _, exists := commands["stock_dividend"]; exists {
t.Fatalf("retired stock_dividend remains in public menu: %v", commands)
}
if _, exists := commands["stock_bonus"]; exists {
t.Fatalf("stock_bonus remains in public menu: %v", commands)
}
+15 -1
View File
@@ -118,7 +118,7 @@ func main() {
}
defer closeProvider()
if err := stats.InitStore(rootCtx, provider.Collection("stats")); err != nil {
if err := initStatsStore(rootCtx, provider); err != nil {
log.Fatal("stats storage init failed", "err", err)
}
if err := lol.InitStore(rootCtx, provider.Collection(lol.CollectionName)); err != nil {
@@ -224,6 +224,20 @@ func initStockStore(ctx context.Context, provider storage.Provider) error {
return initStockStoreWith(ctx, provider, stock.InitStore)
}
func initStatsStore(ctx context.Context, provider storage.Provider) error {
return initStatsStoreWith(ctx, provider, stats.InitStore)
}
type statsStoreInitializer func(context.Context, storage.Collection, storage.Collection) error
func initStatsStoreWith(ctx context.Context, provider storage.Provider, init statsStoreInitializer) error {
return init(
ctx,
provider.Collection("stats"),
provider.Collection(systemstate.CollectionName),
)
}
type stockStoreInitializer func(context.Context, storage.Collection, storage.Collection) error
func initStockStoreWith(ctx context.Context, provider storage.Provider, init stockStoreInitializer) error {
+22
View File
@@ -51,6 +51,18 @@ func TestInitStockStoreRunsStartupMigration(t *testing.T) {
}
}
func TestInitStatsStoreRunsStartupMigration(t *testing.T) {
ctx := context.Background()
provider := storage.NewMemoryProvider()
if err := initStatsStore(ctx, provider); err != nil {
t.Fatalf("initStatsStore: %v", err)
}
marker, exists, err := systemstate.New(provider.Collection(systemstate.CollectionName)).Get(ctx, "migration:stats-delete-stock-dividend-v1")
if err != nil || !exists || marker.Status != "completed" {
t.Fatalf("marker=%+v exists=%v err=%v", marker, exists, err)
}
}
func TestInitStockStorePropagatesMigrationError(t *testing.T) {
want := errors.New("migration failed")
err := initStockStoreWith(context.Background(), storage.NewMemoryProvider(), func(context.Context, storage.Collection, storage.Collection) error {
@@ -61,6 +73,16 @@ func TestInitStockStorePropagatesMigrationError(t *testing.T) {
}
}
func TestInitStatsStorePropagatesMigrationError(t *testing.T) {
want := errors.New("migration failed")
err := initStatsStoreWith(context.Background(), storage.NewMemoryProvider(), func(context.Context, storage.Collection, storage.Collection) error {
return want
})
if !errors.Is(err, want) {
t.Fatalf("initStatsStoreWith error=%v, want %v", err, want)
}
}
func TestShortCommitSHA(t *testing.T) {
if got := shortCommitSHA(" 0123456789abcdef "); got != "0123456" {
t.Errorf("full revision: got %q, want %q", got, "0123456")