feat(server): Redeem 换芯 GuardedRedeem——grant 回调同事务复刻订阅叠加+双审计(#codes-lib)

This commit is contained in:
wangjia
2026-07-10 14:34:30 +08:00
parent e128c96d22
commit 0822d22e2c
5 changed files with 321 additions and 324 deletions
@@ -3,7 +3,9 @@ package codes_test
import (
"context"
"database/sql"
"fmt"
"testing"
"time"
"github.com/wangjia/pangolin/server/internal/config"
"github.com/wangjia/pangolin/server/internal/store"
@@ -28,3 +30,16 @@ func openMigratedSQLite(t *testing.T) *sql.DB {
}
return db
}
// seedUser inserts a minimal `users` row so redeem tests can satisfy the
// subscriptions/audit_log foreign keys.
func seedUser(t *testing.T, db *sql.DB, id int64) {
t.Helper()
if _, err := db.Exec(
`INSERT INTO users (id, uuid, email, pw_hash, dp_uuid, status, created_at)
VALUES (?, ?, ?, 'x', ?, 'active', ?)`,
id, fmt.Sprintf("u-%d", id), fmt.Sprintf("u%d@example.com", id), fmt.Sprintf("dp-%d", id),
time.Now().UTC()); err != nil {
t.Fatalf("seed user: %v", err)
}
}