@@ -81,20 +81,33 @@ export class MockConnectorClient {
8181 ...options ?. headers ,
8282 } ,
8383 } )
84+ if ( ! response . ok ) {
85+ throw new Error (
86+ `Mock connector request failed: ${ response . status } ${ response . statusText } (${ path } )` ,
87+ )
88+ }
8489 return response . json ( ) as Promise < T >
8590 }
8691
87- /** Reset the mock connector state */
88- async reset ( ) : Promise < void > {
89- // Reset state via test endpoint (no auth required)
90- await fetch ( `${ this . baseUrl } /__test__/reset` , { method : 'POST' } )
91-
92- // Connect to establish session
93- await fetch ( `${ this . baseUrl } /connect` , {
92+ /** Make a fire-and-forget POST to a test-only endpoint, throwing on failure. */
93+ private async testEndpoint ( path : string , body : unknown ) : Promise < void > {
94+ const response = await fetch ( `${ this . baseUrl } ${ path } ` , {
9495 method : 'POST' ,
9596 headers : { 'Content-Type' : 'application/json' } ,
96- body : JSON . stringify ( { token : this . token } ) ,
97+ body : JSON . stringify ( body ) ,
9798 } )
99+ if ( ! response . ok ) {
100+ throw new Error (
101+ `Mock connector test endpoint failed: ${ response . status } ${ response . statusText } (${ path } )` ,
102+ )
103+ }
104+ }
105+
106+ /** Reset the mock connector state */
107+ async reset ( ) : Promise < void > {
108+ await this . testEndpoint ( '/__test__/reset' , { } )
109+ // Connect to establish session
110+ await this . testEndpoint ( '/connect' , { token : this . token } )
98111 }
99112
100113 /** Set org data */
@@ -106,41 +119,25 @@ export class MockConnectorClient {
106119 teamMembers ?: Record < string , string [ ] >
107120 } ,
108121 ) : Promise < void > {
109- await fetch ( `${ this . baseUrl } /__test__/org` , {
110- method : 'POST' ,
111- headers : { 'Content-Type' : 'application/json' } ,
112- body : JSON . stringify ( { org, ...data } ) ,
113- } )
122+ await this . testEndpoint ( '/__test__/org' , { org, ...data } )
114123 }
115124
116125 /** Set user orgs */
117126 async setUserOrgs ( orgs : string [ ] ) : Promise < void > {
118- await fetch ( `${ this . baseUrl } /__test__/user-orgs` , {
119- method : 'POST' ,
120- headers : { 'Content-Type' : 'application/json' } ,
121- body : JSON . stringify ( { orgs } ) ,
122- } )
127+ await this . testEndpoint ( '/__test__/user-orgs' , { orgs } )
123128 }
124129
125130 /** Set user packages */
126131 async setUserPackages ( packages : Record < string , 'read-only' | 'read-write' > ) : Promise < void > {
127- await fetch ( `${ this . baseUrl } /__test__/user-packages` , {
128- method : 'POST' ,
129- headers : { 'Content-Type' : 'application/json' } ,
130- body : JSON . stringify ( { packages } ) ,
131- } )
132+ await this . testEndpoint ( '/__test__/user-packages' , { packages } )
132133 }
133134
134135 /** Set package data */
135136 async setPackageData (
136137 pkg : string ,
137138 data : { collaborators ?: Record < string , 'read-only' | 'read-write' > } ,
138139 ) : Promise < void > {
139- await fetch ( `${ this . baseUrl } /__test__/package` , {
140- method : 'POST' ,
141- headers : { 'Content-Type' : 'application/json' } ,
142- body : JSON . stringify ( { package : pkg , ...data } ) ,
143- } )
140+ await this . testEndpoint ( '/__test__/package' , { package : pkg , ...data } )
144141 }
145142
146143 /** Add an operation */
0 commit comments