-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathtestUtils.ts
More file actions
53 lines (46 loc) · 2.66 KB
/
testUtils.ts
File metadata and controls
53 lines (46 loc) · 2.66 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
import { IRBSegment, ISplit } from '../../dtos/types';
import { IStorageSync, IStorageAsync, IImpressionsCacheSync, IEventsCacheSync } from '../types';
// Assert that instances created by storage factories have the expected interface
export function assertStorageInterface(storage: IStorageSync | IStorageAsync) {
expect(typeof storage.destroy).toBe('function');
expect(typeof storage.splits).toBe('object');
expect(typeof storage.segments).toBe('object');
expect(typeof storage.impressions).toBe('object');
expect(typeof storage.events).toBe('object');
expect(!storage.telemetry || typeof storage.telemetry === 'object').toBeTruthy;
expect(!storage.impressionCounts || typeof storage.impressionCounts === 'object').toBeTruthy;
expect(!storage.uniqueKeys || typeof storage.uniqueKeys === 'object').toBeTruthy;
}
export function assertSyncRecorderCacheInterface(cache: IEventsCacheSync | IImpressionsCacheSync) {
expect(typeof cache.isEmpty).toBe('function');
expect(typeof cache.clear).toBe('function');
expect(typeof cache.pop).toBe('function');
expect(typeof cache.track).toBe('function');
}
// Split mocks
//@ts-ignore
export const splitWithUserTT: ISplit = { name: 'user_ff', trafficTypeName: 'user_tt', conditions: [] };
//@ts-ignore
export const splitWithAccountTT: ISplit = { name: 'account_ff', trafficTypeName: 'account_tt', conditions: [] };
//@ts-ignore
export const splitWithAccountTTAndUsesSegments: ISplit = { trafficTypeName: 'account_tt', conditions: [{ matcherGroup: { matchers: [{ matcherType: 'IN_SEGMENT', userDefinedSegmentMatcherData: { segmentName: 'employees' } }] } }] };
//@ts-ignore
export const something: ISplit = { name: 'something' };
//@ts-ignore
export const somethingElse: ISplit = { name: 'something else' };
// - With flag sets
//@ts-ignore
export const featureFlagWithEmptyFS: ISplit = { name: 'ff_empty', sets: [] };
//@ts-ignore
export const featureFlagOne: ISplit = { name: 'ff_one', sets: ['o','n','e'] };
//@ts-ignore
export const featureFlagTwo: ISplit = { name: 'ff_two', sets: ['t','w','o'] };
//@ts-ignore
export const featureFlagThree: ISplit = { name: 'ff_three', sets: ['t','h','r','e'] };
//@ts-ignore
export const featureFlagWithoutFS: ISplit = { name: 'ff_four' };
// Rule-based segments
//@ts-ignore
export const rbSegment: IRBSegment = { name: 'rb_segment', conditions: [{ matcherGroup: { matchers: [{ matcherType: 'EQUAL_TO', unaryNumericMatcherData: { value: 10 } }] } }] };
//@ts-ignore
export const rbSegmentWithInSegmentMatcher: IRBSegment = { name: 'rb_segment_with_in_segment_matcher', conditions: [{ matcherGroup: { matchers: [{ matcherType: 'IN_SEGMENT', userDefinedSegmentMatcherData: { segmentName: 'employees' } }] } }] };