@@ -35,7 +35,13 @@ vi.mock('@doist/comms-sdk', () => {
3535vi . mock ( './auth.js' , ( ) => ( {
3636 getApiTokenSnapshot : vi . fn ( ) . mockResolvedValue ( {
3737 token : 'test-token' ,
38- account : { id : '42' , label : 'Ada' , authMode : 'read-write' , authScope : '' } ,
38+ account : {
39+ id : '42' ,
40+ label : 'Ada' ,
41+ authMode : 'read-write' ,
42+ authResource : 'https://comms.staging.todoist.com' ,
43+ authScope : '' ,
44+ } ,
3945 } ) ,
4046 getAuthMetadata : vi . fn ( ) . mockResolvedValue ( { authMode : 'full' } ) ,
4147} ) )
@@ -59,12 +65,18 @@ vi.mock('./progress.js', () => ({
5965 getProgressTracker : ( ) => ( { isEnabled : ( ) => false , emitApiCall : vi . fn ( ) } ) ,
6066} ) )
6167
62- const { clearWorkspaceUserCache, createWrappedCommsClient, getWorkspaceUsers } =
63- await import ( './api.js' )
68+ const {
69+ clearApiClientCache,
70+ clearWorkspaceUserCache,
71+ createWrappedCommsClient,
72+ getCommsClient,
73+ getWorkspaceUsers,
74+ } = await import ( './api.js' )
6475
6576describe ( 'getWorkspaceUsers' , ( ) => {
6677 beforeEach ( ( ) => {
6778 getWorkspaceUsersMock . mockClear ( )
79+ clearApiClientCache ( )
6880 clearWorkspaceUserCache ( )
6981 } )
7082
@@ -109,6 +121,7 @@ describe('getWorkspaceUsers', () => {
109121
110122describe ( 'wrapResult — central 403 translation' , ( ) => {
111123 beforeEach ( ( ) => {
124+ clearApiClientCache ( )
112125 sdkMocks . createClient . mockReset ( )
113126 sdkMocks . deleteChannel . mockReset ( )
114127 sdkMocks . uploadAttachment . mockReset ( )
@@ -123,6 +136,14 @@ describe('wrapResult — central 403 translation', () => {
123136 } )
124137 } )
125138
139+ it ( 'uses the active OAuth account resource when creating the shared SDK client' , async ( ) => {
140+ await getCommsClient ( )
141+
142+ expect ( sdkMocks . createClient ) . toHaveBeenCalledWith ( 'test-token' , {
143+ baseUrl : 'https://comms.staging.todoist.com' ,
144+ } )
145+ } )
146+
126147 it ( 'translates a plain 403 into a FORBIDDEN CliError' , async ( ) => {
127148 sdkMocks . deleteChannel . mockRejectedValueOnce (
128149 new CommsRequestError ( 'Request failed with status 403' , 403 , { } ) ,
0 commit comments