Skip to content

Commit d08d18f

Browse files
[FME-4362] update sdk version and add support for evaluation options
1 parent 14bfd95 commit d08d18f

15 files changed

Lines changed: 648 additions & 253 deletions

client/__tests__/allTreatments.test.js

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -259,4 +259,44 @@ describe('get-all-treatments', () => {
259259
.set('Authorization', 'test');
260260
expectOkAllTreatments(response, 200, expected, 2);
261261
});
262+
263+
test('should be 400 if options.properties is invalid (GET)', async () => {
264+
const expected = [
265+
'options.properties must only contain boolean, string, or number values.'
266+
];
267+
const response = await request(app)
268+
.get('/client/get-all-treatments?keys=[{"matchingKey":"test","trafficType":"localhost"}]&options={"properties":{"invalid":[1,2,3]}}')
269+
.set('Authorization', 'test');
270+
expectErrorContaining(response, 400, expected);
271+
});
272+
273+
test('should be 400 if options.properties is invalid (POST)', async () => {
274+
const expected = [
275+
'options.properties must only contain boolean, string, or number values.'
276+
];
277+
const response = await request(app)
278+
.post('/client/get-all-treatments?keys=[{"matchingKey":"test","trafficType":"localhost"}]')
279+
.send({
280+
options: { properties: { invalid: [1, 2, 3] } },
281+
})
282+
.set('Authorization', 'test');
283+
expectErrorContaining(response, 400, expected);
284+
});
285+
286+
test('should be 200 if options.properties is valid (GET)', async () => {
287+
const response = await request(app)
288+
.get('/client/get-all-treatments?keys=[{"matchingKey":"test","trafficType":"localhost"}]&options={"properties":{"package":"premium","admin":true,"discount":50}}')
289+
.set('Authorization', 'test');
290+
expect(response.status).toBe(200);
291+
});
292+
293+
test('should be 200 if options.properties is valid (POST)', async () => {
294+
const response = await request(app)
295+
.post('/client/get-all-treatments?keys=[{"matchingKey":"test","trafficType":"localhost"}]')
296+
.send({
297+
options: { properties: { package: 'premium', admin: true, discount: 50 } },
298+
})
299+
.set('Authorization', 'test');
300+
expect(response.status).toBe(200);
301+
});
262302
});

client/__tests__/allTreatmentsWithConfig.test.js

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -267,4 +267,44 @@ describe('get-all-treatments-with-config', () => {
267267
.set('Authorization', 'test');
268268
expectOkAllTreatments(response, 200, expected, 2);
269269
});
270+
271+
test('should be 400 if options.properties is invalid (GET)', async () => {
272+
const expected = [
273+
'options.properties must only contain boolean, string, or number values.'
274+
];
275+
const response = await request(app)
276+
.get('/client/get-all-treatments-with-config?keys=[{"matchingKey":"test","trafficType":"localhost"}]&options={"properties":{"invalid":[1,2,3]}}')
277+
.set('Authorization', 'test');
278+
expectErrorContaining(response, 400, expected);
279+
});
280+
281+
test('should be 400 if options.properties is invalid (POST)', async () => {
282+
const expected = [
283+
'options.properties must only contain boolean, string, or number values.'
284+
];
285+
const response = await request(app)
286+
.post('/client/get-all-treatments-with-config?keys=[{"matchingKey":"test","trafficType":"localhost"}]')
287+
.send({
288+
options: { properties: { invalid: [1, 2, 3] } },
289+
})
290+
.set('Authorization', 'test');
291+
expectErrorContaining(response, 400, expected);
292+
});
293+
294+
test('should be 200 if options.properties is valid (GET)', async () => {
295+
const response = await request(app)
296+
.get('/client/get-all-treatments-with-config?keys=[{"matchingKey":"test","trafficType":"localhost"}]&options={"properties":{"package":"premium","admin":true,"discount":50}}')
297+
.set('Authorization', 'test');
298+
expect(response.status).toBe(200);
299+
});
300+
301+
test('should be 200 if options.properties is valid (POST)', async () => {
302+
const response = await request(app)
303+
.post('/client/get-all-treatments-with-config?keys=[{"matchingKey":"test","trafficType":"localhost"}]')
304+
.send({
305+
options: { properties: { package: 'premium', admin: true, discount: 50 } },
306+
})
307+
.set('Authorization', 'test');
308+
expect(response.status).toBe(200);
309+
});
270310
});

