@@ -156,4 +156,82 @@ describe('MachineLearningApiClient', () => {
156156 . should . eventually . be . rejected . and . deep . equal ( expected ) ;
157157 } ) ;
158158 } ) ;
159+
160+ describe ( 'deleteModel' , ( ) => {
161+ const INVALID_NAMES : any [ ] = [ null , undefined , '' , 1 , true , { } , [ ] ] ;
162+ INVALID_NAMES . forEach ( ( invalidName ) => {
163+ it ( `should reject when called with: ${ JSON . stringify ( invalidName ) } ` , ( ) => {
164+ return apiClient . deleteModel ( invalidName )
165+ . should . eventually . be . rejected . and . have . property (
166+ 'message' , 'Model ID must be a non-empty string.' ) ;
167+ } ) ;
168+ } ) ;
169+
170+ it ( `should reject when called with prefixed name` , ( ) => {
171+ return apiClient . deleteModel ( 'projects/foo/rulesets/bar' )
172+ . should . eventually . be . rejected . and . have . property (
173+ 'message' , 'Model ID must not contain any "/" characters.' ) ;
174+ } ) ;
175+
176+ it ( `should reject when project id is not available` , ( ) => {
177+ return clientWithoutProjectId . deleteModel ( MODEL_ID )
178+ . should . eventually . be . rejectedWith ( noProjectId ) ;
179+ } ) ;
180+
181+ it ( 'should resolve on success' , ( ) => {
182+ const stub = sinon
183+ . stub ( HttpClient . prototype , 'send' )
184+ . resolves ( utils . responseFrom ( { } ) ) ;
185+ stubs . push ( stub ) ;
186+ return apiClient . deleteModel ( MODEL_ID )
187+ . then ( ( ) => {
188+ expect ( stub ) . to . have . been . calledOnce . and . calledWith ( {
189+ method : 'DELETE' ,
190+ url : 'https://mlkit.googleapis.com/v1beta1/projects/test-project/models/1234567' ,
191+ headers : EXPECTED_HEADERS ,
192+ } ) ;
193+ } ) ;
194+ } ) ;
195+
196+ it ( 'should reject when a full platform error response is received' , ( ) => {
197+ const stub = sinon
198+ . stub ( HttpClient . prototype , 'send' )
199+ . rejects ( utils . errorFrom ( ERROR_RESPONSE , 404 ) ) ;
200+ stubs . push ( stub ) ;
201+ const expected = new FirebaseMachineLearningError ( 'not-found' , 'Requested entity not found' ) ;
202+ return apiClient . deleteModel ( MODEL_ID )
203+ . should . eventually . be . rejected . and . deep . equal ( expected ) ;
204+ } ) ;
205+
206+ it ( 'should reject with unknown-error when error code is not present' , ( ) => {
207+ const stub = sinon
208+ . stub ( HttpClient . prototype , 'send' )
209+ . rejects ( utils . errorFrom ( { } , 404 ) ) ;
210+ stubs . push ( stub ) ;
211+ const expected = new FirebaseMachineLearningError ( 'unknown-error' , 'Unknown server error: {}' ) ;
212+ return apiClient . deleteModel ( MODEL_ID )
213+ . should . eventually . be . rejected . and . deep . equal ( expected ) ;
214+ } ) ;
215+
216+ it ( 'should reject with unknown-error for non-json response' , ( ) => {
217+ const stub = sinon
218+ . stub ( HttpClient . prototype , 'send' )
219+ . rejects ( utils . errorFrom ( 'not json' , 404 ) ) ;
220+ stubs . push ( stub ) ;
221+ const expected = new FirebaseMachineLearningError (
222+ 'unknown-error' , 'Unexpected response with status: 404 and body: not json' ) ;
223+ return apiClient . deleteModel ( MODEL_ID )
224+ . should . eventually . be . rejected . and . deep . equal ( expected ) ;
225+ } ) ;
226+
227+ it ( 'should reject when failed with a FirebaseAppError' , ( ) => {
228+ const expected = new FirebaseAppError ( 'network-error' , 'socket hang up' ) ;
229+ const stub = sinon
230+ . stub ( HttpClient . prototype , 'send' )
231+ . rejects ( expected ) ;
232+ stubs . push ( stub ) ;
233+ return apiClient . deleteModel ( MODEL_ID )
234+ . should . eventually . be . rejected . and . deep . equal ( expected ) ;
235+ } ) ;
236+ } ) ;
159237} ) ;
0 commit comments