Skip to content

Commit d8a5f45

Browse files
author
Eric Koleda
committed
Change to toLowerCaseKeys_(), combine tests.
1 parent 313fb23 commit d8a5f45

File tree

3 files changed

+32
-38
lines changed

3 files changed

+32
-38
lines changed

src/Service.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -714,7 +714,7 @@ Service_.prototype.exchangeGrant_ = function() {
714714
// For the client_credentials grant type, add a basic authorization header:
715715
// - If the client ID and client secret are set.
716716
// - No authorization header has been set yet.
717-
var lowerCaseHeaders = witLowerCaseKeys_(this.tokenHeaders_);
717+
var lowerCaseHeaders = toLowerCaseKeys_(this.tokenHeaders_);
718718
if (this.grantType_ === 'client_credentials' &&
719719
this.clientId_ &&
720720
this.clientSecret_ &&

src/Utilities.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,14 +77,14 @@ function extend_(destination, source) {
7777
return destination;
7878
}
7979

80-
/* exported witLowerCaseKeys_ */
80+
/* exported toLowerCaseKeys_ */
8181
/**
8282
* Gets a copy of an object with all the keys converted to lower-case strings.
8383
*
8484
* @param {Object} obj The object to copy.
8585
* @return {Object} a shallow copy of the object with all lower-case keys.
8686
*/
87-
function witLowerCaseKeys_(obj) {
87+
function toLowerCaseKeys_(obj) {
8888
if (obj === null || typeof obj !== 'object') {
8989
return obj;
9090
}

test/test.js

Lines changed: 29 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -243,12 +243,12 @@ describe('Service', function() {
243243
});
244244

245245
describe('#exchangeGrant_()', function() {
246-
var witLowerCaseKeys_ = OAuth2.witLowerCaseKeys_;
246+
var toLowerCaseKeys_ = OAuth2.toLowerCaseKeys_;
247247

248248
it('should not set auth header if the grant type is not client_credentials',
249249
function(done) {
250250
mocks.UrlFetchApp.resultFunction = function(url, urlOptions) {
251-
assert.isUndefined(witLowerCaseKeys_(urlOptions.headers).authorization);
251+
assert.isUndefined(toLowerCaseKeys_(urlOptions.headers).authorization);
252252
done();
253253
};
254254
var service = OAuth2.createService('test')
@@ -260,7 +260,7 @@ describe('Service', function() {
260260
it('should not set auth header if the client ID is not set',
261261
function(done) {
262262
mocks.UrlFetchApp.resultFunction = function(url, urlOptions) {
263-
assert.isUndefined(witLowerCaseKeys_(urlOptions.headers).authorization);
263+
assert.isUndefined(toLowerCaseKeys_(urlOptions.headers).authorization);
264264
done();
265265
};
266266
var service = OAuth2.createService('test')
@@ -272,7 +272,7 @@ describe('Service', function() {
272272
it('should not set auth header if the client secret is not set',
273273
function(done) {
274274
mocks.UrlFetchApp.resultFunction = function(url, urlOptions) {
275-
assert.isUndefined(witLowerCaseKeys_(urlOptions.headers).authorization);
275+
assert.isUndefined(toLowerCaseKeys_(urlOptions.headers).authorization);
276276
done();
277277
};
278278
var service = OAuth2.createService('test')
@@ -285,7 +285,7 @@ describe('Service', function() {
285285
it('should not set auth header if it is already set',
286286
function(done) {
287287
mocks.UrlFetchApp.resultFunction = function(url, urlOptions) {
288-
assert.equal(witLowerCaseKeys_(urlOptions.headers).authorization,
288+
assert.equal(toLowerCaseKeys_(urlOptions.headers).authorization,
289289
'something');
290290
done();
291291
};
@@ -304,7 +304,7 @@ describe('Service', function() {
304304
'the client ID and client secret are set and the authorization header' +
305305
'is not already set', function(done) {
306306
mocks.UrlFetchApp.resultFunction = function(url, urlOptions) {
307-
assert.equal(witLowerCaseKeys_(urlOptions.headers).authorization,
307+
assert.equal(toLowerCaseKeys_(urlOptions.headers).authorization,
308308
'Basic YWJjOmRlZg==');
309309
done();
310310
};
@@ -336,38 +336,32 @@ describe('Utilities', function() {
336336
});
337337
});
338338

339-
describe('#witLowerCaseKeys_()', function() {
340-
var witLowerCaseKeys_ = OAuth2.witLowerCaseKeys_;
341-
var data = {
342-
'a': true,
343-
'A': true,
344-
'B': true,
345-
'Cc': true,
346-
'D2': true,
347-
'E!@#': true
348-
};
349-
var lowerCaseData = witLowerCaseKeys_(data);
350-
351-
it('should contain lower-case keys', function() {
352-
assert.isTrue(lowerCaseData['a']);
353-
assert.isTrue(lowerCaseData['b']);
354-
assert.isTrue(lowerCaseData['cc']);
355-
assert.isTrue(lowerCaseData['d2']);
356-
assert.isTrue(lowerCaseData['e!@#']);
357-
});
358-
359-
it('should not contain upper-case keys', function() {
360-
assert.isUndefined(lowerCaseData['A']);
361-
assert.isUndefined(lowerCaseData['B']);
362-
assert.isUndefined(lowerCaseData['Cc']);
363-
assert.isUndefined(lowerCaseData['D2']);
364-
assert.isUndefined(lowerCaseData['E!@#']);
339+
describe('#toLowerCaseKeys_()', function() {
340+
var toLowerCaseKeys_ = OAuth2.toLowerCaseKeys_;
341+
342+
it('should contain only lower-case keys', function() {
343+
var data = {
344+
'a': true,
345+
'A': true,
346+
'B': true,
347+
'Cc': true,
348+
'D2': true,
349+
'E!@#': true
350+
};
351+
var lowerCaseData = toLowerCaseKeys_(data);
352+
assert.deepEqual(lowerCaseData, {
353+
'a': true,
354+
'b': true,
355+
'cc': true,
356+
'd2': true,
357+
'e!@#': true
358+
});
365359
});
366360

367361
it('should handle null, undefined, and empty objects', function() {
368-
assert.isNull(witLowerCaseKeys_(null));
369-
assert.isUndefined(witLowerCaseKeys_(undefined));
370-
assert.isEmpty(witLowerCaseKeys_({}));
362+
assert.isNull(toLowerCaseKeys_(null));
363+
assert.isUndefined(toLowerCaseKeys_(undefined));
364+
assert.isEmpty(toLowerCaseKeys_({}));
371365
});
372366
});
373367
});

0 commit comments

Comments
 (0)