Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Normalize arguments when using new. #57

Merged
merged 1 commit into from
Jan 24, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -109,10 +109,11 @@ var Sink = require('./sink.js');
*/
function Logging(options) {
if (!(this instanceof Logging)) {
options = common.util.normalizeArguments(this, options);
return new Logging(options);
}

options = common.util.normalizeArguments(this, options);

// Determine what scopes are needed.
// It is the union of the scopes on all three clients.
let scopes = [];
Expand Down
28 changes: 13 additions & 15 deletions test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ var fakeUtil = extend({}, util, {
return reqOpts;
},
});
var originalFakeUtil = extend(true, {}, fakeUtil);

function fakeV2() {}

Expand Down Expand Up @@ -115,6 +116,8 @@ describe('Logging', function() {
});

beforeEach(function() {
extend(fakeUtil, originalFakeUtil);

googleAutoAuthOverride = null;
isCustomTypeOverride = null;
replaceProjectIdTokenOverride = null;
Expand Down Expand Up @@ -148,29 +151,24 @@ describe('Logging', function() {
assert(promisifed);
});

it('should normalize the arguments', function() {
var options = {
projectId: PROJECT_ID,
credentials: 'credentials',
email: 'email',
keyFilename: 'keyFile',
};
it('should work without new', function() {
assert.doesNotThrow(function() {
Logging({projectId: PROJECT_ID});
});
});

var normalizeArguments = fakeUtil.normalizeArguments;
it('should normalize the arguments', function() {
var normalizeArgumentsCalled = false;
var fakeContext = {};
var options = {};

fakeUtil.normalizeArguments = function(context, options_) {
normalizeArgumentsCalled = true;
assert.strictEqual(context, fakeContext);
assert.strictEqual(options, options_);
assert.strictEqual(options_, options);
return options_;
};

Logging.call(fakeContext, options);
assert(normalizeArgumentsCalled);

fakeUtil.normalizeArguments = normalizeArguments;
new Logging(options);
assert.strictEqual(normalizeArgumentsCalled, true);
});

it('should initialize the API object', function() {
Expand Down