client/__tests__/treatment.test.js

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -247,4 +247,44 @@ describe('get-treatment', () => {
247247
.set('Authorization', 'test');
248248
expectOk(response, 200, 'control', 'nonexistant-experiment');
249249
});
250+
251+
test('should be 400 if options.properties is invalid (GET)', async () => {
252+
const expected = [
253+
'options.properties must only contain boolean, string, or number values.'
254+
];
255+
const response = await request(app)
256+
.get('/client/get-treatment?key=test&split-name=my-experiment&options={"properties":{"invalid":[1,2,3]}}')
257+
.set('Authorization', 'test');
258+
expectErrorContaining(response, 400, expected);
259+
});
260+
261+
test('should be 400 if options.properties is invalid (POST)', async () => {
262+
const expected = [
263+
'options.properties must only contain boolean, string, or number values.'
264+
];
265+
const response = await request(app)
266+
.post('/client/get-treatment?key=test&split-name=my-experiment')
267+
.send({
268+
options: { properties: { invalid: [1, 2, 3] } },
269+
})
270+
.set('Authorization', 'test');
271+
expectErrorContaining(response, 400, expected);
272+
});
273+
274+
test('should be 200 if options.properties is valid (GET)', async () => {
275+
const response = await request(app)
276+
.get('/client/get-treatment?key=test&split-name=my-experiment&options={"properties":{"package":"premium","admin":true,"discount":50}}')
277+
.set('Authorization', 'test');
278+
expectOk(response, 200, 'on', 'my-experiment');
279+
});
280+
281+
test('should be 200 if options.properties is valid (POST)', async () => {
282+
const response = await request(app)
283+
.post('/client/get-treatment?key=test&split-name=my-experiment')
284+
.send({
285+
options: { properties: { package: 'premium', admin: true, discount: 50 } },
286+
})
287+
.set('Authorization', 'test');
288+
expectOk(response, 200, 'on', 'my-experiment');
289+
});
250290
});

client/__tests__/treatmentWithConfig.test.js

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -229,4 +229,44 @@ describe('get-treatment-with-config', () => {
229229
.set('Authorization', 'test');
230230
expectOk(response, 200, 'control', 'nonexistant-experiment', null);
231231
});
232+
233+
test('should be 400 if options.properties is invalid (GET)', async () => {
234+
const expected = [
235+
'options.properties must only contain boolean, string, or number values.'
236+
];
237+
const response = await request(app)
238+
.get('/client/get-treatment-with-config?key=test&split-name=my-experiment&options={"properties":{"invalid":[1,2,3]}}')
239+
.set('Authorization', 'test');
240+
expectErrorContaining(response, 400, expected);
241+
});
242+
243+
test('should be 400 if options.properties is invalid (POST)', async () => {
244+
const expected = [
245+
'options.properties must only contain boolean, string, or number values.'
246+
];
247+
const response = await request(app)
248+
.post('/client/get-treatment-with-config?key=test&split-name=my-experiment')
249+
.send({
250+
options: { properties: { invalid: [1, 2, 3] } },
251+
})
252+
.set('Authorization', 'test');
253+
expectErrorContaining(response, 400, expected);
254+
});
255+
256+
test('should be 200 if options.properties is valid (GET)', async () => {
257+
const response = await request(app)
258+
.get('/client/get-treatment-with-config?key=test&split-name=my-experiment&options={"properties":{"package":"premium","admin":true,"discount":50}}')
259+
.set('Authorization', 'test');
260+
expectOk(response, 200, 'on', 'my-experiment', '{"desc" : "this applies only to ON treatment"}');
261+
});
262+
263+
test('should be 200 if options.properties is valid (POST)', async () => {
264+
const response = await request(app)
265+
.post('/client/get-treatment-with-config?key=test&split-name=my-experiment')
266+
.send({
267+
options: { properties: { package: 'premium', admin: true, discount: 50 } },
268+
})
269+
.set('Authorization', 'test');
270+
expectOk(response, 200, 'on', 'my-experiment', '{"desc" : "this applies only to ON treatment"}');
271+
});
232272
});

