Skip to content

Commit

Permalink
Update server-side tests with flag spec 1.1
Browse files Browse the repository at this point in the history
  • Loading branch information
EmilianoSanchez committed Sep 18, 2024
1 parent 5211a8a commit 62723ec
Show file tree
Hide file tree
Showing 23 changed files with 130 additions and 130 deletions.
4 changes: 2 additions & 2 deletions src/__tests__/destroy/node.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ import splitChangesMock1 from '../mocks/splitChanges.since.-1.till.1500492097547
import splitChangesMock2 from '../mocks/splitChanges.since.1500492097547.json';
import impressionsMock from '../mocks/impressions.json';

fetchMock.get(url(settings, '/splitChanges?s=1.2&since=-1'), { status: 200, body: splitChangesMock1 });
fetchMock.get(url(settings, '/splitChanges?s=1.2&since=1500492097547'), { status: 200, body: splitChangesMock2 });
fetchMock.get(url(settings, '/splitChanges?s=1.1&since=-1'), { status: 200, body: splitChangesMock1 });
fetchMock.get(url(settings, '/splitChanges?s=1.1&since=1500492097547'), { status: 200, body: splitChangesMock2 });
fetchMock.postOnce(url(settings, '/v1/metrics/config'), 200);

tape('SDK destroy for NodeJS', async function (assert) {
Expand Down
6 changes: 3 additions & 3 deletions src/__tests__/errorCatching/node.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@ const settings = settingsFactory({
streamingEnabled: false
});

fetchMock.get(url(settings, '/splitChanges?s=1.2&since=-1'), { status: 200, body: splitChangesMock1 }, responseDelay);
fetchMock.get(url(settings, '/splitChanges?s=1.2&since=1500492097547'), { status: 200, body: splitChangesMock2 }, responseDelay);
fetchMock.get(url(settings, '/splitChanges?s=1.2&since=1500492297547'), { status: 200, body: splitChangesMock3 }, responseDelay);
fetchMock.get(url(settings, '/splitChanges?s=1.1&since=-1'), { status: 200, body: splitChangesMock1 }, responseDelay);
fetchMock.get(url(settings, '/splitChanges?s=1.1&since=1500492097547'), { status: 200, body: splitChangesMock2 }, responseDelay);
fetchMock.get(url(settings, '/splitChanges?s=1.1&since=1500492297547'), { status: 200, body: splitChangesMock3 }, responseDelay);
fetchMock.postOnce(url(settings, '/v1/metrics/config'), 200); // SDK_READY
fetchMock.postOnce(url(settings, '/v1/metrics/usage'), 200); // SDK destroyed

Expand Down
4 changes: 2 additions & 2 deletions src/__tests__/nodeSuites/evaluations-semver.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ const config = {

export default async function (fetchMock, assert) {

fetchMock.getOnce(config.urls.sdk + '/splitChanges?s=1.2&since=-1', { status: 200, body: splitChangesMock1 });
fetchMock.get(config.urls.sdk + '/splitChanges?s=1.2&since=1675259356568', { status: 200, body: { splits: [], since: 1675259356568, till: 1675259356568 } });
fetchMock.getOnce(config.urls.sdk + '/splitChanges?s=1.1&since=-1', { status: 200, body: splitChangesMock1 });
fetchMock.get(config.urls.sdk + '/splitChanges?s=1.1&since=1675259356568', { status: 200, body: { splits: [], since: 1675259356568, till: 1675259356568 } });

const splitio = SplitFactory(config);
const client = splitio.client();
Expand Down
2 changes: 1 addition & 1 deletion src/__tests__/nodeSuites/expected-treatments.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { url } from '../testUtils';
import splitChangesMockReal from '../mocks/splitchanges.real.json';

export default async function (config, settings, fetchMock, assert) {
fetchMock.get({ url: url(settings, '/splitChanges?s=1.2&since=-1'), overwriteRoutes: true }, { status: 200, body: splitChangesMockReal });
fetchMock.get({ url: url(settings, '/splitChanges?s=1.1&since=-1'), overwriteRoutes: true }, { status: 200, body: splitChangesMockReal });

const splitio = SplitFactory({
...config,
Expand Down
10 changes: 5 additions & 5 deletions src/__tests__/nodeSuites/fetch-specific-splits.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@ export function fetchSpecificSplits(fetchMock, assert) {
const queryString = queryStrings[i] || '';
let factory;

fetchMock.getOnce(urls.sdk + '/splitChanges?s=1.2&since=-1' + queryString, { status: 200, body: { splits: [], since: -1, till: 1457552620999 } });
fetchMock.getOnce(urls.sdk + '/splitChanges?s=1.2&since=1457552620999' + queryString, { status: 200, body: { splits: [], since: 1457552620999, till: 1457552620999 } });
fetchMock.getOnce(urls.sdk + '/splitChanges?s=1.2&since=1457552620999' + queryString, function () {
fetchMock.getOnce(urls.sdk + '/splitChanges?s=1.1&since=-1' + queryString, { status: 200, body: { splits: [], since: -1, till: 1457552620999 } });
fetchMock.getOnce(urls.sdk + '/splitChanges?s=1.1&since=1457552620999' + queryString, { status: 200, body: { splits: [], since: 1457552620999, till: 1457552620999 } });
fetchMock.getOnce(urls.sdk + '/splitChanges?s=1.1&since=1457552620999' + queryString, function () {
factory.client().destroy().then(() => {
assert.pass(`splitFilters #${i}`);
});
Expand Down Expand Up @@ -64,8 +64,8 @@ export function fetchSpecificSplitsForFlagSets(fetchMock, assert) {
let factory;
const queryString = '&sets=4_valid,set_2,set_3,set_ww,set_x';

fetchMock.getOnce(baseUrls.sdk + '/splitChanges?s=1.2&since=-1' + queryString, { status: 200, body: { splits: [], since: 1457552620999, till: 1457552620999 }});
fetchMock.getOnce(baseUrls.sdk + '/splitChanges?s=1.2&since=1457552620999' + queryString, async function () {
fetchMock.getOnce(baseUrls.sdk + '/splitChanges?s=1.1&since=-1' + queryString, { status: 200, body: { splits: [], since: 1457552620999, till: 1457552620999 }});
fetchMock.getOnce(baseUrls.sdk + '/splitChanges?s=1.1&since=1457552620999' + queryString, async function () {
t.pass('flag set query correctly formed');
factory.client().destroy().then(() => {
t.end();
Expand Down
24 changes: 12 additions & 12 deletions src/__tests__/nodeSuites/flag-sets.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,12 @@ export default function flagSets(fetchMock, t) {
let factory, manager, client = [];

// Receive split change with 1 split belonging to set_1 & set_2 and one belonging to set_3
fetchMock.getOnce(baseUrls.sdk + '/splitChanges?s=1.2&since=-1&sets=set_1,set_2', function () {
fetchMock.getOnce(baseUrls.sdk + '/splitChanges?s=1.1&since=-1&sets=set_1,set_2', function () {
return { status: 200, body: splitChange2};
});

// Receive split change with 1 split belonging to set_1 only
fetchMock.getOnce(baseUrls.sdk + '/splitChanges?s=1.2&since=1602796638344&sets=set_1,set_2', function () {
fetchMock.getOnce(baseUrls.sdk + '/splitChanges?s=1.1&since=1602796638344&sets=set_1,set_2', function () {
// stored feature flags before update
const storedFlags = manager.splits();
assert.true(storedFlags.length === 1, 'only one feature flag should be added');
Expand All @@ -43,7 +43,7 @@ export default function flagSets(fetchMock, t) {
});

// Receive split change with 1 split belonging to set_3 only
fetchMock.getOnce(baseUrls.sdk + '/splitChanges?s=1.2&since=1602797638344&sets=set_1,set_2', function () {
fetchMock.getOnce(baseUrls.sdk + '/splitChanges?s=1.1&since=1602797638344&sets=set_1,set_2', function () {
// stored feature flags before update
const storedFlags = manager.splits();
assert.true(storedFlags.length === 1);
Expand All @@ -54,7 +54,7 @@ export default function flagSets(fetchMock, t) {
return { status: 200, body: splitChange0};
});

fetchMock.getOnce(baseUrls.sdk + '/splitChanges?s=1.2&since=1602798638344&sets=set_1,set_2', async function () {
fetchMock.getOnce(baseUrls.sdk + '/splitChanges?s=1.1&since=1602798638344&sets=set_1,set_2', async function () {
// stored feature flags before update
const storedFlags = manager.splits();
assert.true(storedFlags.length === 0, 'the feature flag should be removed');
Expand All @@ -79,12 +79,12 @@ export default function flagSets(fetchMock, t) {
let factory, manager, client = [];

// Receive split change with 1 split belonging to set_1 & set_2 and one belonging to set_3
fetchMock.getOnce(baseUrls.sdk + '/splitChanges?s=1.2&since=-1', function () {
fetchMock.getOnce(baseUrls.sdk + '/splitChanges?s=1.1&since=-1', function () {
return { status: 200, body: splitChange2};
});

// Receive split change with 1 split belonging to set_1 only
fetchMock.getOnce(baseUrls.sdk + '/splitChanges?s=1.2&since=1602796638344', function () {
fetchMock.getOnce(baseUrls.sdk + '/splitChanges?s=1.1&since=1602796638344', function () {
// stored feature flags before update
const storedFlags = manager.splits();
assert.true(storedFlags.length === 2, 'every feature flag should be added');
Expand All @@ -98,7 +98,7 @@ export default function flagSets(fetchMock, t) {
});

// Receive split change with 1 split belonging to set_3 only
fetchMock.getOnce(baseUrls.sdk + '/splitChanges?s=1.2&since=1602797638344', function () {
fetchMock.getOnce(baseUrls.sdk + '/splitChanges?s=1.1&since=1602797638344', function () {
// stored feature flags before update
const storedFlags = manager.splits();
assert.true(storedFlags.length === 2);
Expand All @@ -111,7 +111,7 @@ export default function flagSets(fetchMock, t) {
return { status: 200, body: splitChange0};
});

fetchMock.getOnce(baseUrls.sdk + '/splitChanges?s=1.2&since=1602798638344', async function () {
fetchMock.getOnce(baseUrls.sdk + '/splitChanges?s=1.1&since=1602798638344', async function () {
// stored feature flags before update
const storedFlags = manager.splits();
assert.true(storedFlags.length === 2);
Expand Down Expand Up @@ -142,11 +142,11 @@ export default function flagSets(fetchMock, t) {
mockSegmentChanges(fetchMock, new RegExp(baseUrls.sdk + '/segmentChanges/*'), []);
fetchMock.post('*', 200);
// Receive split change with 1 split belonging to set_1 & set_2 and one belonging to set_3
fetchMock.getOnce(baseUrls.sdk + '/splitChanges?s=1.2&since=-1&sets=set_1', function () {
fetchMock.getOnce(baseUrls.sdk + '/splitChanges?s=1.1&since=-1&sets=set_1', function () {
return { status: 200, body: splitChange2};
});

fetchMock.getOnce(baseUrls.sdk + '/splitChanges?s=1.2&since=1602796638344&sets=set_1', async function () {
fetchMock.getOnce(baseUrls.sdk + '/splitChanges?s=1.1&since=1602796638344&sets=set_1', async function () {
// stored feature flags before update
assert.deepEqual(client.getTreatmentsByFlagSet(key, 'set_1'), {workm: 'on'}, 'only the flag in set_1 can be evaluated');
assert.deepEqual(client.getTreatmentsByFlagSet(key, 'set_2'), {}, 'only the flag in set_1 can be evaluated');
Expand Down Expand Up @@ -180,11 +180,11 @@ export default function flagSets(fetchMock, t) {
fetchMock.post('*', 200);

// Receive split change with 1 split belonging to set_1 & set_2 and one belonging to set_3
fetchMock.getOnce(baseUrls.sdk + '/splitChanges?s=1.2&since=-1', function () {
fetchMock.getOnce(baseUrls.sdk + '/splitChanges?s=1.1&since=-1', function () {
return { status: 200, body: splitChange2};
});

fetchMock.getOnce(baseUrls.sdk + '/splitChanges?s=1.2&since=1602796638344', async function () {
fetchMock.getOnce(baseUrls.sdk + '/splitChanges?s=1.1&since=1602796638344', async function () {
// stored feature flags before update
assert.deepEqual(client.getTreatmentsByFlagSet(key, 'set_1'), {workm: 'on'}, 'all flags can be evaluated');
assert.deepEqual(client.getTreatmentsByFlagSet(key, 'set_2'), {workm: 'on'}, 'all flags can be evaluated');
Expand Down
4 changes: 2 additions & 2 deletions src/__tests__/nodeSuites/impressions.debug.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@ const config = {

export default async function (key, fetchMock, assert) {
// Mocking this specific route to make sure we only get the items we want to test from the handlers.
fetchMock.getOnce(url(settings, '/splitChanges?s=1.2&since=-1'), { status: 200, body: splitChangesMock1 });
fetchMock.get(url(settings, '/splitChanges?s=1.2&since=1457552620999'), { status: 200, body: splitChangesMock2 });
fetchMock.getOnce(url(settings, '/splitChanges?s=1.1&since=-1'), { status: 200, body: splitChangesMock1 });
fetchMock.get(url(settings, '/splitChanges?s=1.1&since=1457552620999'), { status: 200, body: splitChangesMock2 });
fetchMock.get(new RegExp(`${url(settings, '/segmentChanges/')}.*`), { status: 200, body: { since: 10, till: 10, name: 'segmentName', added: [], removed: [] } });

const splitio = SplitFactory(config);
Expand Down
4 changes: 2 additions & 2 deletions src/__tests__/nodeSuites/impressions.none.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@ const config = {

export default async function (key, fetchMock, assert) {
// Mocking this specific route to make sure we only get the items we want to test from the handlers.
fetchMock.getOnce(url(settings, '/splitChanges?s=1.2&since=-1'), { status: 200, body: splitChangesMock1 });
fetchMock.get(url(settings, '/splitChanges?s=1.2&since=1457552620999'), { status: 200, body: splitChangesMock2 });
fetchMock.getOnce(url(settings, '/splitChanges?s=1.1&since=-1'), { status: 200, body: splitChangesMock1 });
fetchMock.get(url(settings, '/splitChanges?s=1.1&since=1457552620999'), { status: 200, body: splitChangesMock2 });
fetchMock.get(new RegExp(`${url(settings, '/segmentChanges/')}.*`), { status: 200, body: { since: 10, till: 10, name: 'segmentName', added: [], removed: [] } });

const splitio = SplitFactory(config);
Expand Down
4 changes: 2 additions & 2 deletions src/__tests__/nodeSuites/impressions.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@ let truncatedTimeFrame;

export default async function (key, fetchMock, assert) {
// Mocking this specific route to make sure we only get the items we want to test from the handlers.
fetchMock.getOnce(url(settings, '/splitChanges?s=1.2&since=-1'), { status: 200, body: splitChangesMock1 });
fetchMock.get(url(settings, '/splitChanges?s=1.2&since=1457552620999'), { status: 200, body: splitChangesMock2 });
fetchMock.getOnce(url(settings, '/splitChanges?s=1.1&since=-1'), { status: 200, body: splitChangesMock1 });
fetchMock.get(url(settings, '/splitChanges?s=1.1&since=1457552620999'), { status: 200, body: splitChangesMock2 });
fetchMock.get(new RegExp(`${url(settings, '/segmentChanges/')}.*`), { status: 200, body: { since: 10, till: 10, name: 'segmentName', added: [], removed: [] } });

const splitio = SplitFactory(config);
Expand Down
4 changes: 2 additions & 2 deletions src/__tests__/nodeSuites/ip-addresses-setting.debug.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,8 @@ export default function ipAddressesSettingAssertions(fetchMock, assert) {
})();

// Mock GET endpoints to run client normally
fetchMock.getOnce(url(settings, '/splitChanges?s=1.2&since=-1'), { status: 200, body: splitChangesMock1 });
fetchMock.getOnce(url(settings, '/splitChanges?s=1.2&since=1457552620999'), { status: 200, body: { splits: [], since: 1457552620999, till: 1457552620999 } });
fetchMock.getOnce(url(settings, '/splitChanges?s=1.1&since=-1'), { status: 200, body: splitChangesMock1 });
fetchMock.getOnce(url(settings, '/splitChanges?s=1.1&since=1457552620999'), { status: 200, body: { splits: [], since: 1457552620999, till: 1457552620999 } });
fetchMock.get(new RegExp(`${url(settings, '/segmentChanges/')}.*`), { status: 200, body: { since: 10, till: 10, name: 'segmentName', added: [], removed: [] } });

// Mock and assert POST endpoints
Expand Down
4 changes: 2 additions & 2 deletions src/__tests__/nodeSuites/ip-addresses-setting.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -121,8 +121,8 @@ export default function ipAddressesSettingAssertions(fetchMock, assert) {
})();

// Mock GET endpoints to run client normally
fetchMock.getOnce(url(settings, '/splitChanges?s=1.2&since=-1'), { status: 200, body: splitChangesMock1 });
fetchMock.getOnce(url(settings, '/splitChanges?s=1.2&since=1457552620999'), { status: 200, body: { splits: [], since: 1457552620999, till: 1457552620999 } });
fetchMock.getOnce(url(settings, '/splitChanges?s=1.1&since=-1'), { status: 200, body: splitChangesMock1 });
fetchMock.getOnce(url(settings, '/splitChanges?s=1.1&since=1457552620999'), { status: 200, body: { splits: [], since: 1457552620999, till: 1457552620999 } });
fetchMock.get(new RegExp(`${url(settings, '/segmentChanges/')}.*`), { status: 200, body: { since: 10, till: 10, name: 'segmentName', added: [], removed: [] } });

// Mock and assert POST endpoints
Expand Down
2 changes: 1 addition & 1 deletion src/__tests__/nodeSuites/manager.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import map from 'lodash/map';
import { url } from '../testUtils';

export default async function (settings, fetchMock, assert) {
fetchMock.get({ url: url(settings, '/splitChanges?s=1.2&since=-1'), overwriteRoutes: true }, { status: 200, body: splitChangesMockReal });
fetchMock.get({ url: url(settings, '/splitChanges?s=1.1&since=-1'), overwriteRoutes: true }, { status: 200, body: splitChangesMockReal });

const mockSplits = splitChangesMockReal;

Expand Down
Loading

0 comments on commit 62723ec

Please sign in to comment.