feat: add billing and usage domain cores
This commit is contained in:
1 parent
48dd5d07c8
commit
5e60bb40e7
14 files changed
+931
No files matched your search
@@ -0,0 +1,33 @@
|
||||
package postgres
|
||||
|
||||
import (
|
||||
"context"
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"git.nianxx.cn/wangxuming/NianAIGC/backend/internal/usage"
|
||||
)
|
||||
|
||||
func TestInsertUsageEventUsesJobConflictForDedupe(t *testing.T) {
|
||||
q := &fakeQuerier{}
|
||||
db := NewDatabase(Config{Backend: BackendPostgres}, q)
|
||||
_, inserted, err := db.InsertUsageEvent(context.Background(), usage.Event{ID: "e", JobID: "j", OwnerID: "a", Source: "platform", Quantity: 1})
|
||||
if err != nil || inserted {
|
||||
t.Fatalf("inserted=%v err=%v", inserted, err)
|
||||
}
|
||||
if q.sql != InsertUsageEventSQL || !strings.Contains(q.sql, "ON CONFLICT (job_id) DO NOTHING") {
|
||||
t.Fatalf("sql=%q", q.sql)
|
||||
}
|
||||
}
|
||||
|
||||
func TestListUsageEventsUsesExplicitColumnsAndFilters(t *testing.T) {
|
||||
q := &fakeQuerier{}
|
||||
db := NewDatabase(Config{Backend: BackendPostgres}, q)
|
||||
_, err := db.ListUsageEvents(context.Background(), usage.Filters{OwnerID: "a", OrganizationID: "o", From: "2026-01-01", To: "2026-02-01"})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if q.sql != ListUsageEventsSQL || len(q.args) != 4 {
|
||||
t.Fatalf("sql=%q args=%#v", q.sql, q.args)
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user