@@ -6,6 +6,7 @@ var watson = require('../index');
6
6
var assert = require ( 'assert' ) ;
7
7
var wav = require ( 'wav' ) ;
8
8
var concat = require ( 'concat-stream' ) ;
9
+ var path = require ( 'path' ) ;
9
10
10
11
describe ( 'integration-all-services' , function ( ) {
11
12
@@ -23,7 +24,7 @@ describe('integration-all-services', function() {
23
24
}
24
25
25
26
var auth = require ( './resources/auth' ) ;
26
- var mobydick = fs . readFileSync ( __dirname + '/ resources/mobydick.txt', 'utf8' ) ;
27
+ var mobydick = fs . readFileSync ( path . join ( __dirname , ' resources/mobydick.txt') , 'utf8' ) ;
27
28
28
29
this . retries ( 1 ) ;
29
30
@@ -266,8 +267,166 @@ describe('integration-all-services', function() {
266
267
} ) ;
267
268
} ) ;
268
269
} ) ;
269
- } ) ;
270
- } ) ;
270
+
271
+ describe ( "collections" , function ( ) {
272
+ this . retries ( 0 ) ;
273
+ var collection_id ;
274
+ var image_id ;
275
+
276
+ // todo: consider doing some cleanup work and deleting anything older than an hour or so to avoid hitting the 5-collection limit
277
+
278
+ it ( 'createCollection()' , function ( done ) {
279
+ visual_recognition . createCollection ( { name : "integration_test_" + Date . now ( ) } , function ( err , result ) {
280
+ if ( err ) {
281
+ return done ( err ) ;
282
+ }
283
+ assert ( result . collection_id ) ;
284
+ collection_id = result . collection_id ;
285
+ done ( ) ;
286
+ } ) ;
287
+ } ) ;
288
+
289
+ it ( 'listCollections()' , function ( done ) {
290
+ visual_recognition . listCollections ( { } , function ( err , result ) {
291
+ if ( err ) {
292
+ return done ( err ) ;
293
+ }
294
+ assert ( result ) ;
295
+ assert ( result . collections ) ;
296
+ assert ( result . collections . length ) ;
297
+ // todo: consider looping through collections to assert that collection_id is in the list
298
+ if ( result . collections . length > 1 ) {
299
+ //eslint-disable-next-line no-console
300
+ console . warn ( "Visual Recognition %s collections found, maximum is 5" )
301
+ }
302
+ done ( ) ;
303
+ } ) ;
304
+ } ) ;
305
+
306
+
307
+ it ( 'getCollection()' , function ( done ) {
308
+ visual_recognition . getCollection ( { collection_id : collection_id } , function ( err , result ) {
309
+ if ( err ) {
310
+ return done ( err ) ;
311
+ }
312
+ assert ( result ) ;
313
+ assert . equal ( result . collection_id , collection_id ) ;
314
+ done ( ) ;
315
+ } ) ;
316
+ } ) ;
317
+
318
+ it ( 'addImage()' , function ( done ) {
319
+ visual_recognition . addImage ( {
320
+ collection_id : collection_id ,
321
+ image_file : fs . createReadStream ( path . join ( __dirname , 'resources/obama.jpg' ) ) ,
322
+ metadata : { foo : 'bar' }
323
+ } , function ( err , response ) {
324
+ if ( err ) {
325
+ return done ( err ) ;
326
+ }
327
+ assert ( response ) ;
328
+ assert . equal ( response . images_processed , 1 ) ;
329
+ assert ( response . images ) ;
330
+ assert ( response . images . length ) ;
331
+ assert ( response . images [ 0 ] . image_id ) ;
332
+ image_id = response . images [ 0 ] . image_id ;
333
+ assert . equal ( response . images [ 0 ] . image_file , "obama.jpg" ) ;
334
+ assert ( response . images [ 0 ] . metadata ) ;
335
+ assert . equal ( response . images [ 0 ] . metadata . foo , "bar" ) ;
336
+ done ( ) ;
337
+ } ) ;
338
+ } ) ;
339
+
340
+ it ( 'listImages()' , function ( done ) {
341
+ visual_recognition . listImages ( { collection_id : collection_id } , function ( err , result ) {
342
+ if ( err ) {
343
+ return done ( err ) ;
344
+ }
345
+ assert ( result ) ;
346
+ assert ( result . images ) ;
347
+ assert ( result . images . length ) ;
348
+ done ( ) ;
349
+ } ) ;
350
+ } ) ;
351
+
352
+ it ( 'getImage()' , function ( done ) {
353
+ visual_recognition . getImage ( {
354
+ collection_id : collection_id ,
355
+ image_id : image_id
356
+ } , function ( err , result ) {
357
+ if ( err ) {
358
+ return done ( err ) ;
359
+ }
360
+ assert ( result ) ;
361
+ assert ( result . image_id ) ;
362
+ done ( ) ;
363
+ } ) ;
364
+ } ) ;
365
+
366
+ it ( 'setImageMetadata' , function ( done ) {
367
+ visual_recognition . setImageMetadata ( {
368
+ collection_id : collection_id ,
369
+ image_id : image_id ,
370
+ metadata : { baz : 'bam' }
371
+ } , function ( err , result ) {
372
+ if ( err ) {
373
+ return done ( err ) ;
374
+ }
375
+ assert ( result ) ;
376
+ assert . equal ( result . baz , 'bam' ) ;
377
+ done ( ) ;
378
+ } ) ;
379
+ } ) ;
380
+
381
+ it ( 'getImageMetadata()' , function ( done ) {
382
+ visual_recognition . getImageMetadata ( {
383
+ collection_id : collection_id ,
384
+ image_id : image_id
385
+ } , function ( err , result ) {
386
+ if ( err ) {
387
+ return done ( err ) ;
388
+ }
389
+ assert ( result ) ;
390
+ assert . equal ( result . baz , 'bam' ) ;
391
+ done ( ) ;
392
+ } ) ;
393
+ } ) ;
394
+
395
+ it ( 'findSimilar()' , function ( done ) {
396
+ visual_recognition . findSimilar ( {
397
+ collection_id : collection_id ,
398
+ image_file : fs . createReadStream ( path . join ( __dirname , 'resources/obama2.jpg' ) ) ,
399
+ } , function ( err , result ) {
400
+ if ( err ) {
401
+ return done ( err ) ;
402
+ }
403
+ assert ( result ) ;
404
+ assert ( result . images_processed ) ;
405
+ assert ( result . similar_images ) ;
406
+ done ( ) ;
407
+ } ) ;
408
+ } ) ;
409
+
410
+ it ( 'deleteImageMetadata()' , function ( done ) {
411
+ visual_recognition . deleteImageMetadata ( {
412
+ collection_id : collection_id ,
413
+ image_id : image_id
414
+ } , done ) ;
415
+ } ) ;
416
+
417
+ it ( 'deleteImage()' , function ( done ) {
418
+ visual_recognition . deleteImage ( {
419
+ collection_id : collection_id ,
420
+ image_id : image_id
421
+ } , done ) ;
422
+ } ) ;
423
+
424
+ it ( 'deleteCollection()' , function ( done ) {
425
+ visual_recognition . deleteCollection ( { collection_id : collection_id } , done ) ;
426
+ } ) ;
427
+ } ) ; // collections
428
+ } ) ; // v3
429
+ } ) ; // vr
271
430
272
431
describe ( 'functional_tradeoff_analytics' , function ( ) {
273
432
this . timeout ( TWENTY_SECONDS ) ;
0 commit comments