Skip to content

Commit c13cdd1

Browse files
Update tests
1 parent 083999f commit c13cdd1

File tree

3 files changed

+32
-19
lines changed

3 files changed

+32
-19
lines changed

src/__tests__/nodeSuites/client.spec.js

Lines changed: 21 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,31 @@
11
/* eslint-disable jest/no-conditional-expect */
22
import { OpenFeatureSplitProvider } from '../../lib/js-split-provider';
3-
import { getLocalHostSplitClient } from '../testUtils';
3+
import { getLocalHostSplitClient, getSplitFactory } from '../testUtils';
44

55
import { OpenFeature } from '@openfeature/server-sdk';
66

7-
describe('client tests', () => {
7+
const cases = [
8+
[
9+
'openfeature client tests mode: splitClient',
10+
() => ({ splitClient: getLocalHostSplitClient()}),
11+
12+
],
13+
[
14+
'openfeature client tests mode: splitFactory',
15+
getSplitFactory
16+
],
17+
];
18+
19+
describe.each(cases)('%s', (label, getOptions) => {
820

921
let client;
10-
let splitClient;
1122
let provider;
23+
let options;
1224

1325
beforeEach(() => {
14-
splitClient = getLocalHostSplitClient();
15-
provider = new OpenFeatureSplitProvider({ splitClient });
1626

27+
options = getOptions();
28+
provider = new OpenFeatureSplitProvider(options);
1729
OpenFeature.setProvider(provider);
1830

1931
client = OpenFeature.getClient('test');
@@ -22,9 +34,8 @@ describe('client tests', () => {
2234
};
2335
client.setContext(evaluationContext);
2436
});
25-
afterEach(() => {
26-
splitClient.destroy();
27-
provider = undefined;
37+
afterEach(async () => {
38+
await OpenFeature.close();
2839
});
2940

3041
test('use default test', async () => {
@@ -206,13 +217,13 @@ describe('client tests', () => {
206217
});
207218

208219
test('track: without value', async () => {
209-
const trackSpy = jest.spyOn(splitClient, 'track');
220+
const trackSpy = jest.spyOn(options.splitClient ? options.splitClient : options.client(), 'track');
210221
await client.track('my-event', { targetingKey: 'u1', trafficType: 'user' }, { properties: { prop1: 'value1' } });
211222
expect(trackSpy).toHaveBeenCalledWith('u1', 'user', 'my-event', undefined, { prop1: 'value1' });
212223
});
213224

214225
test('track: with value', async () => {
215-
const trackSpy = jest.spyOn(splitClient, 'track');
226+
const trackSpy = jest.spyOn(options.splitClient ? options.splitClient : options.client(), 'track');
216227
await client.track('my-event', { targetingKey: 'u1', trafficType: 'user' }, { value: 9.99, properties: { prop1: 'value1' } });
217228
expect(trackSpy).toHaveBeenCalledWith('u1', 'user', 'my-event', 9.99, { prop1: 'value1' });
218229
});

src/__tests__/nodeSuites/provider.spec.js

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,26 +4,29 @@ import { OpenFeatureSplitProvider } from '../../lib/js-split-provider';
44

55
const cases = [
66
[
7-
'Localhost',
8-
{ splitClient: getLocalHostSplitClient()},
7+
'provider tests mode: splitClient',
8+
() => ({ splitClient: getLocalHostSplitClient()}),
99

1010
],
1111
[
12-
'Factory',
13-
getSplitFactory()
12+
'provider tests mode: splitFactory',
13+
getSplitFactory
1414
],
1515
];
1616

1717
describe.each(cases)('%s', (label, getOptions) => {
1818

1919
let provider;
20+
let options;
2021

21-
beforeEach(async () => {
22-
provider = new OpenFeatureSplitProvider(getOptions);
22+
beforeEach(() => {
23+
options = getOptions();
24+
provider = new OpenFeatureSplitProvider(options);
2325
});
2426

2527
afterEach(async () => {
2628
jest.clearAllMocks()
29+
await provider.onClose();
2730
});
2831

2932
test('evaluate Boolean null/empty test', async () => {
@@ -219,14 +222,14 @@ describe.each(cases)('%s', (label, getOptions) => {
219222
});
220223

221224
test('track: ok without details', async () => {
222-
const trackSpy = jest.spyOn(getOptions.splitClient ? getOptions.splitClient : getOptions.client(), 'track');
225+
const trackSpy = jest.spyOn(options.splitClient ? options.splitClient : options.client(), 'track');
223226
await provider.track('view', { targetingKey: 'u1', trafficType: 'user' }, null);
224227
expect(trackSpy).toHaveBeenCalledTimes(1);
225228
expect(trackSpy).toHaveBeenCalledWith('u1', 'user', 'view', undefined, {});
226229
});
227230

228231
test('track: ok with details', async () => {
229-
const trackSpy = jest.spyOn(getOptions.splitClient ? getOptions.splitClient : getOptions.client(), 'track');
232+
const trackSpy = jest.spyOn(options.splitClient ? options.splitClient : options.client(), 'track');
230233
await provider.track(
231234
'purchase',
232235
{ targetingKey: 'u1', trafficType: 'user' },

src/__tests__/testUtils/index.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,6 @@ const config = {
9595
authorizationKey: 'localhost'
9696
},
9797
features: './split.yaml',
98-
debug: 'DEBUG'
9998
}
10099
/**
101100
* get a Split client in localhost mode for testing purposes

0 commit comments

Comments
 (0)