@@ -17,6 +17,7 @@ vi.mock("vscode", () => ({
1717 window : {
1818 showInformationMessage : vi . fn ( ) ,
1919 showErrorMessage : vi . fn ( ) ,
20+ showQuickPick : vi . fn ( ) ,
2021 } ,
2122 env : {
2223 clipboard : {
@@ -68,24 +69,24 @@ describe("ShareService", () => {
6869 } )
6970
7071 describe ( "shareTask" , ( ) => {
71- it ( "should share task and copy to clipboard" , async ( ) => {
72+ it ( "should share task with organization visibility and copy to clipboard" , async ( ) => {
7273 const mockResponse = {
7374 data : {
7475 success : true ,
7576 shareUrl : "https://app.roocode.com/share/abc123" ,
7677 } ,
7778 }
7879
79- ; ( mockAuthService . hasActiveSession as any ) . mockReturnValue ( true )
8080 ; ( mockAuthService . getSessionToken as any ) . mockReturnValue ( "session-token" )
8181 mockedAxios . post . mockResolvedValue ( mockResponse )
8282
83- const result = await shareService . shareTask ( "task-123" )
83+ const result = await shareService . shareTask ( "task-123" , "organization" )
8484
85- expect ( result ) . toBe ( true )
85+ expect ( result . success ) . toBe ( true )
86+ expect ( result . shareUrl ) . toBe ( "https://app.roocode.com/share/abc123" )
8687 expect ( mockedAxios . post ) . toHaveBeenCalledWith (
8788 "https://app.roocode.com/api/extension/share" ,
88- { taskId : "task-123" } ,
89+ { taskId : "task-123" , visibility : "organization" } ,
8990 {
9091 headers : {
9192 "Content-Type" : "application/json" ,
@@ -97,63 +98,76 @@ describe("ShareService", () => {
9798 expect ( vscode . env . clipboard . writeText ) . toHaveBeenCalledWith ( "https://app.roocode.com/share/abc123" )
9899 } )
99100
100- it ( "should handle API error response " , async ( ) => {
101+ it ( "should share task with public visibility " , async ( ) => {
101102 const mockResponse = {
102103 data : {
103- success : false ,
104- error : "Task not found " ,
104+ success : true ,
105+ shareUrl : "https://app.roocode.com/share/abc123 " ,
105106 } ,
106107 }
107108
108- ; ( mockAuthService . hasActiveSession as any ) . mockReturnValue ( true )
109109 ; ( mockAuthService . getSessionToken as any ) . mockReturnValue ( "session-token" )
110110 mockedAxios . post . mockResolvedValue ( mockResponse )
111111
112- const result = await shareService . shareTask ( "task-123" )
112+ const result = await shareService . shareTask ( "task-123" , "public" )
113113
114- expect ( result ) . toBe ( false )
114+ expect ( result . success ) . toBe ( true )
115+ expect ( mockedAxios . post ) . toHaveBeenCalledWith (
116+ "https://app.roocode.com/api/extension/share" ,
117+ { taskId : "task-123" , visibility : "public" } ,
118+ expect . any ( Object ) ,
119+ )
115120 } )
116121
117- it ( "should handle authentication errors" , async ( ) => {
118- ; ( mockAuthService . hasActiveSession as any ) . mockReturnValue ( false )
122+ it ( "should default to organization visibility when not specified" , async ( ) => {
123+ const mockResponse = {
124+ data : {
125+ success : true ,
126+ shareUrl : "https://app.roocode.com/share/abc123" ,
127+ } ,
128+ }
129+
130+ ; ( mockAuthService . getSessionToken as any ) . mockReturnValue ( "session-token" )
131+ mockedAxios . post . mockResolvedValue ( mockResponse )
119132
120133 const result = await shareService . shareTask ( "task-123" )
121134
122- expect ( result ) . toBe ( false )
123- expect ( mockedAxios . post ) . not . toHaveBeenCalled ( )
135+ expect ( result . success ) . toBe ( true )
136+ expect ( mockedAxios . post ) . toHaveBeenCalledWith (
137+ "https://app.roocode.com/api/extension/share" ,
138+ { taskId : "task-123" , visibility : "organization" } ,
139+ expect . any ( Object ) ,
140+ )
124141 } )
125142
126- it ( "should handle 403 error for disabled sharing" , async ( ) => {
127- ; ( mockAuthService . hasActiveSession as any ) . mockReturnValue ( true )
128- ; ( mockAuthService . getSessionToken as any ) . mockReturnValue ( "session-token" )
129-
130- const error = {
131- isAxiosError : true ,
132- response : {
133- status : 403 ,
134- data : {
135- error : "Task sharing is not enabled for this organization" ,
136- } ,
143+ it ( "should handle API error response" , async ( ) => {
144+ const mockResponse = {
145+ data : {
146+ success : false ,
147+ error : "Task not found" ,
137148 } ,
138149 }
139150
140- mockedAxios . isAxiosError . mockReturnValue ( true )
141- mockedAxios . post . mockRejectedValue ( error )
151+ ; ( mockAuthService . getSessionToken as any ) . mockReturnValue ( "session-token" )
152+ mockedAxios . post . mockResolvedValue ( mockResponse )
142153
143- const result = await shareService . shareTask ( "task-123" )
154+ const result = await shareService . shareTask ( "task-123" , "organization" )
144155
145- expect ( result ) . toBe ( false )
156+ expect ( result . success ) . toBe ( false )
157+ expect ( result . error ) . toBe ( "Task not found" )
158+ } )
159+
160+ it ( "should handle authentication errors" , async ( ) => {
161+ ; ( mockAuthService . getSessionToken as any ) . mockReturnValue ( null )
162+
163+ await expect ( shareService . shareTask ( "task-123" , "organization" ) ) . rejects . toThrow ( "Authentication required" )
146164 } )
147165
148166 it ( "should handle unexpected errors" , async ( ) => {
149- ; ( mockAuthService . hasActiveSession as any ) . mockReturnValue ( true )
150167 ; ( mockAuthService . getSessionToken as any ) . mockReturnValue ( "session-token" )
151-
152168 mockedAxios . post . mockRejectedValue ( new Error ( "Network error" ) )
153169
154- const result = await shareService . shareTask ( "task-123" )
155-
156- expect ( result ) . toBe ( false )
170+ await expect ( shareService . shareTask ( "task-123" , "organization" ) ) . rejects . toThrow ( "Network error" )
157171 } )
158172 } )
159173
0 commit comments