import * as protos from '../protos/protos' ; import * as assert from 'assert' ; import * as sinon from 'sinon' ; import { SinonStub } from 'sinon' ; import { describe , it } from 'mocha' ; import * as adaptationModule from '../src' ; import { PassThrough } from 'stream' ; import { protobuf } from 'google-gax' ; function generateSampleMessage < T extends object > ( instance ) { const filledObject = ( instance . constructor as typeof protobuf . Message ) . toObject ( instance as protobuf . Message < T > , { defaults : true } ) ; return ( instance . constructor as typeof protobuf . Message ) . fromObject ( filledObject ) as T ; } function stubSimpleCall < ResponseType > ( response ? , error ? ) { return error ? sinon . stub ( ) . rejects ( error ) : sinon . stub ( ) . resolves ( [ response ] ) ; } function stubSimpleCallWithCallback < ResponseType > ( response ? , error ? ) { return error ? sinon . stub ( ) . callsArgWith ( 2 , error ) : sinon . stub ( ) . callsArgWith ( 2 , null , response ) ; } function stubPageStreamingCall < ResponseType > ( responses ? , error ? ) { const pagingStub = sinon . stub ( ) ; if ( responses ) { for ( let i = 0 ; i < responses . length ; ++ i ) { pagingStub . onCall ( i ) . callsArgWith ( 2 , null , responses [ i ] ) ; } } const transformStub = error ? sinon . stub ( ) . callsArgWith ( 2 , error ) : pagingStub ; const mockStream = new PassThrough ( { objectMode : true , transform : transformStub , } ) ; if ( responses ) { for ( let i = 0 ; i < responses . length ; ++ i ) { setImmediate ( ( ) => { mockStream . write ( { } ) ; } ) ; } setImmediate ( ( ) => { mockStream . end ( ) ; } ) ; } else { setImmediate ( ( ) => { mockStream . write ( { } ) ; } ) ; setImmediate ( ( ) => { mockStream . end ( ) ; } ) ; } return sinon . stub ( ) . returns ( mockStream ) ; } function stubAsyncIterationCall < ResponseType > ( responses ? , error ? ) { let counter = 0 ; const asyncIterable = { [ Symbol . asyncIterator ] ( ) { return { async next ( ) { if ( error ) { return Promise . reject ( error ) ; } if ( counter >= responses ! . length ) { return Promise . resolve ( { done : true , value : undefined } ) ; } return Promise . resolve ( { done : false , value : responses ! [ counter ++ ] } ) ; } , } ; } , } ; return sinon . stub ( ) . returns ( asyncIterable ) ; } describe ( 'v1p1beta1.AdaptationClient' , ( ) => { it ( 'has servicePath' , ( ) => { const servicePath = adaptationModule . v1p1beta1 . AdaptationClient . servicePath ; assert ( servicePath ) ; } ) ; it ( 'has apiEndpoint' , ( ) => { const apiEndpoint = adaptationModule . v1p1beta1 . AdaptationClient . apiEndpoint ; assert ( apiEndpoint ) ; } ) ; it ( 'has port' , ( ) => { const port = adaptationModule . v1p1beta1 . AdaptationClient . port ; assert ( port ) ; assert ( typeof port === 'number' ) ; } ) ; it ( 'should create a client with no option' , ( ) => { const client = new adaptationModule . v1p1beta1 . AdaptationClient ( ) ; assert ( client ) ; } ) ; it ( 'should create a client with gRPC fallback' , ( ) => { const client = new adaptationModule . v1p1beta1 . AdaptationClient ( { fallback : true , } ) ; assert ( client ) ; } ) ; it ( 'has initialize method and supports deferred initialization' , async ( ) => { const client = new adaptationModule . v1p1beta1 . AdaptationClient ( { credentials : { client_email : 'bogus' , private_key : 'bogus' } , projectId : 'bogus' , } ) ; assert . strictEqual ( client . adaptationStub , undefined ) ; await client . initialize ( ) ; assert ( client . adaptationStub ) ; } ) ; it ( 'has close method' , ( ) => { const client = new adaptationModule . v1p1beta1 . AdaptationClient ( { credentials : { client_email : 'bogus' , private_key : 'bogus' } , projectId : 'bogus' , } ) ; client . close ( ) ; } ) ; it ( 'has getProjectId method' , async ( ) => { const fakeProjectId = 'fake-project-id' ; const client = new adaptationModule . v1p1beta1 . AdaptationClient ( { credentials : { client_email : 'bogus' , private_key : 'bogus' } , projectId : 'bogus' , } ) ; client . auth . getProjectId = sinon . stub ( ) . resolves ( fakeProjectId ) ; const result = await client . getProjectId ( ) ; assert . strictEqual ( result , fakeProjectId ) ; assert ( ( client . auth . getProjectId as SinonStub ) . calledWithExactly ( ) ) ; } ) ; it ( 'has getProjectId method with callback' , async ( ) => { const fakeProjectId = 'fake-project-id' ; const client = new adaptationModule . v1p1beta1 . AdaptationClient ( { credentials : { client_email : 'bogus' , private_key : 'bogus' } , projectId : 'bogus' , } ) ; client . auth . getProjectId = sinon . stub ( ) . callsArgWith ( 0 , null , fakeProjectId ) ; const promise = new Promise ( ( resolve , reject ) => { client . getProjectId ( ( err ? , projectId ? ) => { if ( err ) { reject ( err ) ; } else { resolve ( projectId ) ; } } ) ; } ) ; const result = await promise ; assert . strictEqual ( result , fakeProjectId ) ; } ) ; describe ( 'createPhraseSet' , ( ) => { it ( 'invokes createPhraseSet without error' , async ( ) => { const client = new adaptationModule . v1p1beta1 . AdaptationClient ( { credentials : { client_email : 'bogus' , private_key : 'bogus' } , projectId : 'bogus' , } ) ; client . initialize ( ) ; const request = generateSampleMessage ( new protos . google . cloud . speech . v1p1beta1 . CreatePhraseSetRequest ( ) ) ; request . parent = '' ; const expectedHeaderRequestParams = 'parent=' ; const expectedOptions = { otherArgs : { headers : { 'x-goog-request-params' : expectedHeaderRequestParams , } , } , } ; const expectedResponse = generateSampleMessage ( new protos . google . cloud . speech . v1p1beta1 . PhraseSet ( ) ) ; client . innerApiCalls . createPhraseSet = stubSimpleCall ( expectedResponse ) ; const [ response ] = await client . createPhraseSet ( request ) ; assert . deepStrictEqual ( response , expectedResponse ) ; assert ( ( client . innerApiCalls . createPhraseSet as SinonStub ) . getCall ( 0 ) . calledWith ( request , expectedOptions , undefined ) ) ; } ) ; it ( 'invokes createPhraseSet without error using callback' , async ( ) => { const client = new adaptationModule . v1p1beta1 . AdaptationClient ( { credentials : { client_email : 'bogus' , private_key : 'bogus' } , projectId : 'bogus' , } ) ; client . initialize ( ) ; const request = generateSampleMessage ( new protos . google . cloud . speech . v1p1beta1 . CreatePhraseSetRequest ( ) ) ; request . parent = '' ; const expectedHeaderRequestParams = 'parent=' ; const expectedOptions = { otherArgs : { headers : { 'x-goog-request-params' : expectedHeaderRequestParams , } , } , } ; const expectedResponse = generateSampleMessage ( new protos . google . cloud . speech . v1p1beta1 . PhraseSet ( ) ) ; client . innerApiCalls . createPhraseSet = stubSimpleCallWithCallback ( expectedResponse ) ; const promise = new Promise ( ( resolve , reject ) => { client . createPhraseSet ( request , ( err ? , result ? ) => { if ( err ) { reject ( err ) ; } else { resolve ( result ) ; } } ) ; } ) ; const response = await promise ; assert . deepStrictEqual ( response , expectedResponse ) ; assert ( ( client . innerApiCalls . createPhraseSet as SinonStub ) . getCall ( 0 ) . calledWith ( request , expectedOptions ) ) ; } ) ; it ( 'invokes createPhraseSet with error' , async ( ) => { const client = new adaptationModule . v1p1beta1 . AdaptationClient ( { credentials : { client_email : 'bogus' , private_key : 'bogus' } , projectId : 'bogus' , } ) ; client . initialize ( ) ; const request = generateSampleMessage ( new protos . google . cloud . speech . v1p1beta1 . CreatePhraseSetRequest ( ) ) ; request . parent = '' ; const expectedHeaderRequestParams = 'parent=' ; const expectedOptions = { otherArgs : { headers : { 'x-goog-request-params' : expectedHeaderRequestParams , } , } , } ; const expectedError = new Error ( 'expected' ) ; client . innerApiCalls . createPhraseSet = stubSimpleCall ( undefined , expectedError ) ; await assert . rejects ( client . createPhraseSet ( request ) , expectedError ) ; assert ( ( client . innerApiCalls . createPhraseSet as SinonStub ) . getCall ( 0 ) . calledWith ( request , expectedOptions , undefined ) ) ; } ) ; } ) ; describe ( 'getPhraseSet' , ( ) => { it ( 'invokes getPhraseSet without error' , async ( ) => { const client = new adaptationModule . v1p1beta1 . AdaptationClient ( { credentials : { client_email : 'bogus' , private_key : 'bogus' } , projectId : 'bogus' , } ) ; client . initialize ( ) ; const request = generateSampleMessage ( new protos . google . cloud . speech . v1p1beta1 . GetPhraseSetRequest ( ) ) ; request . name = '' ; const expectedHeaderRequestParams = 'name=' ; const expectedOptions = { otherArgs : { headers : { 'x-goog-request-params' : expectedHeaderRequestParams , } , } , } ; const expectedResponse = generateSampleMessage ( new protos . google . cloud . speech . v1p1beta1 . PhraseSet ( ) ) ; client . innerApiCalls . getPhraseSet = stubSimpleCall ( expectedResponse ) ; const [ response ] = await client . getPhraseSet ( request ) ; assert . deepStrictEqual ( response , expectedResponse ) ; assert ( ( client . innerApiCalls . getPhraseSet as SinonStub ) . getCall ( 0 ) . calledWith ( request , expectedOptions , undefined ) ) ; } ) ; it ( 'invokes getPhraseSet without error using callback' , async ( ) => { const client = new adaptationModule . v1p1beta1 . AdaptationClient ( { credentials : { client_email : 'bogus' , private_key : 'bogus' } , projectId : 'bogus' , } ) ; client . initialize ( ) ; const request = generateSampleMessage ( new protos . google . cloud . speech . v1p1beta1 . GetPhraseSetRequest ( ) ) ; request . name = '' ; const expectedHeaderRequestParams = 'name=' ; const expectedOptions = { otherArgs : { headers : { 'x-goog-request-params' : expectedHeaderRequestParams , } , } , } ; const expectedResponse = generateSampleMessage ( new protos . google . cloud . speech . v1p1beta1 . PhraseSet ( ) ) ; client . innerApiCalls . getPhraseSet = stubSimpleCallWithCallback ( expectedResponse ) ; const promise = new Promise ( ( resolve , reject ) => { client . getPhraseSet ( request , ( err ? , result ? ) => { if ( err ) { reject ( err ) ; } else { resolve ( result ) ; } } ) ; } ) ; const response = await promise ; assert . deepStrictEqual ( response , expectedResponse ) ; assert ( ( client . innerApiCalls . getPhraseSet as SinonStub ) . getCall ( 0 ) . calledWith ( request , expectedOptions ) ) ; } ) ; it ( 'invokes getPhraseSet with error' , async ( ) => { const client = new adaptationModule . v1p1beta1 . AdaptationClient ( { credentials : { client_email : 'bogus' , private_key : 'bogus' } , projectId : 'bogus' , } ) ; client . initialize ( ) ; const request = generateSampleMessage ( new protos . google . cloud . speech . v1p1beta1 . GetPhraseSetRequest ( ) ) ; request . name = '' ; const expectedHeaderRequestParams = 'name=' ; const expectedOptions = { otherArgs : { headers : { 'x-goog-request-params' : expectedHeaderRequestParams , } , } , } ; const expectedError = new Error ( 'expected' ) ; client . innerApiCalls . getPhraseSet = stubSimpleCall ( undefined , expectedError ) ; await assert . rejects ( client . getPhraseSet ( request ) , expectedError ) ; assert ( ( client . innerApiCalls . getPhraseSet as SinonStub ) . getCall ( 0 ) . calledWith ( request , expectedOptions , undefined ) ) ; } ) ; } ) ; describe ( 'updatePhraseSet' , ( ) => { it ( 'invokes updatePhraseSet without error' , async ( ) => { const client = new adaptationModule . v1p1beta1 . AdaptationClient ( { credentials : { client_email : 'bogus' , private_key : 'bogus' } , projectId : 'bogus' , } ) ; client . initialize ( ) ; const request = generateSampleMessage ( new protos . google . cloud . speech . v1p1beta1 . UpdatePhraseSetRequest ( ) ) ; request . phraseSet = { } ; request . phraseSet . name = '' ; const expectedHeaderRequestParams = 'phrase_set.name=' ; const expectedOptions = { otherArgs : { headers : { 'x-goog-request-params' : expectedHeaderRequestParams , } , } , } ; const expectedResponse = generateSampleMessage ( new protos . google . cloud . speech . v1p1beta1 . PhraseSet ( ) ) ; client . innerApiCalls . updatePhraseSet = stubSimpleCall ( expectedResponse ) ; const [ response ] = await client . updatePhraseSet ( request ) ; assert . deepStrictEqual ( response , expectedResponse ) ; assert ( ( client . innerApiCalls . updatePhraseSet as SinonStub ) . getCall ( 0 ) . calledWith ( request , expectedOptions , undefined ) ) ; } ) ; it ( 'invokes updatePhraseSet without error using callback' , async ( ) => { const client = new adaptationModule . v1p1beta1 . AdaptationClient ( { credentials : { client_email : 'bogus' , private_key : 'bogus' } , projectId : 'bogus' , } ) ; client . initialize ( ) ; const request = generateSampleMessage ( new protos . google . cloud . speech . v1p1beta1 . UpdatePhraseSetRequest ( ) ) ; request . phraseSet = { } ; request . phraseSet . name = '' ; const expectedHeaderRequestParams = 'phrase_set.name=' ; const expectedOptions = { otherArgs : { headers : { 'x-goog-request-params' : expectedHeaderRequestParams , } , } , } ; const expectedResponse = generateSampleMessage ( new protos . google . cloud . speech . v1p1beta1 . PhraseSet ( ) ) ; client . innerApiCalls . updatePhraseSet = stubSimpleCallWithCallback ( expectedResponse ) ; const promise = new Promise ( ( resolve , reject ) => { client . updatePhraseSet ( request , ( err ? , result ? ) => { if ( err ) { reject ( err ) ; } else { resolve ( result ) ; } } ) ; } ) ; const response = await promise ; assert . deepStrictEqual ( response , expectedResponse ) ; assert ( ( client . innerApiCalls . updatePhraseSet as SinonStub ) . getCall ( 0 ) . calledWith ( request , expectedOptions ) ) ; } ) ; it ( 'invokes updatePhraseSet with error' , async ( ) => { const client = new adaptationModule . v1p1beta1 . AdaptationClient ( { credentials : { client_email : 'bogus' , private_key : 'bogus' } , projectId : 'bogus' , } ) ; client . initialize ( ) ; const request = generateSampleMessage ( new protos . google . cloud . speech . v1p1beta1 . UpdatePhraseSetRequest ( ) ) ; request . phraseSet = { } ; request . phraseSet . name = '' ; const expectedHeaderRequestParams = 'phrase_set.name=' ; const expectedOptions = { otherArgs : { headers : { 'x-goog-request-params' : expectedHeaderRequestParams , } , } , } ; const expectedError = new Error ( 'expected' ) ; client . innerApiCalls . updatePhraseSet = stubSimpleCall ( undefined , expectedError ) ; await assert . rejects ( client . updatePhraseSet ( request ) , expectedError ) ; assert ( ( client . innerApiCalls . updatePhraseSet as SinonStub ) . getCall ( 0 ) . calledWith ( request , expectedOptions , undefined ) ) ; } ) ; } ) ; describe ( 'deletePhraseSet' , ( ) => { it ( 'invokes deletePhraseSet without error' , async ( ) => { const client = new adaptationModule . v1p1beta1 . AdaptationClient ( { credentials : { client_email : 'bogus' , private_key : 'bogus' } , projectId : 'bogus' , } ) ; client . initialize ( ) ; const request = generateSampleMessage ( new protos . google . cloud . speech . v1p1beta1 . DeletePhraseSetRequest ( ) ) ; request . name = '' ; const expectedHeaderRequestParams = 'name=' ; const expectedOptions = { otherArgs : { headers : { 'x-goog-request-params' : expectedHeaderRequestParams , } , } , } ; const expectedResponse = generateSampleMessage ( new protos . google . protobuf . Empty ( ) ) ; client . innerApiCalls . deletePhraseSet = stubSimpleCall ( expectedResponse ) ; const [ response ] = await client . deletePhraseSet ( request ) ; assert . deepStrictEqual ( response , expectedResponse ) ; assert ( ( client . innerApiCalls . deletePhraseSet as SinonStub ) . getCall ( 0 ) . calledWith ( request , expectedOptions , undefined ) ) ; } ) ; it ( 'invokes deletePhraseSet without error using callback' , async ( ) => { const client = new adaptationModule . v1p1beta1 . AdaptationClient ( { credentials : { client_email : 'bogus' , private_key : 'bogus' } , projectId : 'bogus' , } ) ; client . initialize ( ) ; const request = generateSampleMessage ( new protos . google . cloud . speech . v1p1beta1 . DeletePhraseSetRequest ( ) ) ; request . name = '' ; const expectedHeaderRequestParams = 'name=' ; const expectedOptions = { otherArgs : { headers : { 'x-goog-request-params' : expectedHeaderRequestParams , } , } , } ; const expectedResponse = generateSampleMessage ( new protos . google . protobuf . Empty ( ) ) ; client . innerApiCalls . deletePhraseSet = stubSimpleCallWithCallback ( expectedResponse ) ; const promise = new Promise ( ( resolve , reject ) => { client . deletePhraseSet ( request , ( err ? , result ? ) => { if ( err ) { reject ( err ) ; } else { resolve ( result ) ; } } ) ; } ) ; const response = await promise ; assert . deepStrictEqual ( response , expectedResponse ) ; assert ( ( client . innerApiCalls . deletePhraseSet as SinonStub ) . getCall ( 0 ) . calledWith ( request , expectedOptions ) ) ; } ) ; it ( 'invokes deletePhraseSet with error' , async ( ) => { const client = new adaptationModule . v1p1beta1 . AdaptationClient ( { credentials : { client_email : 'bogus' , private_key : 'bogus' } , projectId : 'bogus' , } ) ; client . initialize ( ) ; const request = generateSampleMessage ( new protos . google . cloud . speech . v1p1beta1 . DeletePhraseSetRequest ( ) ) ; request . name = '' ; const expectedHeaderRequestParams = 'name=' ; const expectedOptions = { otherArgs : { headers : { 'x-goog-request-params' : expectedHeaderRequestParams , } , } , } ; const expectedError = new Error ( 'expected' ) ; client . innerApiCalls . deletePhraseSet = stubSimpleCall ( undefined , expectedError ) ; await assert . rejects ( client . deletePhraseSet ( request ) , expectedError ) ; assert ( ( client . innerApiCalls . deletePhraseSet as SinonStub ) . getCall ( 0 ) . calledWith ( request , expectedOptions , undefined ) ) ; } ) ; } ) ; describe ( 'createCustomClass' , ( ) => { it ( 'invokes createCustomClass without error' , async ( ) => { const client = new adaptationModule . v1p1beta1 . AdaptationClient ( { credentials : { client_email : 'bogus' , private_key : 'bogus' } , projectId : 'bogus' , } ) ; client . initialize ( ) ; const request = generateSampleMessage ( new protos . google . cloud . speech . v1p1beta1 . CreateCustomClassRequest ( ) ) ; request . parent = '' ; const expectedHeaderRequestParams = 'parent=' ; const expectedOptions = { otherArgs : { headers : { 'x-goog-request-params' : expectedHeaderRequestParams , } , } , } ; const expectedResponse = generateSampleMessage ( new protos . google . cloud . speech . v1p1beta1 . CustomClass ( ) ) ; client . innerApiCalls . createCustomClass = stubSimpleCall ( expectedResponse ) ; const [ response ] = await client . createCustomClass ( request ) ; assert . deepStrictEqual ( response , expectedResponse ) ; assert ( ( client . innerApiCalls . createCustomClass as SinonStub ) . getCall ( 0 ) . calledWith ( request , expectedOptions , undefined ) ) ; } ) ; it ( 'invokes createCustomClass without error using callback' , async ( ) => { const client = new adaptationModule . v1p1beta1 . AdaptationClient ( { credentials : { client_email : 'bogus' , private_key : 'bogus' } , projectId : 'bogus' , } ) ; client . initialize ( ) ; const request = generateSampleMessage ( new protos . google . cloud . speech . v1p1beta1 . CreateCustomClassRequest ( ) ) ; request . parent = '' ; const expectedHeaderRequestParams = 'parent=' ; const expectedOptions = { otherArgs : { headers : { 'x-goog-request-params' : expectedHeaderRequestParams , } , } , } ; const expectedResponse = generateSampleMessage ( new protos . google . cloud . speech . v1p1beta1 . CustomClass ( ) ) ; client . innerApiCalls . createCustomClass = stubSimpleCallWithCallback ( expectedResponse ) ; const promise = new Promise ( ( resolve , reject ) => { client . createCustomClass ( request , ( err ? , result ? ) => { if ( err ) { reject ( err ) ; } else { resolve ( result ) ; } } ) ; } ) ; const response = await promise ; assert . deepStrictEqual ( response , expectedResponse ) ; assert ( ( client . innerApiCalls . createCustomClass as SinonStub ) . getCall ( 0 ) . calledWith ( request , expectedOptions ) ) ; } ) ; it ( 'invokes createCustomClass with error' , async ( ) => { const client = new adaptationModule . v1p1beta1 . AdaptationClient ( { credentials : { client_email : 'bogus' , private_key : 'bogus' } , projectId : 'bogus' , } ) ; client . initialize ( ) ; const request = generateSampleMessage ( new protos . google . cloud . speech . v1p1beta1 . CreateCustomClassRequest ( ) ) ; request . parent = '' ; const expectedHeaderRequestParams = 'parent=' ; const expectedOptions = { otherArgs : { headers : { 'x-goog-request-params' : expectedHeaderRequestParams , } , } , } ; const expectedError = new Error ( 'expected' ) ; client . innerApiCalls . createCustomClass = stubSimpleCall ( undefined , expectedError ) ; await assert . rejects ( client . createCustomClass ( request ) , expectedError ) ; assert ( ( client . innerApiCalls . createCustomClass as SinonStub ) . getCall ( 0 ) . calledWith ( request , expectedOptions , undefined ) ) ; } ) ; } ) ; describe ( 'getCustomClass' , ( ) => { it ( 'invokes getCustomClass without error' , async ( ) => { const client = new adaptationModule . v1p1beta1 . AdaptationClient ( { credentials : { client_email : 'bogus' , private_key : 'bogus' } , projectId : 'bogus' , } ) ; client . initialize ( ) ; const request = generateSampleMessage ( new protos . google . cloud . speech . v1p1beta1 . GetCustomClassRequest ( ) ) ; request . name = '' ; const expectedHeaderRequestParams = 'name=' ; const expectedOptions = { otherArgs : { headers : { 'x-goog-request-params' : expectedHeaderRequestParams , } , } , } ; const expectedResponse = generateSampleMessage ( new protos . google . cloud . speech . v1p1beta1 . CustomClass ( ) ) ; client . innerApiCalls . getCustomClass = stubSimpleCall ( expectedResponse ) ; const [ response ] = await client . getCustomClass ( request ) ; assert . deepStrictEqual ( response , expectedResponse ) ; assert ( ( client . innerApiCalls . getCustomClass as SinonStub ) . getCall ( 0 ) . calledWith ( request , expectedOptions , undefined ) ) ; } ) ; it ( 'invokes getCustomClass without error using callback' , async ( ) => { const client = new adaptationModule . v1p1beta1 . AdaptationClient ( { credentials : { client_email : 'bogus' , private_key : 'bogus' } , projectId : 'bogus' , } ) ; client . initialize ( ) ; const request = generateSampleMessage ( new protos . google . cloud . speech . v1p1beta1 . GetCustomClassRequest ( ) ) ; request . name = '' ; const expectedHeaderRequestParams = 'name=' ; const expectedOptions = { otherArgs : { headers : { 'x-goog-request-params' : expectedHeaderRequestParams , } , } , } ; const expectedResponse = generateSampleMessage ( new protos . google . cloud . speech . v1p1beta1 . CustomClass ( ) ) ; client . innerApiCalls . getCustomClass = stubSimpleCallWithCallback ( expectedResponse ) ; const promise = new Promise ( ( resolve , reject ) => { client . getCustomClass ( request , ( err ? , result ? ) => { if ( err ) { reject ( err ) ; } else { resolve ( result ) ; } } ) ; } ) ; const response = await promise ; assert . deepStrictEqual ( response , expectedResponse ) ; assert ( ( client . innerApiCalls . getCustomClass as SinonStub ) . getCall ( 0 ) . calledWith ( request , expectedOptions ) ) ; } ) ; it ( 'invokes getCustomClass with error' , async ( ) => { const client = new adaptationModule . v1p1beta1 . AdaptationClient ( { credentials : { client_email : 'bogus' , private_key : 'bogus' } , projectId : 'bogus' , } ) ; client . initialize ( ) ; const request = generateSampleMessage ( new protos . google . cloud . speech . v1p1beta1 . GetCustomClassRequest ( ) ) ; request . name = '' ; const expectedHeaderRequestParams = 'name=' ; const expectedOptions = { otherArgs : { headers : { 'x-goog-request-params' : expectedHeaderRequestParams , } , } , } ; const expectedError = new Error ( 'expected' ) ; client . innerApiCalls . getCustomClass = stubSimpleCall ( undefined , expectedError ) ; await assert . rejects ( client . getCustomClass ( request ) , expectedError ) ; assert ( ( client . innerApiCalls . getCustomClass as SinonStub ) . getCall ( 0 ) . calledWith ( request , expectedOptions , undefined ) ) ; } ) ; } ) ; describe ( 'updateCustomClass' , ( ) => { it ( 'invokes updateCustomClass without error' , async ( ) => { const client = new adaptationModule . v1p1beta1 . AdaptationClient ( { credentials : { client_email : 'bogus' , private_key : 'bogus' } , projectId : 'bogus' , } ) ; client . initialize ( ) ; const request = generateSampleMessage ( new protos . google . cloud . speech . v1p1beta1 . UpdateCustomClassRequest ( ) ) ; request . customClass = { } ; request . customClass . name = '' ; const expectedHeaderRequestParams = 'custom_class.name=' ; const expectedOptions = { otherArgs : { headers : { 'x-goog-request-params' : expectedHeaderRequestParams , } , } , } ; const expectedResponse = generateSampleMessage ( new protos . google . cloud . speech . v1p1beta1 . CustomClass ( ) ) ; client . innerApiCalls . updateCustomClass = stubSimpleCall ( expectedResponse ) ; const [ response ] = await client . updateCustomClass ( request ) ; assert . deepStrictEqual ( response , expectedResponse ) ; assert ( ( client . innerApiCalls . updateCustomClass as SinonStub ) . getCall ( 0 ) . calledWith ( request , expectedOptions , undefined ) ) ; } ) ; it ( 'invokes updateCustomClass without error using callback' , async ( ) => { const client = new adaptationModule . v1p1beta1 . AdaptationClient ( { credentials : { client_email : 'bogus' , private_key : 'bogus' } , projectId : 'bogus' , } ) ; client . initialize ( ) ; const request = generateSampleMessage ( new protos . google . cloud . speech . v1p1beta1 . UpdateCustomClassRequest ( ) ) ; request . customClass = { } ; request . customClass . name = '' ; const expectedHeaderRequestParams = 'custom_class.name=' ; const expectedOptions = { otherArgs : { headers : { 'x-goog-request-params' : expectedHeaderRequestParams , } , } , } ; const expectedResponse = generateSampleMessage ( new protos . google . cloud . speech . v1p1beta1 . CustomClass ( ) ) ; client . innerApiCalls . updateCustomClass = stubSimpleCallWithCallback ( expectedResponse ) ; const promise = new Promise ( ( resolve , reject ) => { client . updateCustomClass ( request , ( err ? , result ? ) => { if ( err ) { reject ( err ) ; } else { resolve ( result ) ; } } ) ; } ) ; const response = await promise ; assert . deepStrictEqual ( response , expectedResponse ) ; assert ( ( client . innerApiCalls . updateCustomClass as SinonStub ) . getCall ( 0 ) . calledWith ( request , expectedOptions ) ) ; } ) ; it ( 'invokes updateCustomClass with error' , async ( ) => { const client = new adaptationModule . v1p1beta1 . AdaptationClient ( { credentials : { client_email : 'bogus' , private_key : 'bogus' } , projectId : 'bogus' , } ) ; client . initialize ( ) ; const request = generateSampleMessage ( new protos . google . cloud . speech . v1p1beta1 . UpdateCustomClassRequest ( ) ) ; request . customClass = { } ; request . customClass . name = '' ; const expectedHeaderRequestParams = 'custom_class.name=' ; const expectedOptions = { otherArgs : { headers : { 'x-goog-request-params' : expectedHeaderRequestParams , } , } , } ; const expectedError = new Error ( 'expected' ) ; client . innerApiCalls . updateCustomClass = stubSimpleCall ( undefined , expectedError ) ; await assert . rejects ( client . updateCustomClass ( request ) , expectedError ) ; assert ( ( client . innerApiCalls . updateCustomClass as SinonStub ) . getCall ( 0 ) . calledWith ( request , expectedOptions , undefined ) ) ; } ) ; } ) ; describe ( 'deleteCustomClass' , ( ) => { it ( 'invokes deleteCustomClass without error' , async ( ) => { const client = new adaptationModule . v1p1beta1 . AdaptationClient ( { credentials : { client_email : 'bogus' , private_key : 'bogus' } , projectId : 'bogus' , } ) ; client . initialize ( ) ; const request = generateSampleMessage ( new protos . google . cloud . speech . v1p1beta1 . DeleteCustomClassRequest ( ) ) ; request . name = '' ; const expectedHeaderRequestParams = 'name=' ; const expectedOptions = { otherArgs : { headers : { 'x-goog-request-params' : expectedHeaderRequestParams , } , } , } ; const expectedResponse = generateSampleMessage ( new protos . google . protobuf . Empty ( ) ) ; client . innerApiCalls . deleteCustomClass = stubSimpleCall ( expectedResponse ) ; const [ response ] = await client . deleteCustomClass ( request ) ; assert . deepStrictEqual ( response , expectedResponse ) ; assert ( ( client . innerApiCalls . deleteCustomClass as SinonStub ) . getCall ( 0 ) . calledWith ( request , expectedOptions , undefined ) ) ; } ) ; it ( 'invokes deleteCustomClass without error using callback' , async ( ) => { const client = new adaptationModule . v1p1beta1 . AdaptationClient ( { credentials : { client_email : 'bogus' , private_key : 'bogus' } , projectId : 'bogus' , } ) ; client . initialize ( ) ; const request = generateSampleMessage ( new protos . google . cloud . speech . v1p1beta1 . DeleteCustomClassRequest ( ) ) ; request . name = '' ; const expectedHeaderRequestParams = 'name=' ; const expectedOptions = { otherArgs : { headers : { 'x-goog-request-params' : expectedHeaderRequestParams , } , } , } ; const expectedResponse = generateSampleMessage ( new protos . google . protobuf . Empty ( ) ) ; client . innerApiCalls . deleteCustomClass = stubSimpleCallWithCallback ( expectedResponse ) ; const promise = new Promise ( ( resolve , reject ) => { client . deleteCustomClass ( request , ( err ? , result ? ) => { if ( err ) { reject ( err ) ; } else { resolve ( result ) ; } } ) ; } ) ; const response = await promise ; assert . deepStrictEqual ( response , expectedResponse ) ; assert ( ( client . innerApiCalls . deleteCustomClass as SinonStub ) . getCall ( 0 ) . calledWith ( request , expectedOptions ) ) ; } ) ; it ( 'invokes deleteCustomClass with error' , async ( ) => { const client = new adaptationModule . v1p1beta1 . AdaptationClient ( { credentials : { client_email : 'bogus' , private_key : 'bogus' } , projectId : 'bogus' , } ) ; client . initialize ( ) ; const request = generateSampleMessage ( new protos . google . cloud . speech . v1p1beta1 . DeleteCustomClassRequest ( ) ) ; request . name = '' ; const expectedHeaderRequestParams = 'name=' ; const expectedOptions = { otherArgs : { headers : { 'x-goog-request-params' : expectedHeaderRequestParams , } , } , } ; const expectedError = new Error ( 'expected' ) ; client . innerApiCalls . deleteCustomClass = stubSimpleCall ( undefined , expectedError ) ; await assert . rejects ( client . deleteCustomClass ( request ) , expectedError ) ; assert ( ( client . innerApiCalls . deleteCustomClass as SinonStub ) . getCall ( 0 ) . calledWith ( request , expectedOptions , undefined ) ) ; } ) ; } ) ; describe ( 'listPhraseSet' , ( ) => { it ( 'invokes listPhraseSet without error' , async ( ) => { const client = new adaptationModule . v1p1beta1 . AdaptationClient ( { credentials : { client_email : 'bogus' , private_key : 'bogus' } , projectId : 'bogus' , } ) ; client . initialize ( ) ; const request = generateSampleMessage ( new protos . google . cloud . speech . v1p1beta1 . ListPhraseSetRequest ( ) ) ; request . parent = '' ; const expectedHeaderRequestParams = 'parent=' ; const expectedOptions = { otherArgs : { headers : { 'x-goog-request-params' : expectedHeaderRequestParams , } , } , } ; const expectedResponse = [ generateSampleMessage ( new protos . google . cloud . speech . v1p1beta1 . PhraseSet ( ) ) , generateSampleMessage ( new protos . google . cloud . speech . v1p1beta1 . PhraseSet ( ) ) , generateSampleMessage ( new protos . google . cloud . speech . v1p1beta1 . PhraseSet ( ) ) , ] ; client . innerApiCalls . listPhraseSet = stubSimpleCall ( expectedResponse ) ; const [ response ] = await client . listPhraseSet ( request ) ; assert . deepStrictEqual ( response , expectedResponse ) ; assert ( ( client . innerApiCalls . listPhraseSet as SinonStub ) . getCall ( 0 ) . calledWith ( request , expectedOptions , undefined ) ) ; } ) ; it ( 'invokes listPhraseSet without error using callback' , async ( ) => { const client = new adaptationModule . v1p1beta1 . AdaptationClient ( { credentials : { client_email : 'bogus' , private_key : 'bogus' } , projectId : 'bogus' , } ) ; client . initialize ( ) ; const request = generateSampleMessage ( new protos . google . cloud . speech . v1p1beta1 . ListPhraseSetRequest ( ) ) ; request . parent = '' ; const expectedHeaderRequestParams = 'parent=' ; const expectedOptions = { otherArgs : { headers : { 'x-goog-request-params' : expectedHeaderRequestParams , } , } , } ; const expectedResponse = [ generateSampleMessage ( new protos . google . cloud . speech . v1p1beta1 . PhraseSet ( ) ) , generateSampleMessage ( new protos . google . cloud . speech . v1p1beta1 . PhraseSet ( ) ) , generateSampleMessage ( new protos . google . cloud . speech . v1p1beta1 . PhraseSet ( ) ) , ] ; client . innerApiCalls . listPhraseSet = stubSimpleCallWithCallback ( expectedResponse ) ; const promise = new Promise ( ( resolve , reject ) => { client . listPhraseSet ( request , ( err ? , result ? ) => { if ( err ) { reject ( err ) ; } else { resolve ( result ) ; } } ) ; } ) ; const response = await promise ; assert . deepStrictEqual ( response , expectedResponse ) ; assert ( ( client . innerApiCalls . listPhraseSet as SinonStub ) . getCall ( 0 ) . calledWith ( request , expectedOptions ) ) ; } ) ; it ( 'invokes listPhraseSet with error' , async ( ) => { const client = new adaptationModule . v1p1beta1 . AdaptationClient ( { credentials : { client_email : 'bogus' , private_key : 'bogus' } , projectId : 'bogus' , } ) ; client . initialize ( ) ; const request = generateSampleMessage ( new protos . google . cloud . speech . v1p1beta1 . ListPhraseSetRequest ( ) ) ; request . parent = '' ; const expectedHeaderRequestParams = 'parent=' ; const expectedOptions = { otherArgs : { headers : { 'x-goog-request-params' : expectedHeaderRequestParams , } , } , } ; const expectedError = new Error ( 'expected' ) ; client . innerApiCalls . listPhraseSet = stubSimpleCall ( undefined , expectedError ) ; await assert . rejects ( client . listPhraseSet ( request ) , expectedError ) ; assert ( ( client . innerApiCalls . listPhraseSet as SinonStub ) . getCall ( 0 ) . calledWith ( request , expectedOptions , undefined ) ) ; } ) ; it ( 'invokes listPhraseSetStream without error' , async ( ) => { const client = new adaptationModule . v1p1beta1 . AdaptationClient ( { credentials : { client_email : 'bogus' , private_key : 'bogus' } , projectId : 'bogus' , } ) ; client . initialize ( ) ; const request = generateSampleMessage ( new protos . google . cloud . speech . v1p1beta1 . ListPhraseSetRequest ( ) ) ; request . parent = '' ; const expectedHeaderRequestParams = 'parent=' ; const expectedResponse = [ generateSampleMessage ( new protos . google . cloud . speech . v1p1beta1 . PhraseSet ( ) ) , generateSampleMessage ( new protos . google . cloud . speech . v1p1beta1 . PhraseSet ( ) ) , generateSampleMessage ( new protos . google . cloud . speech . v1p1beta1 . PhraseSet ( ) ) , ] ; client . descriptors . page . listPhraseSet . createStream = stubPageStreamingCall ( expectedResponse ) ; const stream = client . listPhraseSetStream ( request ) ; const promise = new Promise ( ( resolve , reject ) => { const responses = [ ] ; stream . on ( 'data' , ( response ) => { responses . push ( response ) ; } ) ; stream . on ( 'end' , ( ) => { resolve ( responses ) ; } ) ; stream . on ( 'error' , ( err ) => { reject ( err ) ; } ) ; } ) ; const responses = await promise ; assert . deepStrictEqual ( responses , expectedResponse ) ; assert ( ( client . descriptors . page . listPhraseSet . createStream as SinonStub ) . getCall ( 0 ) . calledWith ( client . innerApiCalls . listPhraseSet , request ) ) ; assert . strictEqual ( ( client . descriptors . page . listPhraseSet . createStream as SinonStub ) . getCall ( 0 ) . args [ 2 ] . otherArgs . headers [ 'x-goog-request-params' ] , expectedHeaderRequestParams ) ; } ) ; it ( 'invokes listPhraseSetStream with error' , async ( ) => { const client = new adaptationModule . v1p1beta1 . AdaptationClient ( { credentials : { client_email : 'bogus' , private_key : 'bogus' } , projectId : 'bogus' , } ) ; client . initialize ( ) ; const request = generateSampleMessage ( new protos . google . cloud . speech . v1p1beta1 . ListPhraseSetRequest ( ) ) ; request . parent = '' ; const expectedHeaderRequestParams = 'parent=' ; const expectedError = new Error ( 'expected' ) ; client . descriptors . page . listPhraseSet . createStream = stubPageStreamingCall ( undefined , expectedError ) ; const stream = client . listPhraseSetStream ( request ) ; const promise = new Promise ( ( resolve , reject ) => { const responses = [ ] ; stream . on ( 'data' , ( response ) => { responses . push ( response ) ; } ) ; stream . on ( 'end' , ( ) => { resolve ( responses ) ; } ) ; stream . on ( 'error' , ( err ) => { reject ( err ) ; } ) ; } ) ; await assert . rejects ( promise , expectedError ) ; assert ( ( client . descriptors . page . listPhraseSet . createStream as SinonStub ) . getCall ( 0 ) . calledWith ( client . innerApiCalls . listPhraseSet , request ) ) ; assert . strictEqual ( ( client . descriptors . page . listPhraseSet . createStream as SinonStub ) . getCall ( 0 ) . args [ 2 ] . otherArgs . headers [ 'x-goog-request-params' ] , expectedHeaderRequestParams ) ; } ) ; it ( 'uses async iteration with listPhraseSet without error' , async ( ) => { const client = new adaptationModule . v1p1beta1 . AdaptationClient ( { credentials : { client_email : 'bogus' , private_key : 'bogus' } , projectId : 'bogus' , } ) ; client . initialize ( ) ; const request = generateSampleMessage ( new protos . google . cloud . speech . v1p1beta1 . ListPhraseSetRequest ( ) ) ; request . parent = '' ; const expectedHeaderRequestParams = 'parent=' ; const expectedResponse = [ generateSampleMessage ( new protos . google . cloud . speech . v1p1beta1 . PhraseSet ( ) ) , generateSampleMessage ( new protos . google . cloud . speech . v1p1beta1 . PhraseSet ( ) ) , generateSampleMessage ( new protos . google . cloud . speech . v1p1beta1 . PhraseSet ( ) ) , ] ; client . descriptors . page . listPhraseSet . asyncIterate = stubAsyncIterationCall ( expectedResponse ) ; const responses = [ ] ; const iterable = client . listPhraseSetAsync ( request ) ; for await ( const resource of iterable ) { responses . push ( resource ! ) ; } assert . deepStrictEqual ( responses , expectedResponse ) ; assert . deepStrictEqual ( ( client . descriptors . page . listPhraseSet . asyncIterate as SinonStub ) . getCall ( 0 ) . args [ 1 ] , request ) ; assert . strictEqual ( ( client . descriptors . page . listPhraseSet . asyncIterate as SinonStub ) . getCall ( 0 ) . args [ 2 ] . otherArgs . headers [ 'x-goog-request-params' ] , expectedHeaderRequestParams ) ; } ) ; it ( 'uses async iteration with listPhraseSet with error' , async ( ) => { const client = new adaptationModule . v1p1beta1 . AdaptationClient ( { credentials : { client_email : 'bogus' , private_key : 'bogus' } , projectId : 'bogus' , } ) ; client . initialize ( ) ; const request = generateSampleMessage ( new protos . google . cloud . speech . v1p1beta1 . ListPhraseSetRequest ( ) ) ; request . parent = '' ; const expectedHeaderRequestParams = 'parent=' ; const expectedError = new Error ( 'expected' ) ; client . descriptors . page . listPhraseSet . asyncIterate = stubAsyncIterationCall ( undefined , expectedError ) ; const iterable = client . listPhraseSetAsync ( request ) ; await assert . rejects ( async ( ) => { const responses = [ ] ; for await ( const resource of iterable ) { responses . push ( resource ! ) ; } } ) ; assert . deepStrictEqual ( ( client . descriptors . page . listPhraseSet . asyncIterate as SinonStub ) . getCall ( 0 ) . args [ 1 ] , request ) ; assert . strictEqual ( ( client . descriptors . page . listPhraseSet . asyncIterate as SinonStub ) . getCall ( 0 ) . args [ 2 ] . otherArgs . headers [ 'x-goog-request-params' ] , expectedHeaderRequestParams ) ; } ) ; } ) ; describe ( 'listCustomClasses' , ( ) => { it ( 'invokes listCustomClasses without error' , async ( ) => { const client = new adaptationModule . v1p1beta1 . AdaptationClient ( { credentials : { client_email : 'bogus' , private_key : 'bogus' } , projectId : 'bogus' , } ) ; client . initialize ( ) ; const request = generateSampleMessage ( new protos . google . cloud . speech . v1p1beta1 . ListCustomClassesRequest ( ) ) ; request . parent = '' ; const expectedHeaderRequestParams = 'parent=' ; const expectedOptions = { otherArgs : { headers : { 'x-goog-request-params' : expectedHeaderRequestParams , } , } , } ; const expectedResponse = [ generateSampleMessage ( new protos . google . cloud . speech . v1p1beta1 . CustomClass ( ) ) , generateSampleMessage ( new protos . google . cloud . speech . v1p1beta1 . CustomClass ( ) ) , generateSampleMessage ( new protos . google . cloud . speech . v1p1beta1 . CustomClass ( ) ) , ] ; client . innerApiCalls . listCustomClasses = stubSimpleCall ( expectedResponse ) ; const [ response ] = await client . listCustomClasses ( request ) ; assert . deepStrictEqual ( response , expectedResponse ) ; assert ( ( client . innerApiCalls . listCustomClasses as SinonStub ) . getCall ( 0 ) . calledWith ( request , expectedOptions , undefined ) ) ; } ) ; it ( 'invokes listCustomClasses without error using callback' , async ( ) => { const client = new adaptationModule . v1p1beta1 . AdaptationClient ( { credentials : { client_email : 'bogus' , private_key : 'bogus' } , projectId : 'bogus' , } ) ; client . initialize ( ) ; const request = generateSampleMessage ( new protos . google . cloud . speech . v1p1beta1 . ListCustomClassesRequest ( ) ) ; request . parent = '' ; const expectedHeaderRequestParams = 'parent=' ; const expectedOptions = { otherArgs : { headers : { 'x-goog-request-params' : expectedHeaderRequestParams , } , } , } ; const expectedResponse = [ generateSampleMessage ( new protos . google . cloud . speech . v1p1beta1 . CustomClass ( ) ) , generateSampleMessage ( new protos . google . cloud . speech . v1p1beta1 . CustomClass ( ) ) , generateSampleMessage ( new protos . google . cloud . speech . v1p1beta1 . CustomClass ( ) ) , ] ; client . innerApiCalls . listCustomClasses = stubSimpleCallWithCallback ( expectedResponse ) ; const promise = new Promise ( ( resolve , reject ) => { client . listCustomClasses ( request , ( err ? , result ? ) => { if ( err ) { reject ( err ) ; } else { resolve ( result ) ; } } ) ; } ) ; const response = await promise ; assert . deepStrictEqual ( response , expectedResponse ) ; assert ( ( client . innerApiCalls . listCustomClasses as SinonStub ) . getCall ( 0 ) . calledWith ( request , expectedOptions ) ) ; } ) ; it ( 'invokes listCustomClasses with error' , async ( ) => { const client = new adaptationModule . v1p1beta1 . AdaptationClient ( { credentials : { client_email : 'bogus' , private_key : 'bogus' } , projectId : 'bogus' , } ) ; client . initialize ( ) ; const request = generateSampleMessage ( new protos . google . cloud . speech . v1p1beta1 . ListCustomClassesRequest ( ) ) ; request . parent = '' ; const expectedHeaderRequestParams = 'parent=' ; const expectedOptions = { otherArgs : { headers : { 'x-goog-request-params' : expectedHeaderRequestParams , } , } , } ; const expectedError = new Error ( 'expected' ) ; client . innerApiCalls . listCustomClasses = stubSimpleCall ( undefined , expectedError ) ; await assert . rejects ( client . listCustomClasses ( request ) , expectedError ) ; assert ( ( client . innerApiCalls . listCustomClasses as SinonStub ) . getCall ( 0 ) . calledWith ( request , expectedOptions , undefined ) ) ; } ) ; it ( 'invokes listCustomClassesStream without error' , async ( ) => { const client = new adaptationModule . v1p1beta1 . AdaptationClient ( { credentials : { client_email : 'bogus' , private_key : 'bogus' } , projectId : 'bogus' , } ) ; client . initialize ( ) ; const request = generateSampleMessage ( new protos . google . cloud . speech . v1p1beta1 . ListCustomClassesRequest ( ) ) ; request . parent = '' ; const expectedHeaderRequestParams = 'parent=' ; const expectedResponse = [ generateSampleMessage ( new protos . google . cloud . speech . v1p1beta1 . CustomClass ( ) ) , generateSampleMessage ( new protos . google . cloud . speech . v1p1beta1 . CustomClass ( ) ) , generateSampleMessage ( new protos . google . cloud . speech . v1p1beta1 . CustomClass ( ) ) , ] ; client . descriptors . page . listCustomClasses . createStream = stubPageStreamingCall ( expectedResponse ) ; const stream = client . listCustomClassesStream ( request ) ; const promise = new Promise ( ( resolve , reject ) => { const responses = [ ] ; stream . on ( 'data' , ( response ) => { responses . push ( response ) ; } ) ; stream . on ( 'end' , ( ) => { resolve ( responses ) ; } ) ; stream . on ( 'error' , ( err ) => { reject ( err ) ; } ) ; } ) ; const responses = await promise ; assert . deepStrictEqual ( responses , expectedResponse ) ; assert ( ( client . descriptors . page . listCustomClasses . createStream as SinonStub ) . getCall ( 0 ) . calledWith ( client . innerApiCalls . listCustomClasses , request ) ) ; assert . strictEqual ( ( client . descriptors . page . listCustomClasses . createStream as SinonStub ) . getCall ( 0 ) . args [ 2 ] . otherArgs . headers [ 'x-goog-request-params' ] , expectedHeaderRequestParams ) ; } ) ; it ( 'invokes listCustomClassesStream with error' , async ( ) => { const client = new adaptationModule . v1p1beta1 . AdaptationClient ( { credentials : { client_email : 'bogus' , private_key : 'bogus' } , projectId : 'bogus' , } ) ; client . initialize ( ) ; const request = generateSampleMessage ( new protos . google . cloud . speech . v1p1beta1 . ListCustomClassesRequest ( ) ) ; request . parent = '' ; const expectedHeaderRequestParams = 'parent=' ; const expectedError = new Error ( 'expected' ) ; client . descriptors . page . listCustomClasses . createStream = stubPageStreamingCall ( undefined , expectedError ) ; const stream = client . listCustomClassesStream ( request ) ; const promise = new Promise ( ( resolve , reject ) => { const responses = [ ] ; stream . on ( 'data' , ( response ) => { responses . push ( response ) ; } ) ; stream . on ( 'end' , ( ) => { resolve ( responses ) ; } ) ; stream . on ( 'error' , ( err ) => { reject ( err ) ; } ) ; } ) ; await assert . rejects ( promise , expectedError ) ; assert ( ( client . descriptors . page . listCustomClasses . createStream as SinonStub ) . getCall ( 0 ) . calledWith ( client . innerApiCalls . listCustomClasses , request ) ) ; assert . strictEqual ( ( client . descriptors . page . listCustomClasses . createStream as SinonStub ) . getCall ( 0 ) . args [ 2 ] . otherArgs . headers [ 'x-goog-request-params' ] , expectedHeaderRequestParams ) ; } ) ; it ( 'uses async iteration with listCustomClasses without error' , async ( ) => { const client = new adaptationModule . v1p1beta1 . AdaptationClient ( { credentials : { client_email : 'bogus' , private_key : 'bogus' } , projectId : 'bogus' , } ) ; client . initialize ( ) ; const request = generateSampleMessage ( new protos . google . cloud . speech . v1p1beta1 . ListCustomClassesRequest ( ) ) ; request . parent = '' ; const expectedHeaderRequestParams = 'parent=' ; const expectedResponse = [ generateSampleMessage ( new protos . google . cloud . speech . v1p1beta1 . CustomClass ( ) ) , generateSampleMessage ( new protos . google . cloud . speech . v1p1beta1 . CustomClass ( ) ) , generateSampleMessage ( new protos . google . cloud . speech . v1p1beta1 . CustomClass ( ) ) , ] ; client . descriptors . page . listCustomClasses . asyncIterate = stubAsyncIterationCall ( expectedResponse ) ; const responses = [ ] ; const iterable = client . listCustomClassesAsync ( request ) ; for await ( const resource of iterable ) { responses . push ( resource ! ) ; } assert . deepStrictEqual ( responses , expectedResponse ) ; assert . deepStrictEqual ( ( client . descriptors . page . listCustomClasses . asyncIterate as SinonStub ) . getCall ( 0 ) . args [ 1 ] , request ) ; assert . strictEqual ( ( client . descriptors . page . listCustomClasses . asyncIterate as SinonStub ) . getCall ( 0 ) . args [ 2 ] . otherArgs . headers [ 'x-goog-request-params' ] , expectedHeaderRequestParams ) ; } ) ; it ( 'uses async iteration with listCustomClasses with error' , async ( ) => { const client = new adaptationModule . v1p1beta1 . AdaptationClient ( { credentials : { client_email : 'bogus' , private_key : 'bogus' } , projectId : 'bogus' , } ) ; client . initialize ( ) ; const request = generateSampleMessage ( new protos . google . cloud . speech . v1p1beta1 . ListCustomClassesRequest ( ) ) ; request . parent = '' ; const expectedHeaderRequestParams = 'parent=' ; const expectedError = new Error ( 'expected' ) ; client . descriptors . page . listCustomClasses . asyncIterate = stubAsyncIterationCall ( undefined , expectedError ) ; const iterable = client . listCustomClassesAsync ( request ) ; await assert . rejects ( async ( ) => { const responses = [ ] ; for await ( const resource of iterable ) { responses . push ( resource ! ) ; } } ) ; assert . deepStrictEqual ( ( client . descriptors . page . listCustomClasses . asyncIterate as SinonStub ) . getCall ( 0 ) . args [ 1 ] , request ) ; assert . strictEqual ( ( client . descriptors . page . listCustomClasses . asyncIterate as SinonStub ) . getCall ( 0 ) . args [ 2 ] . otherArgs . headers [ 'x-goog-request-params' ] , expectedHeaderRequestParams ) ; } ) ; } ) ; describe ( 'Path templates' , ( ) => { describe ( 'customClass' , ( ) => { const fakePath = '/rendered/path/customClass' ; const expectedParameters = { project : 'projectValue' , location : 'locationValue' , custom_class : 'customClassValue' , } ; const client = new adaptationModule . v1p1beta1 . AdaptationClient ( { credentials : { client_email : 'bogus' , private_key : 'bogus' } , projectId : 'bogus' , } ) ; client . initialize ( ) ; client . pathTemplates . customClassPathTemplate . render = sinon . stub ( ) . returns ( fakePath ) ; client . pathTemplates . customClassPathTemplate . match = sinon . stub ( ) . returns ( expectedParameters ) ; it ( 'customClassPath' , ( ) => { const result = client . customClassPath ( 'projectValue' , 'locationValue' , 'customClassValue' ) ; assert . strictEqual ( result , fakePath ) ; assert ( ( client . pathTemplates . customClassPathTemplate . render as SinonStub ) . getCall ( - 1 ) . calledWith ( expectedParameters ) ) ; } ) ; it ( 'matchProjectFromCustomClassName' , ( ) => { const result = client . matchProjectFromCustomClassName ( fakePath ) ; assert . strictEqual ( result , 'projectValue' ) ; assert ( ( client . pathTemplates . customClassPathTemplate . match as SinonStub ) . getCall ( - 1 ) . calledWith ( fakePath ) ) ; } ) ; it ( 'matchLocationFromCustomClassName' , ( ) => { const result = client . matchLocationFromCustomClassName ( fakePath ) ; assert . strictEqual ( result , 'locationValue' ) ; assert ( ( client . pathTemplates . customClassPathTemplate . match as SinonStub ) . getCall ( - 1 ) . calledWith ( fakePath ) ) ; } ) ; it ( 'matchCustomClassFromCustomClassName' , ( ) => { const result = client . matchCustomClassFromCustomClassName ( fakePath ) ; assert . strictEqual ( result , 'customClassValue' ) ; assert ( ( client . pathTemplates . customClassPathTemplate . match as SinonStub ) . getCall ( - 1 ) . calledWith ( fakePath ) ) ; } ) ; } ) ; describe ( 'location' , ( ) => { const fakePath = '/rendered/path/location' ; const expectedParameters = { project : 'projectValue' , location : 'locationValue' , } ; const client = new adaptationModule . v1p1beta1 . AdaptationClient ( { credentials : { client_email : 'bogus' , private_key : 'bogus' } , projectId : 'bogus' , } ) ; client . initialize ( ) ; client . pathTemplates . locationPathTemplate . render = sinon . stub ( ) . returns ( fakePath ) ; client . pathTemplates . locationPathTemplate . match = sinon . stub ( ) . returns ( expectedParameters ) ; it ( 'locationPath' , ( ) => { const result = client . locationPath ( 'projectValue' , 'locationValue' ) ; assert . strictEqual ( result , fakePath ) ; assert ( ( client . pathTemplates . locationPathTemplate . render as SinonStub ) . getCall ( - 1 ) . calledWith ( expectedParameters ) ) ; } ) ; it ( 'matchProjectFromLocationName' , ( ) => { const result = client . matchProjectFromLocationName ( fakePath ) ; assert . strictEqual ( result , 'projectValue' ) ; assert ( ( client . pathTemplates . locationPathTemplate . match as SinonStub ) . getCall ( - 1 ) . calledWith ( fakePath ) ) ; } ) ; it ( 'matchLocationFromLocationName' , ( ) => { const result = client . matchLocationFromLocationName ( fakePath ) ; assert . strictEqual ( result , 'locationValue' ) ; assert ( ( client . pathTemplates . locationPathTemplate . match as SinonStub ) . getCall ( - 1 ) . calledWith ( fakePath ) ) ; } ) ; } ) ; describe ( 'phraseSet' , ( ) => { const fakePath = '/rendered/path/phraseSet' ; const expectedParameters = { project : 'projectValue' , location : 'locationValue' , phrase_set : 'phraseSetValue' , } ; const client = new adaptationModule . v1p1beta1 . AdaptationClient ( { credentials : { client_email : 'bogus' , private_key : 'bogus' } , projectId : 'bogus' , } ) ; client . initialize ( ) ; client . pathTemplates . phraseSetPathTemplate . render = sinon . stub ( ) . returns ( fakePath ) ; client . pathTemplates . phraseSetPathTemplate . match = sinon . stub ( ) . returns ( expectedParameters ) ; it ( 'phraseSetPath' , ( ) => { const result = client . phraseSetPath ( 'projectValue' , 'locationValue' , 'phraseSetValue' ) ; assert . strictEqual ( result , fakePath ) ; assert ( ( client . pathTemplates . phraseSetPathTemplate . render as SinonStub ) . getCall ( - 1 ) . calledWith ( expectedParameters ) ) ; } ) ; it ( 'matchProjectFromPhraseSetName' , ( ) => { const result = client . matchProjectFromPhraseSetName ( fakePath ) ; assert . strictEqual ( result , 'projectValue' ) ; assert ( ( client . pathTemplates . phraseSetPathTemplate . match as SinonStub ) . getCall ( - 1 ) . calledWith ( fakePath ) ) ; } ) ; it ( 'matchLocationFromPhraseSetName' , ( ) => { const result = client . matchLocationFromPhraseSetName ( fakePath ) ; assert . strictEqual ( result , 'locationValue' ) ; assert ( ( client . pathTemplates . phraseSetPathTemplate . match as SinonStub ) . getCall ( - 1 ) . calledWith ( fakePath ) ) ; } ) ; it ( 'matchPhraseSetFromPhraseSetName' , ( ) => { const result = client . matchPhraseSetFromPhraseSetName ( fakePath ) ; assert . strictEqual ( result , 'phraseSetValue' ) ; assert ( ( client . pathTemplates . phraseSetPathTemplate . match as SinonStub ) . getCall ( - 1 ) . calledWith ( fakePath ) ) ; } ) ; } ) ; describe ( 'project' , ( ) => { const fakePath = '/rendered/path/project' ; const expectedParameters = { project : 'projectValue' , } ; const client = new adaptationModule . v1p1beta1 . AdaptationClient ( { credentials : { client_email : 'bogus' , private_key : 'bogus' } , projectId : 'bogus' , } ) ; client . initialize ( ) ; client . pathTemplates . projectPathTemplate . render = sinon . stub ( ) . returns ( fakePath ) ; client . pathTemplates . projectPathTemplate . match = sinon . stub ( ) . returns ( expectedParameters ) ; it ( 'projectPath' , ( ) => { const result = client . projectPath ( 'projectValue' ) ; assert . strictEqual ( result , fakePath ) ; assert ( ( client . pathTemplates . projectPathTemplate . render as SinonStub ) . getCall ( - 1 ) . calledWith ( expectedParameters ) ) ; } ) ; it ( 'matchProjectFromProjectName' , ( ) => { const result = client . matchProjectFromProjectName ( fakePath ) ; assert . strictEqual ( result , 'projectValue' ) ; assert ( ( client . pathTemplates . projectPathTemplate . match as SinonStub ) . getCall ( - 1 ) . calledWith ( fakePath ) ) ; } ) ; } ) ; } ) ; } ) ;