From 844a8b068ae85fc83f7f1636be94148831d29587 Mon Sep 17 00:00:00 2001 From: LaunchDarklyReleaseBot <86431345+LaunchDarklyReleaseBot@users.noreply.github.com> Date: Tue, 6 Sep 2022 15:07:15 -0700 Subject: [PATCH] prepare 6.4.3 release (#260) * revise tests to use new helper package * misc cleanup * use launchdarkly-js-test-helpers 1.0.0 * fix package reference * minor fixes to config validation messages + add comment * diagnostic eventsInQueue counter should be # of events at last flush * rename eventsInQueue to eventsInLastBatch * don't let user fall outside of last bucket in rollout * add unit tests for basic bucketing logic and edge case * avoid redundant property lookups * fix Redis client parameter to match TS declaration (but still support old incorrect parameter) * add event payload ID * remove mistakenly checked-in test code (note, this SDK key was only valid on staging) * add mention of singleton usage * update diagnostic event info for OS name, data store type, Node version * standardize linting * disallow window and document * fix null/undef checks * misc linting fixes * inlineUsersInEvents is not an unknown option * drop node-sha1 dependency * don't omit streamInits.failed when it's false * bump request dependency to get security patch; loosen some exact dependencies * remove request package; improve polling cache logic + add test * bump typescript version to fix build error in Node 6 * update @types/node to fix TypeScript check step * lint * make sure we keep polling regardless of whether we got new data * use launchdarkly-eventsource, make stream retry behavior consistent * stream retry delay option should be in seconds & should be included in diagnostics * minor test fix * fix: Throw an error on malformed user-supplied logger * don't call unref() on Redis client; ensure that database integration tests close the store * update Redis driver to major version 3 * add test case * allow redisOpts parameter to be omitted * add logger adapter shim + tests * minor cleanup and comments for ch74741 fix (logger wrapper) * fix proxy tunnel configuration and make sure it's used in streaming * change some string concatenation expressions to use interpolation * feat: upgrade winston (#189) * fix merge * remove support for indirect/patch and indirect/put (#182) * reuse same Promise and same event listeners for all waitForInitialization calls * better docs for waitForInitialization + misc doc cleanup (#184) * update js-eventsource to 1.3.1 for stream parsing bugfix (#185) * fix broken logger format (#186) * retroactively update changelog for bugfix in 5.13.2 release * allow get/getAll Redis queries to be queued if Redis client hasn't yet connected * set stream read timeout * adding the alias functionality (#190) * Removed the guides link * remove monkey-patching of setImmediate * Persist contextKind property during feature and custom event transformations (#194) * add inlineUsersInEvents option in TypeScript * Add support for seed to bucketUser * Add note for incorporating seed into evaluation * Send events when the evaluation is from an experiment * Use seed to evaluate. * Clean up test descriptions * Rename variable to be less confusing * Use ternary to eliminate mutation * Make return signature more consistent * Un-prettier the tests * redis lower bounds bump (#199) * update launchdarkly-js-test-helpers to fix TLS tests (#200) * update js-eventsource to remove vulnerability warning (#201) * add CI jobs for all compatible Node versions * CI fixes * more CI fixes * comment * use default value to simplify config * (6.0 - #1) stop saying we're compatible with Node <12 (#203) * add CI jobs for all compatible Node versions (#202) * (6.0 - #2) remove Redis integration (#204) * allow feature store to be specified as a factory (so it can get our logger) * (6.0 - #3) remove Winston (#205) * remove deprecated things for 6.0 (#206) * update node-cache to 5.x (drops old Node compat) * update semver to 7.x (drops old Node compat) * update uuid to 8.x (Node compat, perf improvements, bugfixes) * update dev dependencies * linter * replace lrucache package with lru-cache (#209) * make yaml dependency optional (#210) * update release metadata to include maintenance branch * remove package-lock.json (#211) * rm prerelease changelog * (big segments #1) add interfaces for big segments (#212) * (big segments #2) add all components for big segments except evaluation (#213) * (big segments #3) implement big segments in flag evaluation (#214) * (big segments #4) add standard test suite for big segment store tests + refactor feature store tests (#215) * move new interfaces to a module instead of a namespace (#216) * fix TS export of CachingStoreWrapper * use Releaser v2 config * fix overly specific test expectation that breaks in Node 17 * Initial work on FlagBuilder (#219) * Add TestData factory(with some dummy methods); Initial work on FlagBuilder * fixed indentation and linter errors; fixed an error in update; fixed incorrect test label * fixed typo in TestData store * converted boolean variation constants to be file variables instead of class variables Co-authored-by: charukiewicz Co-authored-by: belevy * implemented FlagRuleBuilder; added .build() methods to FlagBuilder/FlagRuleBuilder and changed tests to avoid using private interface * converted _targets to be Map instead of object literal; changed variationForBoolean to be a module-scoped function instead class-scoped * Implement stream processor(data source) interface for test data * Add TestData to index.js and write out the types for TestData and friends * added testdata documentation to index.d.ts; fix linter errors; changed flag default behavior to create boolean flag * Fix the interface file: reindented to 2 spaces, corrected definition of functions from properties to functions in interfaces; corrected issues in JSDoc comments * modify tests to fix capitalization and actually test the test datasource works as an LDClient updateProcessor. * Fix linter error on defaulted callback * explicitly enable JSDOM types in TypeScript build to avoid errors when jsdom is referenced for some reason * capitalize Big Segments in docs & logs * documentation comment fixes for TestData * pin TypeScript to 4.4.x * move TestData and FIleDataSource to integrations module * lint * rename types used by TestData for clarity (#229) * use varargs semantics for TestFlagBuilder.variations() and add it to the TS interface (#230) * don't ever use for...in (#232) * don't ever use for...in * add null guard * bump launchdarkly-eventsource dependency for sc-136154 fix * use TestData in our own tests (#231) * use TestData in our own tests * update TS interface * lint * typo * fix allFlagsState behavior regarding experimentation * lint * allow "secondary" to be referenced in clauses * don't throw an exception for non-string in semver comparison * correctly handle "client not ready" condition in allFlagsState * lint * Flags with a version of 0 reported as 'unknown' in summary events. (#239) * implement contract test service, not including big segments (#242) Co-authored-by: Eli Bishop * Implement Application tags for the node SDK. (#241) * update js-eventsource to 1.4.4 for security fix * remove package-lock.json * adjust test expectation about error message to work in recent Node versions * Adds link to Relay Proxy docs * Update index.d.ts Co-authored-by: Eli Bishop * ensure setTimeout task is cleared when polling is stopped * fix some flaky tests using async blocking logic * rm unused * simplify polling implementation using setInterval * use newer js-test-helpers for async tests * add request number to timeout message * Enforce 64 character limit for application tag values. (#263) * Fixed operator field key name in TestDataRuleBuilder (#246) Co-authored-by: Eli Bishop Co-authored-by: LaunchDarklyCI Co-authored-by: Ben Woskow Co-authored-by: Maxwell Gerber Co-authored-by: Chris West Co-authored-by: Ben Woskow <48036130+bwoskow-ld@users.noreply.github.com> Co-authored-by: Mike Zorn Co-authored-by: Robert J. Neal Co-authored-by: Ben Levy Co-authored-by: charukiewicz Co-authored-by: belevy Co-authored-by: charukiewicz Co-authored-by: LaunchDarklyReleaseBot Co-authored-by: Ryan Lamb <4955475+kinyoklion@users.noreply.github.com> Co-authored-by: Ember Stevens Co-authored-by: Ember Stevens <79482775+ember-stevens@users.noreply.github.com> --- test/test_data-test.js | 33 +++++++++++++++++++++++++++++++-- test_data.js | 13 ++++++++++--- 2 files changed, 41 insertions(+), 5 deletions(-) diff --git a/test/test_data-test.js b/test/test_data-test.js index 6779663..8f428a6 100644 --- a/test/test_data-test.js +++ b/test/test_data-test.js @@ -222,7 +222,7 @@ describe('TestData', function() { { "attribute": "name", "negate": false, - "operator": "in", + "op": "in", "values": [ "ben", "christian", @@ -231,7 +231,7 @@ describe('TestData', function() { { "attribute": "country", "negate": true, - "operator": "in", + "op": "in", "values": [ "fr", ], @@ -243,4 +243,33 @@ describe('TestData', function() { const clearedRulesFlag = flag.clearRules(); expect(clearedRulesFlag.build(0)).not.toHaveProperty('rules'); }); + + it('can add evaluate a rule', async function() { + const td = TestData(); + td.update(td.flag('test-flag') + .fallthroughVariation(false) + .ifMatch('name', 'ben', 'christian') + .andNotMatch('country', 'fr') + .thenReturn(true)); + + const store = InMemoryFeatureStore(); + const client = LDClient.init('sdk_key', { featureStore: store, updateProcessor: td, sendEvents: false }); + + + // User1 should pass because matching name and not matching country + const user1 = { 'key': 'user1', 'name': 'christian', 'country': 'us' }; + const eval1 = await client.variationDetail('test-flag', user1, 'default' ); + + expect(eval1.value).toEqual(true); + expect(eval1.variationIndex).toEqual(0); + expect(eval1.reason.kind).toEqual('RULE_MATCH'); + + // User2 should NOT pass because matching name but incorrectly matching country + const user2 = { 'key': 'user2', 'name': 'ben', 'country': 'fr' }; + const eval2 = await client.variationDetail('test-flag', user2, 'default' ); + + expect(eval2.value).toEqual(false); + expect(eval2.variationIndex).toEqual(1); + expect(eval2.reason.kind).toEqual('FALLTHROUGH'); + }); }); diff --git a/test_data.js b/test_data.js index 50d72fc..d39aa67 100644 --- a/test_data.js +++ b/test_data.js @@ -97,7 +97,7 @@ TestDataFlagBuilder.prototype.copy = function () { to._on = this._on; to._fallthroughVariation = this._fallthroughVariation; to._targets = !this._targets ? null : new Map(this._targets); - to._rules = !this._rules ? null : JSON.parse(JSON.stringify(this._rules)); + to._rules = !this._rules ? null : this._rules.map(r => r.copy(this)); return to; }; @@ -259,7 +259,7 @@ function TestDataRuleBuilder(flagBuilder) { TestDataRuleBuilder.prototype.andMatch = function (attribute, ...values) { this._clauses.push({ attribute: attribute, - operator: 'in', + op: 'in', values: values, negate: false, }); @@ -269,7 +269,7 @@ TestDataRuleBuilder.prototype.andMatch = function (attribute, ...values) { TestDataRuleBuilder.prototype.andNotMatch = function (attribute, ...values) { this._clauses.push({ attribute: attribute, - operator: 'in', + op: 'in', values: values, negate: true, }); @@ -295,4 +295,11 @@ TestDataRuleBuilder.prototype.build = function (id) { }; }; +TestDataRuleBuilder.prototype.copy = function (flagBuilder) { + const flagRuleBuilder = new TestDataRuleBuilder(flagBuilder); + flagRuleBuilder._clauses = JSON.parse(JSON.stringify(this._clauses)); + flagRuleBuilder._variation = JSON.parse(JSON.stringify(this._variation)); + return flagRuleBuilder; +}; + module.exports = TestData;