client/__tests__/treatments.test.js

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -267,4 +267,52 @@ describe('get-treatments', () => {
267267
},
268268
}, 3);
269269
});
270+
271+
test('should be 400 if options.properties is invalid (GET)', async () => {
272+
const expected = [
273+
'options.properties must only contain boolean, string, or number values.'
274+
];
275+
const response = await request(app)
276+
.get('/client/get-treatments?key=test&split-names=my-experiment&options={"properties":{"invalid":[1,2,3]}}')
277+
.set('Authorization', 'test');
278+
expectErrorContaining(response, 400, expected);
279+
});
280+
281+
test('should be 400 if options.properties is invalid (POST)', async () => {
282+
const expected = [
283+
'options.properties must only contain boolean, string, or number values.'
284+
];
285+
const response = await request(app)
286+
.post('/client/get-treatments?key=test&split-names=my-experiment')
287+
.send({
288+
options: { properties: { invalid: [1, 2, 3] } },
289+
})
290+
.set('Authorization', 'test');
291+
expectErrorContaining(response, 400, expected);
292+
});
293+
294+
test('should be 200 if options.properties is valid (GET)', async () => {
295+
const response = await request(app)
296+
.get('/client/get-treatments?key=test&split-names=my-experiment&options={"properties":{"package":"premium","admin":true,"discount":50}}')
297+
.set('Authorization', 'test');
298+
expectOkMultipleResults(response, 200, {
299+
'my-experiment': {
300+
treatment: 'on',
301+
},
302+
}, 1);
303+
});
304+
305+
test('should be 200 if options.properties is valid (POST)', async () => {
306+
const response = await request(app)
307+
.post('/client/get-treatments?key=test&split-names=my-experiment')
308+
.send({
309+
options: { properties: { package: 'premium', admin: true, discount: 50 } },
310+
})
311+
.set('Authorization', 'test');
312+
expectOkMultipleResults(response, 200, {
313+
'my-experiment': {
314+
treatment: 'on',
315+
},
316+
}, 1);
317+
});
270318
});

client/__tests__/treatmentsByFlagSets.test.js

