feat: add table for purchase

This commit is contained in:
2026-08-07 08:33:09 +03:30
parent 3883d1b471
commit ba660f156c
6 changed files with 301 additions and 15 deletions
+10
View File
@@ -192,6 +192,16 @@ func TestPurchaseCreditsAndIdempotent(t *testing.T) {
if c := coinsOf(t, svc, id); c != pkg.Coins {
t.Fatalf("want %d coins, got %d", pkg.Coins, c)
}
// نوع و قیمتِ خرید باید ثبت شده باشند (پنلِ تراکنش‌ها).
var kind string
var priceToman int
if err := svc.db.QueryRow(`SELECT kind, price_toman FROM purchases WHERE user_id=?`, id).
Scan(&kind, &priceToman); err != nil {
t.Fatalf("read purchase: %v", err)
}
if kind != "coin" || priceToman != pkg.PriceToman {
t.Fatalf("want kind=coin price=%d, got kind=%q price=%d", pkg.PriceToman, kind, priceToman)
}
// همان توکن دوباره ⇒ قبلاً پردازش شده، بدون شارژ مجدد
if err := svc.VerifyPurchase(ctx, id, req); err != ErrAlreadyOwned {
t.Fatalf("want ErrAlreadyOwned, got %v", err)