@@ -267,6 +267,34 @@ describe('ServiceObject', () => {
267267 serviceObject . delete ( options , assert . ifError ) ;
268268 } ) ;
269269
270+ it ( 'should override method and uri field in request with methodConfig' , done => {
271+ const methodConfig = {
272+ reqOpts : {
273+ uri : 'v2' ,
274+ method : 'PATCH' ,
275+ } ,
276+ } ;
277+
278+ const cachedMethodConfig = extend ( true , { } , methodConfig ) ;
279+
280+ sandbox
281+ . stub ( ServiceObject . prototype , 'request' )
282+ . callsFake ( ( reqOpts_ , callback ) => {
283+ assert . deepStrictEqual (
284+ serviceObject . methods . delete ,
285+ cachedMethodConfig
286+ ) ;
287+ assert . deepStrictEqual ( reqOpts_ . uri , 'v2' ) ;
288+ assert . deepStrictEqual ( reqOpts_ . method , 'PATCH' ) ;
289+ done ( ) ;
290+ callback ( null , null , null ! ) ;
291+ } ) ;
292+
293+ const serviceObject = new ServiceObject ( CONFIG ) as FakeServiceObject ;
294+ serviceObject . methods . delete = methodConfig ;
295+ serviceObject . delete ( ) ;
296+ } ) ;
297+
270298 it ( 'should extend the defaults with request options' , done => {
271299 const methodConfig = {
272300 reqOpts : {
@@ -561,6 +589,32 @@ describe('ServiceObject', () => {
561589 serviceObject . getMetadata ( options , assert . ifError ) ;
562590 } ) ;
563591
592+ it ( 'should override uri field in request with methodConfig' , done => {
593+ const methodConfig = {
594+ reqOpts : {
595+ uri : 'v2' ,
596+ } ,
597+ } ;
598+
599+ const cachedMethodConfig = extend ( true , { } , methodConfig ) ;
600+
601+ sandbox
602+ . stub ( ServiceObject . prototype , 'request' )
603+ . callsFake ( ( reqOpts_ , callback ) => {
604+ assert . deepStrictEqual (
605+ serviceObject . methods . getMetadata ,
606+ cachedMethodConfig
607+ ) ;
608+ assert . deepStrictEqual ( reqOpts_ . uri , 'v2' ) ;
609+ done ( ) ;
610+ callback ( null , null , null ! ) ;
611+ } ) ;
612+
613+ const serviceObject = new ServiceObject ( CONFIG ) as FakeServiceObject ;
614+ serviceObject . methods . getMetadata = methodConfig ;
615+ serviceObject . getMetadata ( ) ;
616+ } ) ;
617+
564618 it ( 'should extend the defaults with request options' , done => {
565619 const methodConfig = {
566620 reqOpts : {
@@ -662,6 +716,33 @@ describe('ServiceObject', () => {
662716 serviceObject . setMetadata ( metadata , options , ( ) => { } ) ;
663717 } ) ;
664718
719+ it ( 'should override uri and method with methodConfig' , done => {
720+ const methodConfig = {
721+ reqOpts : {
722+ uri : 'v2' ,
723+ method : 'PUT' ,
724+ } ,
725+ } ;
726+ const cachedMethodConfig = extend ( true , { } , methodConfig ) ;
727+
728+ sandbox
729+ . stub ( ServiceObject . prototype , 'request' )
730+ . callsFake ( ( reqOpts_ , callback ) => {
731+ assert . deepStrictEqual (
732+ serviceObject . methods . setMetadata ,
733+ cachedMethodConfig
734+ ) ;
735+ assert . deepStrictEqual ( reqOpts_ . uri , 'v2' ) ;
736+ assert . deepStrictEqual ( reqOpts_ . method , 'PUT' ) ;
737+ done ( ) ;
738+ callback ( null , null , null ! ) ;
739+ } ) ;
740+
741+ const serviceObject = new ServiceObject ( CONFIG ) as FakeServiceObject ;
742+ serviceObject . methods . setMetadata = methodConfig ;
743+ serviceObject . setMetadata ( { } ) ;
744+ } ) ;
745+
665746 it ( 'should extend the defaults with request options' , done => {
666747 const methodConfig = {
667748 reqOpts : {
0 commit comments