@@ -1275,78 +1275,97 @@ describe('common/util', function() {
12751275 assert . strictEqual ( decoratedReqOpts . json . autoPaginateVal , undefined ) ;
12761276 } ) ;
12771277
1278- describe ( 'projectId placeholder' , function ( ) {
1279- var PROJECT_ID = 'project-id' ;
1278+ it ( 'should decorate the request' , function ( ) {
1279+ var config = {
1280+ projectId : 'project-id'
1281+ } ;
1282+ var reqOpts = { } ;
1283+ var decoratedReqOpts = { } ;
12801284
1281- it ( 'should replace any {{projectId}} it finds' , function ( ) {
1282- assert . deepEqual ( util . decorateRequest ( {
1285+ utilOverrides . replaceProjectIdToken = function ( reqOpts_ , projectId ) {
1286+ assert . strictEqual ( reqOpts_ , reqOpts ) ;
1287+ assert . strictEqual ( projectId , config . projectId ) ;
1288+ return decoratedReqOpts ;
1289+ } ;
1290+
1291+ assert . strictEqual (
1292+ util . decorateRequest ( reqOpts , config ) ,
1293+ decoratedReqOpts
1294+ ) ;
1295+ } ) ;
1296+ } ) ;
1297+
1298+ describe ( 'projectId placeholder' , function ( ) {
1299+ var PROJECT_ID = 'project-id' ;
1300+
1301+ it ( 'should replace any {{projectId}} it finds' , function ( ) {
1302+ assert . deepEqual ( util . replaceProjectIdToken ( {
1303+ here : 'A {{projectId}} Z' ,
1304+ nested : {
12831305 here : 'A {{projectId}} Z' ,
12841306 nested : {
1307+ here : 'A {{projectId}} Z'
1308+ }
1309+ } ,
1310+ array : [
1311+ {
12851312 here : 'A {{projectId}} Z' ,
12861313 nested : {
12871314 here : 'A {{projectId}} Z'
1288- }
1289- } ,
1290- array : [
1291- {
1292- here : 'A {{projectId}} Z' ,
1293- nested : {
1294- here : 'A {{projectId}} Z'
1295- } ,
1296- nestedArray : [
1297- {
1298- here : 'A {{projectId}} Z' ,
1299- nested : {
1300- here : 'A {{projectId}} Z'
1301- }
1315+ } ,
1316+ nestedArray : [
1317+ {
1318+ here : 'A {{projectId}} Z' ,
1319+ nested : {
1320+ here : 'A {{projectId}} Z'
13021321 }
1303- ]
1304- }
1305- ]
1306- } , { projectId : PROJECT_ID } ) ,
1307- {
1322+ }
1323+ ]
1324+ }
1325+ ]
1326+ } , PROJECT_ID ) ,
1327+ {
1328+ here : 'A ' + PROJECT_ID + ' Z' ,
1329+ nested : {
13081330 here : 'A ' + PROJECT_ID + ' Z' ,
13091331 nested : {
1332+ here : 'A ' + PROJECT_ID + ' Z'
1333+ }
1334+ } ,
1335+ array : [
1336+ {
13101337 here : 'A ' + PROJECT_ID + ' Z' ,
13111338 nested : {
13121339 here : 'A ' + PROJECT_ID + ' Z'
1313- }
1314- } ,
1315- array : [
1316- {
1317- here : 'A ' + PROJECT_ID + ' Z' ,
1318- nested : {
1319- here : 'A ' + PROJECT_ID + ' Z'
1320- } ,
1321- nestedArray : [
1322- {
1323- here : 'A ' + PROJECT_ID + ' Z' ,
1324- nested : {
1325- here : 'A ' + PROJECT_ID + ' Z'
1326- }
1340+ } ,
1341+ nestedArray : [
1342+ {
1343+ here : 'A ' + PROJECT_ID + ' Z' ,
1344+ nested : {
1345+ here : 'A ' + PROJECT_ID + ' Z'
13271346 }
1328- ]
1329- }
1330- ]
1331- } ) ;
1347+ }
1348+ ]
1349+ }
1350+ ]
13321351 } ) ;
1352+ } ) ;
13331353
1334- it ( 'should replace more than one {{projectId}}' , function ( ) {
1335- assert . deepEqual ( util . decorateRequest ( {
1336- here : 'A {{projectId}} M {{projectId}} Z' ,
1337- } , { projectId : PROJECT_ID } ) ,
1338- {
1339- here : 'A ' + PROJECT_ID + ' M ' + PROJECT_ID + ' Z'
1340- } ) ;
1354+ it ( 'should replace more than one {{projectId}}' , function ( ) {
1355+ assert . deepEqual ( util . replaceProjectIdToken ( {
1356+ here : 'A {{projectId}} M {{projectId}} Z' ,
1357+ } , PROJECT_ID ) ,
1358+ {
1359+ here : 'A ' + PROJECT_ID + ' M ' + PROJECT_ID + ' Z'
13411360 } ) ;
1361+ } ) ;
13421362
1343- it ( 'should throw if it needs a projectId and cannot find it' , function ( ) {
1344- assert . throws ( function ( ) {
1345- util . decorateRequest ( {
1346- here : '{{projectId}}'
1347- } ) ;
1348- } , new RegExp ( util . missingProjectIdError ) ) ;
1349- } ) ;
1363+ it ( 'should throw if it needs a projectId and cannot find it' , function ( ) {
1364+ assert . throws ( function ( ) {
1365+ util . replaceProjectIdToken ( {
1366+ here : '{{projectId}}'
1367+ } ) ;
1368+ } , new RegExp ( util . missingProjectIdError ) ) ;
13501369 } ) ;
13511370 } ) ;
13521371
0 commit comments