This repository has been archived by the owner on May 30, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 65
/
test-types.ts
210 lines (185 loc) · 7.1 KB
/
test-types.ts
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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
// This file exists only so that we can run the TypeScript compiler in the CI build
// to validate our index.d.ts file. This code will not actually be run - the point is
// just to verify that the type declarations exist and are correct so a TypeScript
// developer can use all of the SDK features.
import * as ld from 'launchdarkly-node-server-sdk';
import * as integrations from 'launchdarkly-node-server-sdk/integrations';
import * as interfaces from 'launchdarkly-node-server-sdk/interfaces';
const logger: ld.LDLogger = {
error: (...args) => { },
warn: (...args) => { },
info: (...args) => { },
debug: (...args) => { }
};
const emptyOptions: ld.LDOptions = {};
const allOptions: ld.LDOptions = {
baseUri: '',
eventsUri: '',
streamUri: '',
stream: true,
streamInitialReconnectDelay: 1.5,
sendEvents: true,
allAttributesPrivate: true,
privateAttributes: [ 'x' ],
capacity: 100,
flushInterval: 1,
contextKeysCapacity: 100,
contextKeysFlushInterval: 1,
pollInterval: 5,
timeout: 1,
logger: logger,
tlsParams: {
ca: 'x',
cert: 'y',
key: 'z'
},
diagnosticOptOut: true,
diagnosticRecordingInterval: 100,
wrapperName: 'x',
wrapperVersion: 'y',
application: {
id: 'test-id',
version: 'test-version'
}
};
const userWithKeyOnly: ld.LDUser = { key: 'user' };
const anonymousUser: ld.LDUser = { key: 'anon-user', anonymous: true };
const user: ld.LDUser = {
key: 'user',
name: 'name',
firstName: 'first',
lastName: 'last',
email: '[email protected]',
avatar: 'http://avatar.url',
ip: '1.1.1.1',
country: 'us',
anonymous: true,
custom: {
'a': 's',
'b': true,
'c': 3,
'd': [ 'x', 'y' ],
'e': [ true, false ],
'f': [ 1, 2 ]
},
privateAttributeNames: [ 'name', 'email' ]
};
const singleKindContextWithOnlyKey: ld.LDContext = {
kind: 'user',
key: 'user'
};
const anonymousContext: ld.LDContext = {
kind: 'user',
key: 'user',
anonymous: true,
};
const singleKindContext: ld.LDContext = {
kind: 'user',
key: 'user',
name: 'name',
firstName: 'first',
lastName: 'last',
email: '[email protected]',
avatar: 'http://avatar.url',
ip: '1.1.1.1',
country: 'us',
anonymous: true,
custom: {
'a': 's',
'b': true,
'c': 3,
'd': [ 'x', 'y' ],
'e': [ true, false ],
'f': [ 1, 2 ]
},
_meta: {
privateAttributes: [ 'name', 'email' ]
}
}
const singleKindPart: ld.LDContextCommon = {...singleKindContext};
delete singleKindPart["kind"];
const multiKindContext: ld.LDContext = {
kind: 'multi',
user: singleKindPart,
org: {
key: 'org',
}
}
const client: ld.LDClient = ld.init('sdk-key', allOptions);
client.identify(user);
client.identify(singleKindContext);
client.track('key', user);
client.track('key', user, { ok: 1 });
client.track('key', user, null, 1.5);
client.track('key', singleKindContext);
client.track('key', singleKindContext, { ok: 1 });
client.track('key', singleKindContext, null, 1.5);
client.track('key', multiKindContext);
client.track('key', multiKindContext, { ok: 1 });
client.track('key', multiKindContext, null, 1.5);
// evaluation methods with callbacks
client.variation('key', user, false, (value: ld.LDFlagValue) => { });
client.variation('key', user, 2, (value: ld.LDFlagValue) => { });
client.variation('key', user, 'default', (value: ld.LDFlagValue) => { });
client.variationDetail('key', user, 'default', (detail: ld.LDEvaluationDetail) => {
const detailValue: ld.LDFlagValue = detail.value;
const detailIndex: number | undefined = detail.variationIndex;
const detailReason: ld.LDEvaluationReason = detail.reason;
});
client.allFlagsState(user, {}, (err: Error, flagSet: ld.LDFlagsState) => { });
client.variation('key', singleKindContext, false, (value: ld.LDFlagValue) => { });
client.variation('key', singleKindContext, 2, (value: ld.LDFlagValue) => { });
client.variation('key', singleKindContext, 'default', (value: ld.LDFlagValue) => { });
client.variationDetail('key', singleKindContext, 'default', (detail: ld.LDEvaluationDetail) => {
const detailValue: ld.LDFlagValue = detail.value;
const detailIndex: number | undefined = detail.variationIndex;
const detailReason: ld.LDEvaluationReason = detail.reason;
});
client.allFlagsState(singleKindContext, {}, (err: Error, flagSet: ld.LDFlagsState) => { });
client.variation('key', multiKindContext, false, (value: ld.LDFlagValue) => { });
client.variation('key', multiKindContext, 2, (value: ld.LDFlagValue) => { });
client.variation('key', multiKindContext, 'default', (value: ld.LDFlagValue) => { });
client.variationDetail('key', multiKindContext, 'default', (detail: ld.LDEvaluationDetail) => {
const detailValue: ld.LDFlagValue = detail.value;
const detailIndex: number | undefined = detail.variationIndex;
const detailReason: ld.LDEvaluationReason = detail.reason;
});
client.allFlagsState(multiKindContext, {}, (err: Error, flagSet: ld.LDFlagsState) => { });
// evaluation methods with promises
client.variation('key', singleKindContext, false).then((value: ld.LDFlagValue) => { });
client.variation('key', singleKindContext, 2).then((value: ld.LDFlagValue) => { });
client.variation('key', singleKindContext, 'default').then((value: ld.LDFlagValue) => { });
client.variationDetail('key', singleKindContext, 'default').then((detail: ld.LDEvaluationDetail) => { });
client.allFlagsState(singleKindContext).then((flagSet: ld.LDFlagsState) => { });
client.variation('key', singleKindContext, false).then((value: ld.LDFlagValue) => { });
client.variation('key', singleKindContext, 2).then((value: ld.LDFlagValue) => { });
client.variation('key', singleKindContext, 'default').then((value: ld.LDFlagValue) => { });
client.variationDetail('key', singleKindContext, 'default').then((detail: ld.LDEvaluationDetail) => { });
client.allFlagsState(singleKindContext).then((flagSet: ld.LDFlagsState) => { });
client.variation('key', multiKindContext, false).then((value: ld.LDFlagValue) => { });
client.variation('key', multiKindContext, 2).then((value: ld.LDFlagValue) => { });
client.variation('key', multiKindContext, 'default').then((value: ld.LDFlagValue) => { });
client.variationDetail('key', multiKindContext, 'default').then((detail: ld.LDEvaluationDetail) => { });
client.allFlagsState(multiKindContext).then((flagSet: ld.LDFlagsState) => { });
// basicLogger
const logger1: ld.LDLogger = ld.basicLogger();
const logger2: ld.LDLogger = ld.basicLogger({ level: 'info' });
const logger3: ld.LDLogger = ld.basicLogger({ destination: console.log });
// integrations module:
// FileDataSource
const fdsOptions: integrations.FileDataSourceOptions = {
paths: [ 'filepath' ],
autoUpdate: true,
logger: ld.basicLogger(),
};
const fds = integrations.FileDataSource(fdsOptions);
// TestData
const td: integrations.TestData = integrations.TestData();
const fb: integrations.TestDataFlagBuilder = td.flag('key');
td.update(fb);
fb.ifMatch('name', 'x').thenReturn(true);
// interfaces module:
// BigSegmentStoreStatusProvider
const bsssp: interfaces.BigSegmentStoreStatusProvider = client.bigSegmentStoreStatusProvider
const bssStatus: interfaces.BigSegmentStoreStatus | undefined = bsssp.getStatus();
bsssp.requireStatus().then((value: interfaces.BigSegmentStoreStatus) => { });