From 27c9efbbab66d91b7c3c555678cb25c8816bfb75 Mon Sep 17 00:00:00 2001 From: Benjamin Patterson Date: Tue, 27 Jul 2021 15:37:59 -0700 Subject: [PATCH] Fix issue where data isn't overwritten with multiple calls to setup --- lib/brie.js | 2 +- test/helpers/setup.js | 36 ++++++++++++++++++++++++++++++++++++ 2 files changed, 37 insertions(+), 1 deletion(-) diff --git a/lib/brie.js b/lib/brie.js index 8dda426..033c451 100644 --- a/lib/brie.js +++ b/lib/brie.js @@ -38,7 +38,7 @@ const brie = module.exports = (function () { Object.assign(functionalCriteria, optCriteria); features = optFeatures; overrides = optOverrides; - Object.assign(data, optContext); + data = optContext rulesEngine.setup({ criteria: functionalCriteria, features: features diff --git a/test/helpers/setup.js b/test/helpers/setup.js index a2deb60..602e189 100644 --- a/test/helpers/setup.js +++ b/test/helpers/setup.js @@ -125,5 +125,41 @@ module.exports = function () { }); assert(!!(bSetup)); }); + + it("replaces data when called twice", function () { + const fakeNumber = '8675309' + const features = { + allowId:{ + criteria: [{ + allowValues: { + trait: "aId", + values: [ + fakeNumber + ] + } + }] + } + } + + const b1 = brie.setup({ + data: { + aId: fakeNumber + }, + overrides: {}, + features, + }); + + assert.deepEqual(b1.get('allowId'), true) + + const b2 = b1.setup({ + data: { + wrongId: "555555" + }, + overrides: {}, + features, + }); + + assert.deepEqual(b2.get('allowId'), false) + }) }); };