@@ -66,24 +66,30 @@ describe("billing subscribe", () => {
6666} ) ;
6767
6868describe ( "billing add-credits" , ( ) => {
69- it . each ( [ "add-credits" , "top-up" ] ) (
70- "opens the credits page for `%s`, with no notice" ,
71- async ( name ) => {
72- vi . stubEnv ( "HYPERFRAMES_PLANS_URL" , "https://plans.test/p" ) ;
73- vi . stubEnv ( "HYPERFRAMES_CREDITS_URL" , "https://credits.test/c" ) ;
74- const log = vi . spyOn ( console , "log" ) . mockImplementation ( ( ) => undefined ) ;
75- const error = vi . spyOn ( console , "error" ) . mockImplementation ( ( ) => undefined ) ;
76- vi . useFakeTimers ( ) ;
77- const done = runCommand ( billing , { rawArgs : [ name ] } ) ;
78- await vi . advanceTimersByTimeAsync ( 2000 ) ;
79- await done ;
80- vi . useRealTimers ( ) ;
81- vi . unstubAllEnvs ( ) ;
82- expect ( new URL ( opened [ 0 ] ?? "" ) . origin ) . toBe ( "https://credits.test" ) ;
83- expect ( error ) . not . toHaveBeenCalled ( ) ;
84- expect ( log . mock . calls . flat ( ) . join ( "\n" ) ) . not . toMatch ( / d e p r e c a t | r e n a m e d | t o p - u p / i) ;
85- } ,
86- ) ;
69+ it ( "opens the credits page" , async ( ) => {
70+ vi . stubEnv ( "HYPERFRAMES_PLANS_URL" , "https://plans.test/p" ) ;
71+ vi . stubEnv ( "HYPERFRAMES_CREDITS_URL" , "https://credits.test/c" ) ;
72+ const log = vi . spyOn ( console , "log" ) . mockImplementation ( ( ) => undefined ) ;
73+ const error = vi . spyOn ( console , "error" ) . mockImplementation ( ( ) => undefined ) ;
74+ vi . useFakeTimers ( ) ;
75+ const done = runCommand ( billing , { rawArgs : [ "add-credits" ] } ) ;
76+ await vi . advanceTimersByTimeAsync ( 2000 ) ;
77+ await done ;
78+ vi . useRealTimers ( ) ;
79+ vi . unstubAllEnvs ( ) ;
80+ expect ( new URL ( opened [ 0 ] ?? "" ) . origin ) . toBe ( "https://credits.test" ) ;
81+ expect ( error ) . not . toHaveBeenCalled ( ) ;
82+ expect ( log . mock . calls . flat ( ) . join ( "\n" ) ) . not . toMatch ( / d e p r e c a t | r e n a m e d | t o p - u p / i) ;
83+ } ) ;
84+
85+ it ( "refuses the old name `top-up` like any unknown action, naming the valid ones" , async ( ) => {
86+ const error = vi . spyOn ( console , "error" ) . mockImplementation ( ( ) => undefined ) ;
87+ await expect ( runCommand ( billing , { rawArgs : [ "top-up" ] } ) ) . rejects . toThrow ( ) ;
88+ expect ( error . mock . calls . flat ( ) . join ( "\n" ) ) . toContain (
89+ "Use `billing subscribe` or `billing add-credits`." ,
90+ ) ;
91+ expect ( opened ) . toEqual ( [ ] ) ;
92+ } ) ;
8793} ) ;
8894
8995describe ( "billing without a terminal" , ( ) => {
0 commit comments