@@ -34,6 +34,9 @@ describe('visual recognition v4 integration', () => {
3434 let collectionId ;
3535 let imageId ;
3636
37+ const object = 'node sdk test - temp' ;
38+ const newObject = 'node sdk test - temp - updated' ;
39+
3740 describe ( 'analysis' , ( ) => {
3841 test ( 'analyze' , async done => {
3942 const params = {
@@ -142,9 +145,6 @@ describe('visual recognition v4 integration', () => {
142145 } ) ;
143146
144147 describe ( 'images' , ( ) => {
145- // const collectionId = giraffesCollectionId;
146- let imageId ;
147-
148148 test ( 'addImages' , async done => {
149149 if ( ! collectionId ) {
150150 return done ( ) ;
@@ -256,7 +256,7 @@ describe('visual recognition v4 integration', () => {
256256 imageId,
257257 objects : [
258258 {
259- object : 'node sdk unit test - temp' ,
259+ object,
260260 location : {
261261 top : 8 ,
262262 left : 48 ,
@@ -278,6 +278,7 @@ describe('visual recognition v4 integration', () => {
278278 const { result } = res || { } ;
279279 expect ( result ) . toBeDefined ( ) ;
280280 expect ( result . objects ) . toBeDefined ( ) ;
281+ expect ( result . objects . length ) . toBeGreaterThan ( 0 ) ;
281282
282283 // for some reason, train won't work in it's own test,
283284 // even when I run the tests serially
@@ -293,7 +294,7 @@ describe('visual recognition v4 integration', () => {
293294
294295 expect ( res2 ) . toBeDefined ( ) ;
295296 expect ( res2 . status ) . toBe ( 202 ) ;
296- const { result2 } = res2 || { } ;
297+ const result2 = res2 . result || { } ;
297298 expect ( result2 ) . toBeDefined ( ) ;
298299
299300 done ( ) ;
@@ -314,6 +315,107 @@ describe('visual recognition v4 integration', () => {
314315 } ) ;
315316 } ) ;
316317
318+ describe ( 'objects' , ( ) => {
319+ // need to ensure training data is added before running these tests
320+ beforeAll ( async done => {
321+ const params = {
322+ collectionId,
323+ imageId,
324+ objects : [
325+ {
326+ object,
327+ location : {
328+ top : 8 ,
329+ left : 48 ,
330+ width : 101 ,
331+ height : 91 ,
332+ } ,
333+ } ,
334+ ] ,
335+ } ;
336+
337+ try {
338+ await visualRecognition . addImageTrainingData ( params ) ;
339+ } catch ( err ) {
340+ return done ( err ) ;
341+ }
342+
343+ done ( ) ;
344+ } ) ;
345+
346+ test ( 'listObjectMetadata' , async done => {
347+ if ( ! collectionId ) {
348+ return done ( ) ;
349+ }
350+
351+ const params = {
352+ collectionId,
353+ } ;
354+
355+ let res ;
356+ try {
357+ res = await visualRecognition . listObjectMetadata ( params ) ;
358+ } catch ( err ) {
359+ return done ( err ) ;
360+ }
361+
362+ expect ( res ) . toBeDefined ( ) ;
363+ const { result } = res || { } ;
364+ expect ( result ) . toBeDefined ( ) ;
365+ expect ( result . object_count ) . toBeGreaterThan ( 0 ) ;
366+ done ( ) ;
367+ } ) ;
368+
369+ test ( 'getObjectMetadata' , async done => {
370+ if ( ! collectionId || ! object ) {
371+ return done ( ) ;
372+ }
373+
374+ const params = {
375+ collectionId,
376+ object,
377+ } ;
378+
379+ let res ;
380+ try {
381+ res = await visualRecognition . getObjectMetadata ( params ) ;
382+ } catch ( err ) {
383+ return done ( err ) ;
384+ }
385+
386+ expect ( res ) . toBeDefined ( ) ;
387+ const { result } = res || { } ;
388+ expect ( result ) . toBeDefined ( ) ;
389+ expect ( result . object ) . toBe ( object ) ;
390+ done ( ) ;
391+ } ) ;
392+
393+ test ( 'updateObjectMetadata' , async done => {
394+ if ( ! collectionId || ! object ) {
395+ return done ( ) ;
396+ }
397+
398+ const params = {
399+ collectionId,
400+ object,
401+ newObject,
402+ } ;
403+
404+ let res ;
405+ try {
406+ res = await visualRecognition . updateObjectMetadata ( params ) ;
407+ } catch ( err ) {
408+ return done ( err ) ;
409+ }
410+
411+ expect ( res ) . toBeDefined ( ) ;
412+ const { result } = res || { } ;
413+ expect ( result ) . toBeDefined ( ) ;
414+ expect ( result . object ) . toBe ( newObject ) ;
415+ done ( ) ;
416+ } ) ;
417+ } ) ;
418+
317419 describe ( 'userData' , ( ) => {
318420 test ( 'deleteUserData' , async done => {
319421 const params = {
@@ -335,6 +437,29 @@ describe('visual recognition v4 integration', () => {
335437 } ) ;
336438
337439 describe ( 'cleanup - test the delete operations' , ( ) => {
440+ test ( 'deleteObject' , async done => {
441+ if ( ! collectionId ) {
442+ return done ( ) ;
443+ }
444+
445+ const params = {
446+ collectionId,
447+ object : newObject ,
448+ } ;
449+
450+ let res ;
451+ try {
452+ res = await visualRecognition . deleteObject ( params ) ;
453+ } catch ( err ) {
454+ return done ( err ) ;
455+ }
456+
457+ expect ( res ) . toBeDefined ( ) ;
458+ const { result } = res || { } ;
459+ expect ( result ) . toBeDefined ( ) ;
460+ done ( ) ;
461+ } ) ;
462+
338463 test ( 'deleteImage' , async done => {
339464 if ( ! collectionId || ! imageId ) {
340465 return done ( ) ;
0 commit comments