Lines changed: 41 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ const { expectedGreenResults, expectedPurpleResults, expectedPinkResults } = req
77
jest.mock('node-fetch', () => {
88
return jest.fn().mockImplementation((url) => {
99

10-
const sdkUrl = 'https://sdk.test.io/api/splitChanges?s=1.1&since=-1';
10+
const sdkUrl = 'https://sdk.test.io/api/splitChanges?s=1.3&since=-1';
1111
const splitChange2 = require('../../utils/mocks/splitchanges.since.-1.till.1602796638344.json');
1212
if (url.startsWith(sdkUrl)) return Promise.resolve({ status: 200, json: () => (splitChange2), ok: true });
1313

@@ -273,4 +273,44 @@ describe('get-treatments-by-sets', () => {
273273
.set('Authorization', 'key_pink');
274274
expectOkMultipleResults(response, 200, expectedPinkResults, 5);
275275
});
276+
277+
test('should be 400 if options.properties is invalid (GET)', async () => {
278+
const expected = [
279+
'options.properties must only contain boolean, string, or number values.'
280+
];
281+
const response = await request(app)
282+
.get('/client/get-treatments-by-sets?key=test&flag-sets=set_green&options={"properties":{"invalid":[1,2,3]}}')
283+
.set('Authorization', 'key_green');
284+
expectErrorContaining(response, 400, expected);
285+
});
286+
287+
test('should be 400 if options.properties is invalid (POST)', async () => {
288+
const expected = [
289+
'options.properties must only contain boolean, string, or number values.'
290+
];
291+
const response = await request(app)
292+
.post('/client/get-treatments-by-sets?key=test&flag-sets=set_green')
293+
.send({
294+
options: { properties: { invalid: [1, 2, 3] } },
295+
})
296+
.set('Authorization', 'key_green');
297+
expectErrorContaining(response, 400, expected);
298+
});
299+
300+
test('should be 200 if options.properties is valid (GET)', async () => {
301+
const response = await request(app)
302+
.get('/client/get-treatments-by-sets?key=test&flag-sets=set_green&options={"properties":{"package":"premium","admin":true,"discount":50}}')
303+
.set('Authorization', 'key_green');
304+
expect(response.status).toBe(200);
305+
});
306+
307+
test('should be 200 if options.properties is valid (POST)', async () => {
308+
const response = await request(app)
309+
.post('/client/get-treatments-by-sets?key=test&flag-sets=set_green')
310+
.send({
311+
options: { properties: { package: 'premium', admin: true, discount: 50 } },
312+
})
313+
.set('Authorization', 'key_green');
314+
expect(response.status).toBe(200);
315+
});
276316
});

client/__tests__/treatmentsWithConfig.test.js

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -252,4 +252,54 @@ describe('get-treatments-with-config', () => {
252252
},
253253
}, 3);
254254
});
255+
256+
test('should be 400 if options.properties is invalid (GET)', async () => {
257+
const expected = [
258+
'options.properties must only contain boolean, string, or number values.'
259+
];
260+
const response = await request(app)
261+
.get('/client/get-treatments-with-config?key=test&split-names=my-experiment&options={"properties":{"invalid":[1,2,3]}}')
262+
.set('Authorization', 'test');
263+
expectErrorContaining(response, 400, expected);
264+
});
265+
266+
test('should be 400 if options.properties is invalid (POST)', async () => {
267+
const expected = [
268+
'options.properties must only contain boolean, string, or number values.'
269+
];
270+
const response = await request(app)
271+
.post('/client/get-treatments-with-config?key=test&split-names=my-experiment')
272+
.send({
273+
options: { properties: { invalid: [1, 2, 3] } },
274+
})
275+
.set('Authorization', 'test');
276+
expectErrorContaining(response, 400, expected);
277+
});
278+
279+
test('should be 200 if options.properties is valid (GET)', async () => {
280+
const response = await request(app)
281+
.get('/client/get-treatments-with-config?key=test&split-names=my-experiment&options={"properties":{"package":"premium","admin":true,"discount":50}}')
282+
.set('Authorization', 'test');
283+
expectOkMultipleResults(response, 200, {
284+
'my-experiment': {
285+
treatment: 'on',
286+
config: '{"desc" : "this applies only to ON treatment"}',
287+
},
288+
}, 1);
289+
});
290+
291+
test('should be 200 if options.properties is valid (POST)', async () => {
292+
const response = await request(app)
293+
.post('/client/get-treatments-with-config?key=test&split-names=my-experiment')
294+
.send({
295+
options: { properties: { package: 'premium', admin: true, discount: 50 } },
296+
})
297+
.set('Authorization', 'test');
298+
expectOkMultipleResults(response, 200, {
299+
'my-experiment': {
300+
treatment: 'on',
301+
config: '{"desc" : "this applies only to ON treatment"}',
302+
},
303+
}, 1);
304+
});
255305
});

client/__tests__/treatmentsWithConfigByFlagSets.test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ const { expectedGreenResultsWithConfig, expectedPurpleResultsWithConfig, expecte
66

77
jest.mock('node-fetch', () => {
88
return jest.fn().mockImplementation((url) => {
9-
const sdkUrl = 'https://sdk.test.io/api/splitChanges?s=1.1&since=-1';
9+
const sdkUrl = 'https://sdk.test.io/api/splitChanges?s=1.3&since=-1';
1010
const splitChange2 = require('../../utils/mocks/splitchanges.since.-1.till.1602796638344.json');
1111
if (url.startsWith(sdkUrl)) return Promise.resolve({ status: 200, json: () => (splitChange2), ok: true});
1212
return Promise.resolve({ status: 200, json: () => ({}), ok: true });

0 commit comments

Comments
 (0)