@@ -32,18 +32,11 @@ async function runTokenPlan(response: Record<string, unknown>, output?: string):
3232 } as never ) ;
3333}
3434
35- function makeUsageResponse (
36- per5HourPercentage ?: number ,
37- per1WeekPercentage = per5HourPercentage ,
38- ) : Record < string , unknown > {
35+ function makeUsageResponse ( per1MonthPercentage ?: number ) : Record < string , unknown > {
3936 const usage : Record < string , number > = { } ;
40- if ( per5HourPercentage !== undefined ) {
41- usage . per5HourPercentage = per5HourPercentage ;
42- if ( per5HourPercentage !== 0 ) usage . per5HourResetTime = 1_786_000_000_000 ;
43- }
44- if ( per1WeekPercentage !== undefined ) {
45- usage . per1WeekPercentage = per1WeekPercentage ;
46- if ( per1WeekPercentage !== 0 ) usage . per1WeekResetTime = 1_786_100_000_000 ;
37+ if ( per1MonthPercentage !== undefined ) {
38+ usage . per1MonthPercentage = per1MonthPercentage ;
39+ if ( per1MonthPercentage !== 0 ) usage . per1MonthResetTime = 1_786_000_000_000 ;
4740 }
4841
4942 return wrapResponse ( usage ) ;
@@ -86,91 +79,62 @@ describe("usage token-plan view", () => {
8679 expect ( renderedOutput ) . not . toContain ( "\u2588" . repeat ( 11 ) ) ;
8780 } ) ;
8881
89- test ( "accepts missing reset times when the quota usage is zero" , async ( ) => {
82+ test ( "accepts a missing reset time when the quota usage is zero" , async ( ) => {
9083 const output = captureStdout ( ) ;
9184
9285 await runTokenPlan ( makeUsageResponse ( 0 ) ) ;
9386
9487 expect ( output . join ( "" ) ) . toContain ( "Resets: not applicable (no usage yet)" ) ;
9588 } ) ;
9689
97- test ( "allows one unused quota window without masking another reset time " , async ( ) => {
90+ test ( "renders the monthly reset time when usage is present " , async ( ) => {
9891 const output = captureStdout ( ) ;
9992
100- await runTokenPlan ( makeUsageResponse ( 0 , 0 .5) ) ;
93+ await runTokenPlan ( makeUsageResponse ( 0.5 ) ) ;
10194
102- const renderedOutput = output . join ( "" ) ;
103- expect ( renderedOutput ) . toContain ( "Resets: not applicable (no usage yet)" ) ;
104- expect ( renderedOutput ) . toMatch ( / R e s e t s : \d { 4 } - \d { 2 } - \d { 2 } \d { 2 } : \d { 2 } : \d { 2 } / ) ;
95+ expect ( output . join ( "" ) ) . toMatch ( / R e s e t s : \d { 4 } - \d { 2 } - \d { 2 } \d { 2 } : \d { 2 } : \d { 2 } / ) ;
10596 } ) ;
10697
107- test ( "renders missing quota windows as possibly unlimited" , async ( ) => {
98+ test ( "renders a missing monthly quota as possibly unlimited" , async ( ) => {
10899 const output = captureStdout ( ) ;
109100
110101 await runTokenPlan ( makeUsageResponse ( ) ) ;
111102
112- const renderedOutput = output . join ( "" ) ;
113- expect ( renderedOutput ) . toContain (
114- "The 5-hour limit may be unlimited; verify in the Bailian Token Plan console." ,
115- ) ;
116- expect ( renderedOutput ) . toContain (
117- "The 1-week limit may be unlimited; verify in the Bailian Token Plan console." ,
118- ) ;
119- } ) ;
120-
121- test ( "renders only the missing quota window as possibly unlimited" , async ( ) => {
122- const output = captureStdout ( ) ;
123-
124- await runTokenPlan ( makeUsageResponse ( undefined , 0.5 ) ) ;
125-
126- const renderedOutput = output . join ( "" ) ;
127- expect ( renderedOutput ) . toContain (
128- "The 5-hour limit may be unlimited; verify in the Bailian Token Plan console." ,
129- ) ;
130- expect ( renderedOutput ) . not . toContain (
131- "The 1-week limit may be unlimited; verify in the Bailian Token Plan console." ,
103+ expect ( output . join ( "" ) ) . toContain (
104+ "The monthly limit may be unlimited; verify in the Bailian Token Plan console." ,
132105 ) ;
133- expect ( renderedOutput ) . toMatch ( / R e s e t s : \d { 4 } - \d { 2 } - \d { 2 } \d { 2 } : \d { 2 } : \d { 2 } / ) ;
134106 } ) ;
135107
136- test ( "renders a window with a missing percentage as possibly unlimited even when its reset time is present" , async ( ) => {
108+ test ( "renders the monthly window as possibly unlimited when its percentage is missing even if the reset time is present" , async ( ) => {
137109 const output = captureStdout ( ) ;
138110
139- await runTokenPlan ( wrapResponse ( { per5HourResetTime : 1_786_000_000_000 } ) ) ;
111+ await runTokenPlan ( wrapResponse ( { per1MonthResetTime : 1_786_000_000_000 } ) ) ;
140112
141113 expect ( output . join ( "" ) ) . toContain (
142- "The 5-hour limit may be unlimited; verify in the Bailian Token Plan console." ,
114+ "The monthly limit may be unlimited; verify in the Bailian Token Plan console." ,
143115 ) ;
144116 } ) ;
145117
146118 test ( "treats non-numeric quota fields as absent instead of failing" , async ( ) => {
147119 const output = captureStdout ( ) ;
148120
149- await runTokenPlan (
150- wrapResponse ( { per5HourPercentage : "not-a-number" , per1WeekPercentage : Number . NaN } ) ,
151- ) ;
121+ await runTokenPlan ( wrapResponse ( { per1MonthPercentage : "not-a-number" } ) ) ;
152122
153- const renderedOutput = output . join ( "" ) ;
154- expect ( renderedOutput ) . toContain (
155- "The 5-hour limit may be unlimited; verify in the Bailian Token Plan console." ,
156- ) ;
157- expect ( renderedOutput ) . toContain (
158- "The 1-week limit may be unlimited; verify in the Bailian Token Plan console." ,
123+ expect ( output . join ( "" ) ) . toContain (
124+ "The monthly limit may be unlimited; verify in the Bailian Token Plan console." ,
159125 ) ;
160126 } ) ;
161127} ) ;
162128
163129describe ( "usage token-plan json" , ( ) => {
164- test ( "outputs the four core usage fields with --output json" , async ( ) => {
130+ test ( "outputs the monthly usage fields with --output json" , async ( ) => {
165131 const output = captureStdout ( ) ;
166132
167- await runTokenPlan ( makeUsageResponse ( 0.5 , 0.25 ) , "json" ) ;
133+ await runTokenPlan ( makeUsageResponse ( 0.5 ) , "json" ) ;
168134
169135 expect ( JSON . parse ( output . join ( "" ) ) ) . toEqual ( {
170- per5HourPercentage : 0.5 ,
171- per5HourResetTime : 1_786_000_000_000 ,
172- per1WeekPercentage : 0.25 ,
173- per1WeekResetTime : 1_786_100_000_000 ,
136+ per1MonthPercentage : 0.5 ,
137+ per1MonthResetTime : 1_786_000_000_000 ,
174138 } ) ;
175139 } ) ;
176140
@@ -186,10 +150,10 @@ describe("usage token-plan json", () => {
186150 const output = captureStdout ( ) ;
187151
188152 await runTokenPlan (
189- wrapResponse ( { per5HourPercentage : "not-a-number" , per1WeekPercentage : 0 } ) ,
153+ wrapResponse ( { per1MonthPercentage : "not-a-number" , per1MonthResetTime : 1_786_000_000_000 } ) ,
190154 "json" ,
191155 ) ;
192156
193- expect ( JSON . parse ( output . join ( "" ) ) ) . toEqual ( { per1WeekPercentage : 0 } ) ;
157+ expect ( JSON . parse ( output . join ( "" ) ) ) . toEqual ( { per1MonthResetTime : 1_786_000_000_000 } ) ;
194158 } ) ;
195159} ) ;
0 commit comments