@@ -22,6 +22,20 @@ vi.mock("../../src/lib/oauth.js", () => ({
2222 revokeToken : ( ...args : unknown [ ] ) => revokeToken ( ...args ) ,
2323} ) ) ;
2424vi . mock ( "open" , ( ) => ( { default : vi . fn ( ) } ) ) ;
25+ vi . mock ( "yocto-spinner" , ( ) => {
26+ const spinner : Record < string , unknown > = { text : "" } ;
27+ spinner . start = vi . fn ( ( ) => spinner ) ;
28+ spinner . stop = vi . fn ( ( ) => spinner ) ;
29+ return { default : ( ) => spinner } ;
30+ } ) ;
31+ vi . mock ( "../../src/lib/program.js" , ( ) => ( {
32+ program : { opts : ( ) => ( { } ) } ,
33+ } ) ) ;
34+
35+ const graphqlRequest = vi . fn ( ) ;
36+ vi . mock ( "../../src/lib/graphql-client.js" , ( ) => ( {
37+ graphqlRequest : ( ...args : unknown [ ] ) => graphqlRequest ( ...args ) ,
38+ } ) ) ;
2539
2640const { authCommand } = await import ( "../../src/commands/auth.js" ) ;
2741
@@ -104,4 +118,65 @@ describe("auth", () => {
104118 expect ( loadTokens ) . toHaveBeenCalled ( ) ;
105119 } ) ;
106120 } ) ;
121+
122+ describe ( "update-profile" , ( ) => {
123+ it ( "sends first name and last name" , async ( ) => {
124+ graphqlRequest . mockResolvedValueOnce ( {
125+ updateUserProfile : {
126+ id : "usr_1" ,
127+ auth : { email : "test@example.com" } ,
128+ profile : { firstName : "Ben" , lastName : "Sabic" } ,
129+ } ,
130+ } ) ;
131+
132+ await runCommand ( authCommand , [
133+ "update-profile" ,
134+ "--first-name" ,
135+ "Ben" ,
136+ "--last-name" ,
137+ "Sabic" ,
138+ ] ) ;
139+
140+ const call = graphqlRequest . mock . calls [ 0 ] [ 0 ] ;
141+ expect ( call . variables . input ) . toEqual ( {
142+ firstName : "Ben" ,
143+ lastName : "Sabic" ,
144+ } ) ;
145+ } ) ;
146+
147+ it ( "sends email only" , async ( ) => {
148+ graphqlRequest . mockResolvedValueOnce ( {
149+ updateUserProfile : {
150+ id : "usr_1" ,
151+ auth : { email : "new@example.com" } ,
152+ profile : { firstName : "Ben" , lastName : "Sabic" } ,
153+ } ,
154+ } ) ;
155+
156+ await runCommand ( authCommand , [
157+ "update-profile" ,
158+ "--email" ,
159+ "new@example.com" ,
160+ ] ) ;
161+
162+ const call = graphqlRequest . mock . calls [ 0 ] [ 0 ] ;
163+ expect ( call . variables . input ) . toEqual ( { email : "new@example.com" } ) ;
164+ } ) ;
165+
166+ it ( "rejects with no options" , async ( ) => {
167+ const original = process . exitCode ;
168+ await runCommand ( authCommand , [ "update-profile" ] ) ;
169+ expect ( process . exitCode ) . toBe ( 1 ) ;
170+ process . exitCode = original ;
171+ } ) ;
172+
173+ it ( "handles errors gracefully" , async ( ) => {
174+ graphqlRequest . mockRejectedValueOnce ( new Error ( "Unauthorized" ) ) ;
175+
176+ const original = process . exitCode ;
177+ await runCommand ( authCommand , [ "update-profile" , "--first-name" , "Test" ] ) ;
178+ expect ( process . exitCode ) . toBe ( 1 ) ;
179+ process . exitCode = original ;
180+ } ) ;
181+ } ) ;
107182} ) ;
0 commit comments