@@ -127,6 +127,178 @@ describe('admin.machineLearning', () => {
127
127
} ) ;
128
128
} ) ;
129
129
130
+ describe ( 'updateModel()' , ( ) => {
131
+
132
+ const UPDATE_NAME : admin . machineLearning . ModelOptions = {
133
+ displayName : 'update-model-new-name' ,
134
+ } ;
135
+
136
+ it ( 'rejects with not-found when the Model does not exist' , ( ) => {
137
+ const nonExistingId = '00000000' ;
138
+ return admin . machineLearning ( ) . updateModel ( nonExistingId , UPDATE_NAME )
139
+ . should . eventually . be . rejected . and . have . property (
140
+ 'code' , 'machine-learning/not-found' ) ;
141
+ } ) ;
142
+
143
+ it ( 'rejects with invalid-argument when the ModelId is invalid' , ( ) => {
144
+ return admin . machineLearning ( ) . updateModel ( 'invalid-model-id' , UPDATE_NAME )
145
+ . should . eventually . be . rejected . and . have . property (
146
+ 'code' , 'machine-learning/invalid-argument' ) ;
147
+ } ) ;
148
+
149
+ it ( 'rejects with invalid-argument when modelOptions are invalid' , ( ) => {
150
+ const modelOptions : admin . machineLearning . ModelOptions = {
151
+ displayName : 'Invalid Name#*^!' ,
152
+ } ;
153
+ return createTemporaryModel ( { displayName : 'node-integration-invalid-argument' } )
154
+ . then ( ( model ) => admin . machineLearning ( ) . updateModel ( model . modelId , modelOptions )
155
+ . should . eventually . be . rejected . and . have . property (
156
+ 'code' , 'machine-learning/invalid-argument' ) ) ;
157
+ } ) ;
158
+
159
+ it ( 'updates the displayName' , ( ) => {
160
+ const DISPLAY_NAME = 'node-integration-test-update-1b' ;
161
+ return createTemporaryModel ( { displayName : 'node-integration-test-update-1a' } )
162
+ . then ( ( model ) => {
163
+ const modelOptions : admin . machineLearning . ModelOptions = {
164
+ displayName : DISPLAY_NAME ,
165
+ } ;
166
+ return admin . machineLearning ( ) . updateModel ( model . modelId , modelOptions )
167
+ . then ( ( updatedModel ) => {
168
+ verifyModel ( updatedModel , modelOptions ) ;
169
+ } ) ;
170
+ } ) ;
171
+ } ) ;
172
+
173
+ it ( 'sets tags for a model' , ( ) => {
174
+ // TODO(ifielker): Uncomment & replace when BE change lands.
175
+ // const ORIGINAL_TAGS = ['tag-node-update-1'];
176
+ const ORIGINAL_TAGS : string [ ] = [ ] ;
177
+ const NEW_TAGS = [ 'tag-node-update-2' , 'tag-node-update-3' ] ;
178
+
179
+ return createTemporaryModel ( {
180
+ displayName : 'node-integration-test-update-2' ,
181
+ tags : ORIGINAL_TAGS ,
182
+ } ) . then ( ( expectedModel ) => {
183
+ const modelOptions : admin . machineLearning . ModelOptions = {
184
+ tags : NEW_TAGS ,
185
+ } ;
186
+ return admin . machineLearning ( ) . updateModel ( expectedModel . modelId , modelOptions )
187
+ . then ( ( actualModel ) => {
188
+ expect ( actualModel . tags ! . length ) . to . equal ( 2 ) ;
189
+ expect ( actualModel . tags ) . to . have . same . members ( NEW_TAGS ) ;
190
+ } ) ;
191
+ } ) ;
192
+ } ) ;
193
+
194
+ it ( 'updates the tflite file' , ( ) => {
195
+ Promise . all ( [
196
+ createTemporaryModel ( ) ,
197
+ uploadModelToGcs ( 'model1.tflite' , 'valid_model.tflite' ) ] )
198
+ . then ( ( [ model , fileName ] ) => {
199
+ const modelOptions : admin . machineLearning . ModelOptions = {
200
+ tfliteModel : { gcsTfliteUri : fileName } ,
201
+ } ;
202
+ return admin . machineLearning ( ) . updateModel ( model . modelId , modelOptions )
203
+ . then ( ( updatedModel ) => {
204
+ verifyModel ( updatedModel , modelOptions ) ;
205
+ } ) ;
206
+ } ) ;
207
+ } ) ;
208
+
209
+ it ( 'can update more than 1 field' , ( ) => {
210
+ const DISPLAY_NAME = 'node-integration-test-update-3b' ;
211
+ const TAGS = [ 'node-integration-tag-1' , 'node-integration-tag-2' ] ;
212
+ return createTemporaryModel ( { displayName : 'node-integration-test-update-3a' } )
213
+ . then ( ( model ) => {
214
+ const modelOptions : admin . machineLearning . ModelOptions = {
215
+ displayName : DISPLAY_NAME ,
216
+ tags : TAGS ,
217
+ } ;
218
+ return admin . machineLearning ( ) . updateModel ( model . modelId , modelOptions )
219
+ . then ( ( updatedModel ) => {
220
+ expect ( updatedModel . displayName ) . to . equal ( DISPLAY_NAME ) ;
221
+ expect ( updatedModel . tags ) . to . have . same . members ( TAGS ) ;
222
+ } ) ;
223
+ } ) ;
224
+ } ) ;
225
+ } ) ;
226
+
227
+ describe ( 'publishModel()' , ( ) => {
228
+ it ( 'should reject when model does not exist' , ( ) => {
229
+ const nonExistingName = '00000000' ;
230
+ return admin . machineLearning ( ) . publishModel ( nonExistingName )
231
+ . should . eventually . be . rejected . and . have . property (
232
+ 'code' , 'machine-learning/not-found' ) ;
233
+ } ) ;
234
+
235
+ it ( 'rejects with invalid-argument when the ModelId is invalid' , ( ) => {
236
+ return admin . machineLearning ( ) . publishModel ( 'invalid-model-id' )
237
+ . should . eventually . be . rejected . and . have . property (
238
+ 'code' , 'machine-learning/invalid-argument' ) ;
239
+ } ) ;
240
+
241
+ it ( 'publishes the model successfully' , ( ) => {
242
+ const modelOptions : admin . machineLearning . ModelOptions = {
243
+ displayName : 'node-integration-test-publish-1' ,
244
+ tfliteModel : { gcsTfliteUri : 'this will be replaced below' } ,
245
+ } ;
246
+ return uploadModelToGcs ( 'model1.tflite' , 'valid_model.tflite' )
247
+ . then ( ( fileName : string ) => {
248
+ modelOptions . tfliteModel ! . gcsTfliteUri = fileName ;
249
+ createTemporaryModel ( modelOptions )
250
+ . then ( ( createdModel ) => {
251
+ expect ( createdModel . validationError ) . to . be . empty ;
252
+ expect ( createdModel . published ) . to . be . false ;
253
+ admin . machineLearning ( ) . publishModel ( createdModel . modelId )
254
+ . then ( ( publishedModel ) => {
255
+ expect ( publishedModel . published ) . to . be . true ;
256
+ } ) ;
257
+ } ) ;
258
+ } ) ;
259
+ } ) ;
260
+ } ) ;
261
+
262
+ describe ( 'unpublishModel()' , ( ) => {
263
+ it ( 'should reject when model does not exist' , ( ) => {
264
+ const nonExistingName = '00000000' ;
265
+ return admin . machineLearning ( ) . unpublishModel ( nonExistingName )
266
+ . should . eventually . be . rejected . and . have . property (
267
+ 'code' , 'machine-learning/not-found' ) ;
268
+ } ) ;
269
+
270
+ it ( 'rejects with invalid-argument when the ModelId is invalid' , ( ) => {
271
+ return admin . machineLearning ( ) . unpublishModel ( 'invalid-model-id' )
272
+ . should . eventually . be . rejected . and . have . property (
273
+ 'code' , 'machine-learning/invalid-argument' ) ;
274
+ } ) ;
275
+
276
+ it ( 'unpublishes the model successfully' , ( ) => {
277
+ const modelOptions : admin . machineLearning . ModelOptions = {
278
+ displayName : 'node-integration-test-unpublish-1' ,
279
+ tfliteModel : { gcsTfliteUri : 'this will be replaced below' } ,
280
+ } ;
281
+ return uploadModelToGcs ( 'model1.tflite' , 'valid_model.tflite' )
282
+ . then ( ( fileName : string ) => {
283
+ modelOptions . tfliteModel ! . gcsTfliteUri = fileName ;
284
+ createTemporaryModel ( modelOptions )
285
+ . then ( ( createdModel ) => {
286
+ expect ( createdModel . validationError ) . to . be . empty ;
287
+ expect ( createdModel . published ) . to . be . false ;
288
+ admin . machineLearning ( ) . publishModel ( createdModel . modelId )
289
+ . then ( ( publishedModel ) => {
290
+ expect ( publishedModel . published ) . to . be . true ;
291
+ admin . machineLearning ( ) . unpublishModel ( publishedModel . modelId )
292
+ . then ( ( unpublishedModel ) => {
293
+ expect ( unpublishedModel . published ) . to . be . false ;
294
+ } ) ;
295
+ } ) ;
296
+ } ) ;
297
+ } ) ;
298
+ } ) ;
299
+ } ) ;
300
+
301
+
130
302
describe ( 'getModel()' , ( ) => {
131
303
it ( 'rejects with not-found when the Model does not exist' , ( ) => {
132
304
const nonExistingName = '00000000' ;
@@ -181,7 +353,11 @@ describe('admin.machineLearning', () => {
181
353
} ) ;
182
354
183
355
function verifyModel ( model : admin . machineLearning . Model , expectedOptions : admin . machineLearning . ModelOptions ) {
184
- expect ( model . displayName ) . to . equal ( expectedOptions . displayName ) ;
356
+ if ( expectedOptions . displayName ) {
357
+ expect ( model . displayName ) . to . equal ( expectedOptions . displayName ) ;
358
+ } else {
359
+ expect ( model . displayName ) . not . to . be . empty ;
360
+ }
185
361
expect ( model . createTime ) . to . not . be . empty ;
186
362
expect ( model . updateTime ) . to . not . be . empty ;
187
363
expect ( model . etag ) . to . not . be . empty ;
0 commit comments