feat(stock): persist per-user dividend history

This commit is contained in:
tiennm99 committed 2026-07-22 16:17:29 +07:00
1 parent 8de459b131
commit df240a5db0
25 files changed
+2076 -582

No files matched your search

+29
View File
@@ -1,13 +1,17 @@
package main
import (
"context"
"errors"
"os"
"path/filepath"
"strings"
"testing"
"github.com/tiennm99/miti99bot/internal/modules"
"github.com/tiennm99/miti99bot/internal/modules/stock"
"github.com/tiennm99/miti99bot/internal/storage"
"github.com/tiennm99/miti99bot/internal/systemstate"
)
func TestResolveCommitSHA(t *testing.T) {
@@ -32,6 +36,31 @@ func TestResolveCommitSHA(t *testing.T) {
}
}
func TestInitStockStoreRunsStartupMigration(t *testing.T) {
ctx := context.Background()
provider := storage.NewMemoryProvider()
if err := initStockStore(ctx, provider); err != nil {
t.Fatalf("initStockStore: %v", err)
}
marker, exists, err := systemstate.New(provider.Collection(systemstate.CollectionName)).Get(ctx, "migration:stock-dividend-history-v1")
if err != nil || !exists || marker.Status != "completed" {
t.Fatalf("marker=%+v exists=%v err=%v", marker, exists, err)
}
if _, _, err := storage.Typed[stock.Portfolio](provider.Collection(stock.CollectionName)).Get(ctx, "user:1"); !errors.Is(err, storage.ErrNotFound) {
t.Fatalf("unexpected portfolio lookup error: %v", 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 {
return want
})
if !errors.Is(err, want) {
t.Fatalf("initStockStoreWith 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")