@@ -2,23 +2,13 @@ import { describe, expect, it, vi } from "vitest";
22import { createProviderUsageFetch , makeResponse } from "../test-utils/provider-usage-fetch.js" ;
33import { loadProviderUsageSummary } from "./provider-usage.load.js" ;
44import { ignoredErrors } from "./provider-usage.shared.js" ;
5+ import {
6+ loadUsageWithAuth ,
7+ type ProviderUsageAuth ,
8+ usageNow ,
9+ } from "./provider-usage.test-support.js" ;
510
6- const usageNow = Date . UTC ( 2026 , 0 , 7 , 0 , 0 , 0 ) ;
7-
8- type ProviderAuth = NonNullable <
9- NonNullable < Parameters < typeof loadProviderUsageSummary > [ 0 ] > [ "auth" ]
10- > [ number ] ;
11-
12- async function loadUsageWithAuth (
13- auth : ProviderAuth [ ] ,
14- mockFetch : ReturnType < typeof createProviderUsageFetch > ,
15- ) {
16- return await loadProviderUsageSummary ( {
17- now : usageNow ,
18- auth,
19- fetch : mockFetch as unknown as typeof fetch ,
20- } ) ;
21- }
11+ type ProviderAuth = ProviderUsageAuth < typeof loadProviderUsageSummary > ;
2212
2313describe ( "provider-usage.load" , ( ) => {
2414 it ( "loads snapshots for copilot gemini codex and xiaomi" , async ( ) => {
@@ -53,6 +43,7 @@ describe("provider-usage.load", () => {
5343 } ) ;
5444
5545 const summary = await loadUsageWithAuth (
46+ loadProviderUsageSummary ,
5647 [
5748 { provider : "github-copilot" , token : "copilot-token" } ,
5849 { provider : "google-gemini-cli" , token : "gemini-token" } ,
@@ -85,13 +76,14 @@ describe("provider-usage.load", () => {
8576
8677 it ( "returns empty provider list when auth resolves to none" , async ( ) => {
8778 const mockFetch = createProviderUsageFetch ( async ( ) => makeResponse ( 404 , "not found" ) ) ;
88- const summary = await loadUsageWithAuth ( [ ] , mockFetch ) ;
79+ const summary = await loadUsageWithAuth ( loadProviderUsageSummary , [ ] , mockFetch ) ;
8980 expect ( summary ) . toEqual ( { updatedAt : usageNow , providers : [ ] } ) ;
9081 } ) ;
9182
9283 it ( "returns unsupported provider snapshots for unknown provider ids" , async ( ) => {
9384 const mockFetch = createProviderUsageFetch ( async ( ) => makeResponse ( 404 , "not found" ) ) ;
9485 const summary = await loadUsageWithAuth (
86+ loadProviderUsageSummary ,
9587 [ { provider : "unsupported-provider" , token : "token-u" } ] as unknown as ProviderAuth [ ] ,
9688 mockFetch ,
9789 ) ;
@@ -109,6 +101,7 @@ describe("provider-usage.load", () => {
109101 ignoredErrors . add ( "HTTP 500" ) ;
110102 try {
111103 const summary = await loadUsageWithAuth (
104+ loadProviderUsageSummary ,
112105 [ { provider : "anthropic" , token : "token-a" } ] ,
113106 mockFetch ,
114107 ) ;
0 commit comments