Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion CHANGES.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
- Updated base image to node:24.3.0-alpine3.21

2.7.1 (Jun 25, 2025)
- Fixed OpenAPI spec fot /manager/splits
- Fixed OpenAPI spec for /manager/splits
- Updated base image to node:24.2.0-alpine3.22

2.7.0 (Dec 20, 2024)
Expand Down
25 changes: 21 additions & 4 deletions client/__tests__/allTreatments.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -260,18 +260,35 @@ describe('get-all-treatments', () => {
expectOkAllTreatments(response, 200, expected, 2);
});

test('should be 200 if options.properties is valid (GET)', async () => {
test('should be 200 if properties is valid (GET)', async () => {
const response = await request(app)
.get('/client/get-all-treatments?keys=[{"matchingKey":"test","trafficType":"localhost"}]&options={"properties":{"package":"premium","admin":true,"discount":50}}')
.get('/client/get-all-treatments?keys=[{"matchingKey":"test","trafficType":"localhost"}]&properties={"package":"premium","admin":true,"discount":50}')
.set('Authorization', 'test');
expect(response.status).toBe(200);
});

test('should be 200 if options.properties is valid (POST)', async () => {
test('should be 200 if properties is valid (POST)', async () => {
const response = await request(app)
.post('/client/get-all-treatments?keys=[{"matchingKey":"test","trafficType":"localhost"}]')
.send({
options: { properties: { package: 'premium', admin: true, discount: 50 } },
properties: { package: 'premium', admin: true, discount: 50 },
})
.set('Authorization', 'test');
expect(response.status).toBe(200);
});

test('should be 200 if properties is invalid (GET)', async () => {
const response = await request(app)
.get('/client/get-all-treatments?keys=[{"matchingKey":"test","trafficType":"localhost"}]&properties={"foo": {"bar": 1}}')
.set('Authorization', 'test');
expect(response.status).toBe(200);
});

test('should be 200 if properties is invalid (POST)', async () => {
const response = await request(app)
.post('/client/get-all-treatments?keys=[{"matchingKey":"test","trafficType":"localhost"}]')
.send({
properties: { foo: { bar: 1 } },
})
.set('Authorization', 'test');
expect(response.status).toBe(200);
Expand Down
25 changes: 21 additions & 4 deletions client/__tests__/allTreatmentsWithConfig.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -268,18 +268,35 @@ describe('get-all-treatments-with-config', () => {
expectOkAllTreatments(response, 200, expected, 2);
});

test('should be 200 if options.properties is valid (GET)', async () => {
test('should be 200 if properties is valid (GET)', async () => {
const response = await request(app)
.get('/client/get-all-treatments-with-config?keys=[{"matchingKey":"test","trafficType":"localhost"}]&options={"properties":{"package":"premium","admin":true,"discount":50}}')
.get('/client/get-all-treatments-with-config?keys=[{"matchingKey":"test","trafficType":"localhost"}]&properties={"package":"premium","admin":true,"discount":50}')
.set('Authorization', 'test');
expect(response.status).toBe(200);
});

test('should be 200 if options.properties is valid (POST)', async () => {
test('should be 200 if properties is valid (POST)', async () => {
const response = await request(app)
.post('/client/get-all-treatments-with-config?keys=[{"matchingKey":"test","trafficType":"localhost"}]')
.send({
options: { properties: { package: 'premium', admin: true, discount: 50 } },
properties: { package: 'premium', admin: true, discount: 50 },
})
.set('Authorization', 'test');
expect(response.status).toBe(200);
});

test('should be 200 if properties is invalid (GET)', async () => {
const response = await request(app)
.get('/client/get-all-treatments-with-config?keys=[{"matchingKey":"test","trafficType":"localhost"}]&properties={"foo": {"bar": 1}}')
.set('Authorization', 'test');
expect(response.status).toBe(200);
});

test('should be 200 if properties is invalid (POST)', async () => {
const response = await request(app)
.post('/client/get-all-treatments-with-config?keys=[{"matchingKey":"test","trafficType":"localhost"}]')
.send({
properties: { foo: { bar: 1 } },
})
.set('Authorization', 'test');
expect(response.status).toBe(200);
Expand Down
12 changes: 6 additions & 6 deletions client/__tests__/track.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ process.env.SPLIT_EVALUATOR_API_KEY = 'localhost';
const request = require('supertest');
const app = require('../../app');
const { expectError, expectErrorContaining, getLongKey } = require('../../utils/testWrapper');
const { PROPERTIES_WARNING } = require('../../utils/constants');

describe('track', () => {
// Testing authorization
Expand Down Expand Up @@ -143,22 +144,21 @@ describe('track', () => {
expectErrorContaining(response, 400, expected);
});

test('should be 400 if properties is invalid', async () => {
const expected = [
'properties must be a plain object with only boolean, string, number or null values.'
];
test('should be 200 if properties is invalid', async () => {
const logSpy = jest.spyOn(console, 'log').mockImplementation(() => {});
const response = await request(app)
.get('/client/track?key=my-key&event-type=my-event&traffic-type=my-traffic&value=1&properties=lalala')
.set('Authorization', 'test');
expectErrorContaining(response, 400, expected);
expect(response.statusCode).toBe(200);
expect(logSpy).toHaveBeenCalledWith(PROPERTIES_WARNING);
logSpy.mockRestore();
});

test('should be 400 if there are multiple errors in every input', async () => {
const expected = [
'key too long, key must be 250 characters or less.',
'you passed "@!test", event-type must adhere to the regular expression /^[a-zA-Z0-9][-_.:a-zA-Z0-9]{0,79}$/g. This means an event_type must be alphanumeric, cannot be more than 80 characters long, and can only include a dash, underscore, period, or colon as separators of alphanumeric characters.',
'you passed an empty traffic-type, traffic-type must be a non-empty string.',
'properties must be a plain object with only boolean, string, number or null values.',
'value must be null or number.'
];
const key = getLongKey();
Expand Down
25 changes: 21 additions & 4 deletions client/__tests__/treatment.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -248,18 +248,35 @@ describe('get-treatment', () => {
expectOk(response, 200, 'control', 'nonexistant-experiment');
});

test('should be 200 if options.properties is valid (GET)', async () => {
test('should be 200 if properties is valid (GET)', async () => {
const response = await request(app)
.get('/client/get-treatment?key=test&split-name=my-experiment&options={"properties":{"package":"premium","admin":true,"discount":50}}')
.get('/client/get-treatment?key=test&split-name=my-experiment&properties={"package":"premium","admin":true,"discount":50}')
.set('Authorization', 'test');
expectOk(response, 200, 'on', 'my-experiment');
});

test('should be 200 if options.properties is valid (POST)', async () => {
test('should be 200 if properties is valid (POST)', async () => {
const response = await request(app)
.post('/client/get-treatment?key=test&split-name=my-experiment')
.send({
options: { properties: { package: 'premium', admin: true, discount: 50 } },
properties: { package: 'premium', admin: true, discount: 50 },
})
.set('Authorization', 'test');
expectOk(response, 200, 'on', 'my-experiment');
});

test('should be 200 if properties is invalid (GET)', async () => {
const response = await request(app)
.get('/client/get-treatment?key=test&split-name=my-experiment&properties={"foo": {"bar": 1}}')
.set('Authorization', 'test');
expectOk(response, 200, 'on', 'my-experiment');
});

test('should be 200 if properties is invalid (POST)', async () => {
const response = await request(app)
.post('/client/get-treatment?key=test&split-name=my-experiment')
.send({
properties: { foo: { bar: 1 } },
})
.set('Authorization', 'test');
expectOk(response, 200, 'on', 'my-experiment');
Expand Down
25 changes: 21 additions & 4 deletions client/__tests__/treatmentWithConfig.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -230,18 +230,35 @@ describe('get-treatment-with-config', () => {
expectOk(response, 200, 'control', 'nonexistant-experiment', null);
});

test('should be 200 if options.properties is valid (GET)', async () => {
test('should be 200 if properties is valid (GET)', async () => {
const response = await request(app)
.get('/client/get-treatment-with-config?key=test&split-name=my-experiment&options={"properties":{"package":"premium","admin":true,"discount":50}}')
.get('/client/get-treatment-with-config?key=test&split-name=my-experiment&properties={"package":"premium","admin":true,"discount":50}')
.set('Authorization', 'test');
expectOk(response, 200, 'on', 'my-experiment', '{"desc" : "this applies only to ON treatment"}');
});

test('should be 200 if options.properties is valid (POST)', async () => {
test('should be 200 if properties is valid (POST)', async () => {
const response = await request(app)
.post('/client/get-treatment-with-config?key=test&split-name=my-experiment')
.send({
options: { properties: { package: 'premium', admin: true, discount: 50 } },
properties: { package: 'premium', admin: true, discount: 50 },
})
.set('Authorization', 'test');
expectOk(response, 200, 'on', 'my-experiment', '{"desc" : "this applies only to ON treatment"}');
});

test('should be 200 if properties is invalid (GET)', async () => {
const response = await request(app)
.get('/client/get-treatment-with-config?key=test&split-name=my-experiment&properties={"foo": {"bar": 1}}')
.set('Authorization', 'test');
expectOk(response, 200, 'on', 'my-experiment', '{"desc" : "this applies only to ON treatment"}');
});

test('should be 200 if properties is invalid (POST)', async () => {
const response = await request(app)
.post('/client/get-treatment-with-config?key=test&split-name=my-experiment')
.send({
properties: { foo: { bar: 1 } },
})
.set('Authorization', 'test');
expectOk(response, 200, 'on', 'my-experiment', '{"desc" : "this applies only to ON treatment"}');
Expand Down
33 changes: 29 additions & 4 deletions client/__tests__/treatments.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -268,9 +268,9 @@ describe('get-treatments', () => {
}, 3);
});

test('should be 200 if options.properties is valid (GET)', async () => {
test('should be 200 if properties is valid (GET)', async () => {
const response = await request(app)
.get('/client/get-treatments?key=test&split-names=my-experiment&options={"properties":{"package":"premium","admin":true,"discount":50}}')
.get('/client/get-treatments?key=test&split-names=my-experiment&properties={"package":"premium","admin":true,"discount":50}')
.set('Authorization', 'test');
expectOkMultipleResults(response, 200, {
'my-experiment': {
Expand All @@ -279,11 +279,36 @@ describe('get-treatments', () => {
}, 1);
});

test('should be 200 if options.properties is valid (POST)', async () => {
test('should be 200 if properties is valid (POST)', async () => {
const response = await request(app)
.post('/client/get-treatments?key=test&split-names=my-experiment')
.send({
options: { properties: { package: 'premium', admin: true, discount: 50 } },
properties: { package: 'premium', admin: true, discount: 50 },
})
.set('Authorization', 'test');
expectOkMultipleResults(response, 200, {
'my-experiment': {
treatment: 'on',
},
}, 1);
});

test('should be 200 if properties is invalid (GET)', async () => {
const response = await request(app)
.get('/client/get-treatments?key=test&split-names=my-experiment&properties={"foo": {"bar": 1}}')
.set('Authorization', 'test');
expectOkMultipleResults(response, 200, {
'my-experiment': {
treatment: 'on',
},
}, 1);
});

test('should be 200 if properties is invalid (POST)', async () => {
const response = await request(app)
.post('/client/get-treatments?key=test&split-names=my-experiment')
.send({
properties: { foo: { bar: 1 } },
})
.set('Authorization', 'test');
expectOkMultipleResults(response, 200, {
Expand Down
25 changes: 21 additions & 4 deletions client/__tests__/treatmentsByFlagSets.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -274,18 +274,35 @@ describe('get-treatments-by-sets', () => {
expectOkMultipleResults(response, 200, expectedPinkResults, 5);
});

test('should be 200 if options.properties is valid (GET)', async () => {
test('should be 200 if properties is valid (GET)', async () => {
const response = await request(app)
.get('/client/get-treatments-by-sets?key=test&flag-sets=set_green&options={"properties":{"package":"premium","admin":true,"discount":50}}')
.get('/client/get-treatments-by-sets?key=test&flag-sets=set_green&properties={"package":"premium","admin":true,"discount":50}')
.set('Authorization', 'key_green');
expect(response.status).toBe(200);
});

test('should be 200 if options.properties is valid (POST)', async () => {
test('should be 200 if properties is valid (POST)', async () => {
const response = await request(app)
.post('/client/get-treatments-by-sets?key=test&flag-sets=set_green')
.send({
options: { properties: { package: 'premium', admin: true, discount: 50 } },
properties: { package: 'premium', admin: true, discount: 50 },
})
.set('Authorization', 'key_green');
expect(response.status).toBe(200);
});

test('should be 200 if properties is invalid (GET)', async () => {
const response = await request(app)
.get('/client/get-treatments-by-sets?key=test&flag-sets=set_green&properties={"foo": {"bar": 1}}')
.set('Authorization', 'key_green');
expect(response.status).toBe(200);
});

test('should be 200 if properties is invalid (POST)', async () => {
const response = await request(app)
.post('/client/get-treatments-by-sets?key=test&flag-sets=set_green')
.send({
properties: { foo: { bar: 1 } },
})
.set('Authorization', 'key_green');
expect(response.status).toBe(200);
Expand Down
35 changes: 31 additions & 4 deletions client/__tests__/treatmentsWithConfig.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -253,9 +253,9 @@ describe('get-treatments-with-config', () => {
}, 3);
});

test('should be 200 if options.properties is valid (GET)', async () => {
test('should be 200 if properties is valid (GET)', async () => {
const response = await request(app)
.get('/client/get-treatments-with-config?key=test&split-names=my-experiment&options={"properties":{"package":"premium","admin":true,"discount":50}}')
.get('/client/get-treatments-with-config?key=test&split-names=my-experiment&properties={"package":"premium","admin":true,"discount":50}')
.set('Authorization', 'test');
expectOkMultipleResults(response, 200, {
'my-experiment': {
Expand All @@ -265,11 +265,38 @@ describe('get-treatments-with-config', () => {
}, 1);
});

test('should be 200 if options.properties is valid (POST)', async () => {
test('should be 200 if properties is valid (POST)', async () => {
const response = await request(app)
.post('/client/get-treatments-with-config?key=test&split-names=my-experiment')
.send({
options: { properties: { package: 'premium', admin: true, discount: 50 } },
properties: { package: 'premium', admin: true, discount: 50 },
})
.set('Authorization', 'test');
expectOkMultipleResults(response, 200, {
'my-experiment': {
treatment: 'on',
config: '{"desc" : "this applies only to ON treatment"}',
},
}, 1);
});

test('should be 200 if properties is invalid (GET)', async () => {
const response = await request(app)
.get('/client/get-treatments-with-config?key=test&split-names=my-experiment&properties={"foo": {"bar": 1}}')
.set('Authorization', 'test');
expectOkMultipleResults(response, 200, {
'my-experiment': {
treatment: 'on',
config: '{"desc" : "this applies only to ON treatment"}',
},
}, 1);
});

test('should be 200 if properties is invalid (POST)', async () => {
const response = await request(app)
.post('/client/get-treatments-with-config?key=test&split-names=my-experiment')
.send({
properties: { foo: { bar: 1 } },
})
.set('Authorization', 'test');
expectOkMultipleResults(response, 200, {
Expand Down
34 changes: 34 additions & 0 deletions client/__tests__/treatmentsWithConfigByFlagSets.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -249,4 +249,38 @@ describe('get-treatments-with-config-by-sets', () => {
.set('Authorization', 'key_pink');
expectOkMultipleResults(response, 200, expectedPinkResultsWithConfig, 5);
});

test('should be 200 if properties is valid (GET)', async () => {
const response = await request(app)
.get('/client/get-treatments-with-config-by-sets?key=test&flag-sets=set_green&properties={"package":"premium","admin":true,"discount":50}')
.set('Authorization', 'key_green');
expect(response.status).toBe(200);
});

test('should be 200 if properties is valid (POST)', async () => {
const response = await request(app)
.post('/client/get-treatments-with-config-by-sets?key=test&flag-sets=set_green')
.send({
properties: { package: 'premium', admin: true, discount: 50 },
})
.set('Authorization', 'key_green');
expect(response.status).toBe(200);
});

test('should be 200 if properties is invalid (GET)', async () => {
const response = await request(app)
.get('/client/get-treatments-with-config-by-sets?key=test&flag-sets=set_green&properties={"foo": {"bar": 1}}')
.set('Authorization', 'key_green');
expect(response.status).toBe(200);
});

test('should be 200 if properties is invalid (POST)', async () => {
const response = await request(app)
.post('/client/get-treatments-with-config-by-sets?key=test&flag-sets=set_green')
.send({
properties: { foo: { bar: 1 } },
})
.set('Authorization', 'key_green');
expect(response.status).toBe(200);
});
});
Loading