Skip to content

Commit

Permalink
fix: do not overwrite flushIntervalMillis=0 with default value (10 se…
Browse files Browse the repository at this point in the history
…conds) (#589)
  • Loading branch information
falconandy authored Apr 27, 2023
1 parent 94e9d61 commit 9c96890
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/amplitude-client.js
Original file line number Diff line number Diff line change
Expand Up @@ -413,6 +413,8 @@ var _parseConfig = function _parseConfig(options, config) {
// Add exception in headers
const freeFormObjectKeys = new Set(['headers']);

const zeroAllowedKeys = new Set(['eventUploadPeriodMillis']);

// validates config value is defined, is the correct type, and some additional value sanity checks
var parseValidateAndLoad = function parseValidateAndLoad(key) {
if (!Object.prototype.hasOwnProperty.call(options, key)) {
Expand All @@ -433,7 +435,7 @@ var _parseConfig = function _parseConfig(options, config) {
options[key] = !!inputValue;
} else if (
(expectedType === 'string' && !utils.isEmptyString(inputValue)) ||
(expectedType === 'number' && inputValue > 0) ||
(expectedType === 'number' && (inputValue > 0 || (inputValue === 0 && zeroAllowedKeys.has(key)))) ||
expectedType === 'function'
) {
options[key] = inputValue;
Expand Down
9 changes: 9 additions & 0 deletions test/amplitude-client.js
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,15 @@ describe('AmplitudeClient', function () {
assert.equal(amplitude.options.bogusKey, undefined);
});

it('should not overwrite eventUploadPeriodMillis=0 with default value', function () {
var config = {
eventUploadPeriodMillis: 0,
};

amplitude.init(apiKey, userId, config);
assert.equal(amplitude.options.eventUploadPeriodMillis, 0);
});

it('should set the default log level', function () {
const config = {};

Expand Down

0 comments on commit 9c96890

Please sign in to comment.