MCPcopy Create free account
hub / github.com/Mnexa-AI/e2a / TestUsageSummaryIncrementAndGet

Function TestUsageSummaryIncrementAndGet

internal/usage/usage_test.go:29–67  ·  view source on GitHub ↗

-- Store tests (DB required) --

(t *testing.T)

Source from the content-addressed store, hash-verified

27// -- Store tests (DB required) --
28
29func TestUsageSummaryIncrementAndGet(t *testing.T) {
30 pool := testutil.TestDB(t)
31 store := usage.NewStore(pool)
32 idStore := identity.NewStore(pool)
33
34 ctx := context.Background()
35 bucketDate := "2026-03-29"
36
37 // Create a real user to satisfy FK constraint
38 user, err := idStore.CreateOrGetUser(ctx, "billing-test@example.com", "Billing Test", "google-billing-test")
39 if err != nil {
40 t.Fatalf("CreateOrGetUser: %v", err)
41 }
42
43 // Increment inbound
44 if err := store.IncrementUsageSummary(ctx, user.ID, bucketDate, "inbound"); err != nil {
45 t.Fatalf("IncrementUsageSummary inbound: %v", err)
46 }
47 // Increment outbound twice
48 for i := 0; i < 2; i++ {
49 if err := store.IncrementUsageSummary(ctx, user.ID, bucketDate, "outbound"); err != nil {
50 t.Fatalf("IncrementUsageSummary outbound: %v", err)
51 }
52 }
53
54 sum, err := store.GetUsageSummary(ctx, user.ID, bucketDate)
55 if err != nil {
56 t.Fatalf("GetUsageSummary: %v", err)
57 }
58 if sum.InboundCount != 1 {
59 t.Errorf("InboundCount = %d, want 1", sum.InboundCount)
60 }
61 if sum.OutboundCount != 2 {
62 t.Errorf("OutboundCount = %d, want 2", sum.OutboundCount)
63 }
64 if sum.TotalCount != 3 {
65 t.Errorf("TotalCount = %d, want 3", sum.TotalCount)
66 }
67}
68
69func TestLiveUsageTracker_AlwaysAllows(t *testing.T) {
70 pool := testutil.TestDB(t)

Callers

nothing calls this directly

Calls 6

CreateOrGetUserMethod · 0.95
IncrementUsageSummaryMethod · 0.95
GetUsageSummaryMethod · 0.95
TestDBFunction · 0.92
NewStoreFunction · 0.92
NewStoreFunction · 0.92

Tested by

no test coverage detected