@@ -468,6 +468,91 @@ describe('VisualRecognitionV4', () => {
468468 } ) ;
469469 } ) ;
470470 } ) ;
471+ describe ( 'getModelFile' , ( ) => {
472+ describe ( 'positive tests' , ( ) => {
473+ test ( 'should pass the right params to createRequest' , ( ) => {
474+ // parameters
475+ const collectionId = 'fake_collectionId' ;
476+ const feature = 'fake_feature' ;
477+ const modelFormat = 'fake_modelFormat' ;
478+ const params = {
479+ collectionId,
480+ feature,
481+ modelFormat,
482+ } ;
483+
484+ const getModelFileResult = visualRecognition . getModelFile ( params ) ;
485+
486+ // all methods should return a Promise
487+ expectToBePromise ( getModelFileResult ) ;
488+
489+ // assert that create request was called
490+ expect ( createRequestMock ) . toHaveBeenCalledTimes ( 1 ) ;
491+
492+ const options = getOptions ( createRequestMock ) ;
493+
494+ checkUrlAndMethod ( options , '/v4/collections/{collection_id}/model' , 'GET' ) ;
495+ const expectedAccept = 'application/octet-stream' ;
496+ const expectedContentType = undefined ;
497+ checkMediaHeaders ( createRequestMock , expectedAccept , expectedContentType ) ;
498+ expect ( options . qs [ 'feature' ] ) . toEqual ( feature ) ;
499+ expect ( options . qs [ 'model_format' ] ) . toEqual ( modelFormat ) ;
500+ expect ( options . path [ 'collection_id' ] ) . toEqual ( collectionId ) ;
501+ expect ( options . responseType ) . toBe ( 'stream' ) ;
502+ } ) ;
503+
504+ test ( 'should prioritize user-given headers' , ( ) => {
505+ // parameters
506+ const collectionId = 'fake_collectionId' ;
507+ const feature = 'fake_feature' ;
508+ const modelFormat = 'fake_modelFormat' ;
509+ const userAccept = 'fake/header' ;
510+ const userContentType = 'fake/header' ;
511+ const params = {
512+ collectionId,
513+ feature,
514+ modelFormat,
515+ headers : {
516+ Accept : userAccept ,
517+ 'Content-Type' : userContentType ,
518+ } ,
519+ } ;
520+
521+ visualRecognition . getModelFile ( params ) ;
522+ checkMediaHeaders ( createRequestMock , userAccept , userContentType ) ;
523+ } ) ;
524+ } ) ;
525+
526+ describe ( 'negative tests' , ( ) => {
527+ test ( 'should enforce required parameters' , async done => {
528+ // required parameters for this method
529+ const requiredParams = [ 'collectionId' , 'feature' , 'modelFormat' ] ;
530+
531+ let err ;
532+ try {
533+ await visualRecognition . getModelFile ( { } ) ;
534+ } catch ( e ) {
535+ err = e ;
536+ }
537+
538+ expect ( err . message ) . toMatch ( / M i s s i n g r e q u i r e d p a r a m e t e r s / ) ;
539+ done ( ) ;
540+ } ) ;
541+
542+ test ( 'should reject promise when required params are not given' , done => {
543+ // required parameters for this method
544+ const requiredParams = [ 'collectionId' , 'feature' , 'modelFormat' ] ;
545+
546+ const getModelFilePromise = visualRecognition . getModelFile ( ) ;
547+ expectToBePromise ( getModelFilePromise ) ;
548+
549+ getModelFilePromise . catch ( err => {
550+ expect ( err . message ) . toMatch ( / M i s s i n g r e q u i r e d p a r a m e t e r s / ) ;
551+ done ( ) ;
552+ } ) ;
553+ } ) ;
554+ } ) ;
555+ } ) ;
471556 describe ( 'addImages' , ( ) => {
472557 describe ( 'positive tests' , ( ) => {
473558 test ( 'should pass the right params to createRequest' , ( ) => {
0 commit comments