From 9b12b4b02ef49e7ba0b34b0f23a84b9b31b7f917 Mon Sep 17 00:00:00 2001 From: tore-statsig <74584483+tore-statsig@users.noreply.github.com> Date: Fri, 6 May 2022 15:42:24 -0700 Subject: [PATCH] v4.14.1 (#157) * v4.14.1 * bump version --- package-lock.json | 4 ++-- package.json | 2 +- src/LogEventProcessor.js | 2 +- src/__tests__/index.test.js | 45 +++++++++++++++++++++++++++++++++++-- 4 files changed, 47 insertions(+), 6 deletions(-) diff --git a/package-lock.json b/package-lock.json index 685a48c..c64b23f 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "statsig-node", - "version": "4.14.0", + "version": "4.14.1", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "statsig-node", - "version": "4.14.0", + "version": "4.14.1", "license": "ISC", "dependencies": { "ip3country": "^5.0.0", diff --git a/package.json b/package.json index 57e020d..a45ef88 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "statsig-node", - "version": "4.14.0", + "version": "4.14.1", "description": "Statsig Node.js SDK for usage in multi-user server environments.", "main": "dist/src/index.js", "scripts": { diff --git a/src/LogEventProcessor.js b/src/LogEventProcessor.js index d8f3a9a..283bb1a 100644 --- a/src/LogEventProcessor.js +++ b/src/LogEventProcessor.js @@ -177,7 +177,7 @@ function LogEventProcessor(options, secretKey) { let metadataKey = ''; if (metadata && typeof(metadata) === 'object') { - customIdKey = Object.values(metadata).join(); + metadataKey = Object.values(metadata).join(); } const keyList = [ diff --git a/src/__tests__/index.test.js b/src/__tests__/index.test.js index 1934e68..38cd269 100644 --- a/src/__tests__/index.test.js +++ b/src/__tests__/index.test.js @@ -420,7 +420,7 @@ describe('Verify behavior of top level index functions', () => { expect(spy).toHaveBeenCalledWith(configExposure); }); - test('Verify that getConfig() and getExperiment() are deduped with same metadata', async () => { + test('Verify that checkGate() getConfig() and getExperiment() are deduped with same metadata', async () => { expect.assertions(1); const statsig = require('../index'); @@ -431,6 +431,9 @@ describe('Verify behavior of top level index functions', () => { number: 12345, }); }); + jest.spyOn(Evaluator, 'checkGate').mockImplementation((_, configName) => { + return new ConfigEvaluation(true, 'rule_id_config', [], {}); + }); await statsig.initialize(secretKey); let user = { userID: 123, privateAttributes: { secret: 'do not log' } }; @@ -439,9 +442,47 @@ describe('Verify behavior of top level index functions', () => { const spy = jest.spyOn(statsig._logger, 'log'); for (let ii = 0 ; ii < 10000; ii++) { await statsig.getConfig(user, configName); + await statsig.checkGate(user, "test_gate"); } - expect(spy).toHaveBeenCalledTimes(1); + expect(spy).toHaveBeenCalledTimes(2); + }); + + test('Verify that checkGate() getConfig() and getExperiment() are not deduped with different customIDs', async () => { + expect.assertions(2); + + const statsig = require('../index'); + const { Evaluator, ConfigEvaluation } = require('../Evaluator'); + jest.spyOn(Evaluator, 'getConfig').mockImplementation((_, configName) => { + return new ConfigEvaluation(true, 'rule_id_config', [], { + string: '12345', + number: 12345, + }); + }); + jest.spyOn(Evaluator, 'checkGate').mockImplementation((_, configName) => { + return new ConfigEvaluation(true, 'rule_id_config', [], {}); + }); + await statsig.initialize(secretKey); + + let user = { userID: 123, customIDs: {"project": "def", company: "abc"}, privateAttributes: { secret: 'do not log' } }; + let configName = 'config_downloaded'; + const gateName = "test"; + + const spy = jest.spyOn(statsig._logger, 'log'); + for (let ii = 0 ; ii < 10000; ii++) { + await statsig.getConfig(user, configName); + await statsig.checkGate(user, gateName); + } + + expect(spy).toHaveBeenCalledTimes(2); + + for (let ii = 0 ; ii < 10000; ii++) { + user.customIDs.project = ii + ""; + await statsig.getConfig(user, configName); + await statsig.checkGate(user, gateName); + } + + expect(spy).toHaveBeenCalledTimes(20002); }); test('Verify that getConfig() and getExperiment() are not deduped with different user', async () => {