Skip to content

Commit d3a1289

Browse files
destrutcure config in tests and add inlocalstorage
1 parent cf950bc commit d3a1289

File tree

2 files changed

+100
-40
lines changed

2 files changed

+100
-40
lines changed

src/__tests__/browserSuites/evaluations-fallback.spec.js

Lines changed: 99 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,11 @@ const listener = {
55
logImpression: sinon.stub()
66
};
77

8-
export default function (baseConfig, fetchMock, assert) {
8+
export default function (configInMemory, configInLocalStorage, fetchMock, assert) {
99

1010
assert.test('FallbackTreatment / Split factory with no fallbackTreatment defined', async t => {
1111

12-
const splitio = SplitFactory(baseConfig);
12+
const splitio = SplitFactory(configInMemory);
1313
const client = splitio.client();
1414

1515
await client.whenReady();
@@ -24,9 +24,11 @@ export default function (baseConfig, fetchMock, assert) {
2424

2525
assert.test('FallbackTreatment / Split factory with global fallbackTreatment defined', async t => {
2626

27-
const config = Object.assign({}, baseConfig);
28-
config.fallbackTreatments = {
29-
global: 'FALLBACK_TREATMENT'
27+
const config = {
28+
...configInMemory,
29+
fallbackTreatments: {
30+
global: 'FALLBACK_TREATMENT'
31+
}
3032
};
3133
const splitio = SplitFactory(config);
3234
const client = splitio.client();
@@ -44,10 +46,12 @@ export default function (baseConfig, fetchMock, assert) {
4446

4547
assert.test('FallbackTreatment / Split factory with specific fallbackTreatment defined', async t => {
4648

47-
const config = Object.assign({}, baseConfig);
48-
config.fallbackTreatments = {
49-
byFlag: {
50-
'non_existent_flag': 'FALLBACK_TREATMENT',
49+
const config = {
50+
...configInMemory,
51+
fallbackTreatments: {
52+
byFlag: {
53+
'non_existent_flag': 'FALLBACK_TREATMENT',
54+
}
5155
}
5256
};
5357
const splitio = SplitFactory(config);
@@ -69,11 +73,13 @@ export default function (baseConfig, fetchMock, assert) {
6973

7074
assert.test('FallbackTreatment / flag override beats global fallbackTreatment', async t => {
7175

72-
const config = Object.assign({}, baseConfig);
73-
config.fallbackTreatments = {
74-
global: 'OFF_FALLBACK',
75-
byFlag: {
76-
'my_flag': 'ON_FALLBACK',
76+
const config = {
77+
...configInMemory,
78+
fallbackTreatments: {
79+
global: 'OFF_FALLBACK',
80+
byFlag: {
81+
'my_flag': 'ON_FALLBACK',
82+
}
7783
}
7884
};
7985
const splitio = SplitFactory(config);
@@ -94,9 +100,11 @@ export default function (baseConfig, fetchMock, assert) {
94100

95101
assert.test('FallbackTreatment / override applies only when original is control', async t => {
96102

97-
const config = Object.assign({}, baseConfig);
98-
config.fallbackTreatments = {
99-
global: 'OFF_FALLBACK'
103+
const config = {
104+
...configInMemory,
105+
fallbackTreatments: {
106+
global: 'OFF_FALLBACK'
107+
}
100108
};
101109
const splitio = SplitFactory(config);
102110
const client = splitio.client();
@@ -111,15 +119,39 @@ export default function (baseConfig, fetchMock, assert) {
111119

112120
});
113121

114-
assert.test('FallbackTreatment / Impressions correctness with fallback when client is not ready', async t => {
115122

116-
const config = Object.assign({}, baseConfig);
117-
config.urls = {
118-
events: 'https://events.fallbacktreatment/api'
123+
assert.test('FallbackTreatment / override applies only when original is control - inLocalStorage', async t => {
124+
125+
const config = {
126+
...configInLocalStorage,
127+
fallbackTreatments: {
128+
global: 'OFF_FALLBACK'
129+
}
119130
};
120-
config.fallbackTreatments = {
121-
byFlag: {
122-
'any_flag': 'OFF_FALLBACK'
131+
const splitio = SplitFactory(config);
132+
const client = splitio.client();
133+
134+
await client.whenReady();
135+
136+
t.equal(client.getTreatment('user_account_in_whitelist'), 'off', 'The evaluation will return the treatment defined in the flag if it exists');
137+
t.equal(client.getTreatment('non_existent_flag'), 'OFF_FALLBACK', 'The evaluation will return `OFF_FALLBACK` if the flag does not exist and no fallbackTreatment is defined');
138+
139+
await client.destroy();
140+
t.end();
141+
142+
});
143+
144+
assert.test('FallbackTreatment / Impressions correctness with fallback when client is not ready', async t => {
145+
146+
const config = {
147+
...configInMemory,
148+
urls: {
149+
events: 'https://events.fallbacktreatment/api'
150+
},
151+
fallbackTreatments: {
152+
byFlag: {
153+
'any_flag': 'OFF_FALLBACK'
154+
}
123155
}
124156
};
125157
const splitio = SplitFactory(config);
@@ -153,11 +185,13 @@ export default function (baseConfig, fetchMock, assert) {
153185

154186
assert.test('FallbackTreatment / Fallback dynamic config propagation', async t => {
155187

156-
const config = Object.assign({}, baseConfig);
157-
config.fallbackTreatments = {
158-
global: { treatment: 'OFF_FALLBACK', config: '{"global": true}' },
159-
byFlag: {
160-
'my_flag': { treatment: 'ON_FALLBACK', config: '{"flag": true}' }
188+
const config = {
189+
...configInMemory,
190+
fallbackTreatments: {
191+
global: { treatment: 'OFF_FALLBACK', config: '{"global": true}' },
192+
byFlag: {
193+
'my_flag': { treatment: 'ON_FALLBACK', config: '{"flag": true}' }
194+
}
161195
}
162196
};
163197
const splitio = SplitFactory(config);
@@ -173,16 +207,42 @@ export default function (baseConfig, fetchMock, assert) {
173207

174208
});
175209

176-
assert.test('FallbackTreatment / Evaluations non existing flags with fallback do not generate impressions', async t => {
210+
assert.test('FallbackTreatment / Fallback dynamic config propagation - inLocalStorage', async t => {
177211

178-
const config = Object.assign({}, baseConfig);
179-
config.urls = {
180-
events: 'https://events.fallbacktreatment/api'
212+
const config = {
213+
...configInLocalStorage,
214+
fallbackTreatments: {
215+
global: { treatment: 'OFF_FALLBACK', config: '{"global": true}' },
216+
byFlag: {
217+
'my_flag': { treatment: 'ON_FALLBACK', config: '{"flag": true}' }
218+
}
219+
}
181220
};
182-
config.fallbackTreatments = {
183-
global: { treatment: 'OFF_FALLBACK', config: '{"global": true}' },
184-
byFlag: {
185-
'my_flag': { treatment: 'ON_FALLBACK', config: '{"flag": true}' }
221+
const splitio = SplitFactory(config);
222+
const client = splitio.client();
223+
224+
await client.whenReady();
225+
226+
t.deepEqual(client.getTreatmentWithConfig('my_flag'), { treatment: 'ON_FALLBACK', config: '{"flag": true}' }, 'The evaluation will propagate the config along with the treatment from the fallbackTreatment');
227+
t.deepEqual(client.getTreatmentWithConfig('non_existent_flag'), { treatment: 'OFF_FALLBACK', config: '{"global": true}' }, 'The evaluation will propagate the config along with the treatment from the fallbackTreatment');
228+
229+
await client.destroy();
230+
t.end();
231+
232+
});
233+
234+
assert.test('FallbackTreatment / Evaluations non existing flags with fallback do not generate impressions', async t => {
235+
236+
const config = {
237+
...configInMemory,
238+
urls: {
239+
events: 'https://events.fallbacktreatment/api'
240+
},
241+
fallbackTreatments: {
242+
global: { treatment: 'OFF_FALLBACK', config: '{"global": true}' },
243+
byFlag: {
244+
'my_flag': { treatment: 'ON_FALLBACK', config: '{"flag": true}' }
245+
}
186246
}
187247
};
188248
config.impressionListener = listener;
@@ -229,9 +289,9 @@ export default function (baseConfig, fetchMock, assert) {
229289
assert.test('FallbackTreatment / LocalhostMode', async t => {
230290

231291
const config = {
232-
...baseConfig,
292+
...configInMemory,
233293
core: {
234-
...baseConfig.core,
294+
...configInMemory.core,
235295
authorizationKey: 'localhost',
236296
},
237297
fallbackTreatments: {

src/__tests__/online/browser.spec.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ tape('## E2E CI Tests ##', function (assert) {
9898

9999
/* Check client evaluations. */
100100
assert.test('E2E / In Memory', evaluationsSuite.bind(null, configInMemory, fetchMock));
101-
assert.test('E2E / In Memory Fallback', evaluationsFallbackSuite.bind(null, configInMemory, fetchMock));
101+
assert.test('E2E / In Memory Fallback', evaluationsFallbackSuite.bind(null, configInMemory, configInLocalStorage, fetchMock));
102102
assert.test('E2E / In Memory with Bucketing Key', evaluationsSuite.bind(null, configInMemoryWithBucketingKey, fetchMock));
103103
assert.test('E2E / In LocalStorage with In Memory Fallback', evaluationsSuite.bind(null, configInLocalStorage, fetchMock));
104104
/* Check impressions */

0 commit comments

Comments
 (0)