-
Notifications
You must be signed in to change notification settings - Fork 66
/
test-types.ts
131 lines (110 loc) · 3.38 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
// This file exists only so that we can run the TypeScript compiler in the CI build
// to validate our typings.d.ts file. The code will not actually be run.
import * as ld from 'launchdarkly-js-client-sdk';
import LaunchDarkly from 'launchdarkly-js-client-sdk';
const ver: string = LaunchDarkly.version;
const emptyOptions: ld.LDOptions = {};
const logger: ld.LDLogger = ld.basicLogger({ level: 'info' });
const allOptions: ld.LDOptions = {
bootstrap: { },
hash: '',
baseUrl: '',
eventsUrl: '',
streamUrl: '',
streaming: true,
useReport: true,
sendLDHeaders: true,
evaluationReasons: true,
fetchGoals: true,
sendEvents: true,
allAttributesPrivate: true,
privateAttributes: [ 'x' ],
sendEventsOnlyForVariation: true,
flushInterval: 1,
streamReconnectDelay: 1,
eventUrlTransformer: url => url + 'x',
disableSyncEventPost: true,
logger: logger,
};
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 singleKindContext: ld.LDContext = {
kind: 'user',
key: 'user',
aCustomValue: {
some: 'value'
},
_meta: {
privateAttributes: ['aCustomValue']
}
}
const multiKindContext: ld.LDContext = {
kind: 'multi',
user: {
key: 'user',
aCustomValue: {
some: 'value'
},
_meta: {
privateAttributes: ['aCustomValue']
}
},
device: {
key: 'device'
}
}
const client: ld.LDClient = ld.initialize('env', user, allOptions);
client.waitUntilReady().then(() => {});
client.waitForInitialization(5).then(() => {});
client.waitUntilGoalsReady().then(() => {});
client.identify(user).then(() => {});
client.identify(user, undefined, () => {});
client.identify(user, 'hash').then(() => {});
client.identify(singleKindContext).then(() => {});
client.identify(singleKindContext, undefined, () => {});
client.identify(singleKindContext, 'hash').then(() => {});
client.identify(multiKindContext).then(() => {});
client.identify(multiKindContext, undefined, () => {});
client.identify(multiKindContext, 'hash').then(() => {});
const context: ld.LDContext = client.getContext();
client.flush(() => {});
client.flush().then(() => {});
const boolFlagValue: ld.LDFlagValue = client.variation('key', false);
const numberFlagValue: ld.LDFlagValue = client.variation('key', 2);
const stringFlagValue: ld.LDFlagValue = client.variation('key', 'default');
const detail: ld.LDEvaluationDetail = client.variationDetail('key', 'default');
const detailValue: ld.LDFlagValue = detail.value;
const detailIndex: number | undefined = detail.variationIndex;
const detailReason: ld.LDEvaluationReason | undefined = detail.reason;
client.setStreaming(true);
client.setStreaming();
function handleEvent() {}
client.on('event', handleEvent);
client.off('event', handleEvent);
client.track('event');
client.track('event', { someData: 'x' });
client.track('event', null, 3.5);
const flagSet: ld.LDFlagSet = client.allFlags();
const flagSetValue: ld.LDFlagValue = flagSet['key'];
client.close(() => {});
client.close().then(() => {});