-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathConfidenceServerProviderLocal.e2e.test.ts
More file actions
98 lines (78 loc) · 3.12 KB
/
ConfidenceServerProviderLocal.e2e.test.ts
File metadata and controls
98 lines (78 loc) · 3.12 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
import { afterAll, beforeAll, describe, expect, it } from 'vitest';
import { OpenFeature } from '@openfeature/server-sdk';
import { ConfidenceServerProviderLocal } from './ConfidenceServerProviderLocal';
import { readFileSync } from 'node:fs';
import { WasmResolver } from './WasmResolver';
const {
CONFIDENCE_API_CLIENT_ID,
CONFIDENCE_API_CLIENT_SECRET,
} = requireEnv('CONFIDENCE_API_CLIENT_ID', 'CONFIDENCE_API_CLIENT_SECRET');
const moduleBytes = readFileSync(__dirname + '/../../../wasm/confidence_resolver.wasm');
const module = new WebAssembly.Module(moduleBytes);
const resolver = await WasmResolver.load(module);
const confidenceProvider = new ConfidenceServerProviderLocal(resolver, {
clientKey: 'RxDVTrXvc6op1XxiQ4OaR31dKbJ39aYV',
clientId: CONFIDENCE_API_CLIENT_ID,
clientSecret: CONFIDENCE_API_CLIENT_SECRET
});
describe('ConfidenceServerProvider E2E tests', () => {
beforeAll( async () => {
await OpenFeature.setProviderAndWait(confidenceProvider);
OpenFeature.setContext({
targetingKey: 'test-a', // control
});
});
afterAll(() => OpenFeature.close())
it('should resolve a boolean e2e', async () => {
const client = OpenFeature.getClient();
expect(await client.getBooleanValue('web-sdk-e2e-flag.bool', true)).toBeFalsy();
});
it('should resolve an int', async () => {
const client = OpenFeature.getClient();
expect(await client.getNumberValue('web-sdk-e2e-flag.int', 10)).toEqual(3);
});
it('should resolve a double', async () => {
const client = OpenFeature.getClient();
expect(await client.getNumberValue('web-sdk-e2e-flag.double', 10)).toEqual(3.5);
});
it('should resolve a string', async () => {
const client = OpenFeature.getClient();
expect(await client.getStringValue('web-sdk-e2e-flag.str', 'default')).toEqual('control');
});
it('should resolve a struct', async () => {
const client = OpenFeature.getClient();
const expectedObject = {
int: 4,
str: 'obj control',
bool: false,
double: 3.6,
['obj-obj']: {},
};
expect(await client.getObjectValue('web-sdk-e2e-flag.obj', {})).toEqual(expectedObject);
});
it('should resolve a sub value from a struct', async () => {
const client = OpenFeature.getClient();
expect(await client.getBooleanValue('web-sdk-e2e-flag.obj.bool', true)).toBeFalsy();
});
it('should resolve a sub value from a struct with details with resolve token for client side apply call', async () => {
const client = OpenFeature.getClient();
const expectedObject = {
flagKey: 'web-sdk-e2e-flag.obj.double',
reason: 'MATCH',
variant: 'flags/web-sdk-e2e-flag/variants/control',
flagMetadata: {},
value: 3.6,
};
expect(await client.getNumberDetails('web-sdk-e2e-flag.obj.double', 1)).toEqual(expectedObject);
});
});
function requireEnv<const N extends string[]>(...names:N): Record<N[number],string> {
return names.reduce((acc, name) => {
const value = process.env[name];
if(!value) throw new Error(`Missing environment variable ${name}`)
return {
...acc,
[name]: value
};
}, {}) as Record<N[number],string>;
}