forked from launchdarkly/integration-framework
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvalidateSyncedSegmentCapability.js
80 lines (71 loc) · 3.08 KB
/
validateSyncedSegmentCapability.js
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
const { getManifests } = require('./__utils__');
const manifests = getManifests();
const manifestsWithCapability = manifests.filter(
([dir, mfst]) => !!mfst.capabilities?.syncedSegment
);
// test a happy path because jest test fails when there no manifest with the capability defined to run in the jest test suite
manifestsWithCapability.push([
'dummy_manifest',
{
capabilities: {
syncedSegment: {
requestParser: {
environmentIdPath: '/environmentId',
contextKindPath: '/contextKind',
cohortIdPath: '/batch[0]/cohortId',
cohortNamePath: '/batch[0]/cohortName',
cohortUrlPath: '/batch[0]/cohortUrl',
memberArrayPath: '/batch',
arrayInclusion: {
path: '/action',
matcher: '^(members|add_members)$',
},
memberArrayParser: {
memberIdPath: '/userId',
booleanMembershipPath: '/value',
},
},
},
},
},
]);
describe('Validate Synced Segment Capability Dependencies', () => {
manifestsWithCapability.forEach(([_, manifest]) => {
test(`${manifest.name} syncedSegement capability: addMemberArrayPath is required when removeMemberArrayPath is specified`, () => {
const rp = manifest.capabilities.syncedSegment?.requestParser;
if (!!rp?.removeMemberArrayPath) {
expect(rp.addMemberArrayPath).toBeDefined();
}
});
test(`${manifest.name} syncedSegement capability: removeMemberArrayPath is required when addMemberArrayPath is specified`, () => {
const rp = manifest.capabilities.syncedSegment?.requestParser;
if (!!rp?.addMemberArrayPath) {
expect(rp.removeMemberArrayPath).toBeDefined();
}
});
test(`${manifest.name} syncedSegement capability: memberArrayPath should not be specified when addMemberArrayPath or removeMemberArrayPath are specified`, () => {
const rp = manifest.capabilities.syncedSegment?.requestParser;
if (!!rp?.addMemberArrayPath || !!rp.removeMemberArrayPath) {
expect(rp.memberArrayPath).toBeUndefined();
}
});
test(`${manifest.name} syncedSegement capability: memberArrayPath should be specified when arrayInclusion is specified`, () => {
const rp = manifest.capabilities.syncedSegment?.requestParser;
if (!!rp?.arrayInclusion) {
expect(rp.memberArrayPath).toBeDefined();
}
});
test(`${manifest.name} syncedSegement capability: arrayInclusion should not be specified when addMemberArrayPath or removeMemberArrayPath are specified`, () => {
const rp = manifest.capabilities.syncedSegment?.requestParser;
if (!!rp?.addMemberArrayPath || !!rp.removeMemberArrayPath) {
expect(rp.arrayInclusion).toBeUndefined();
}
});
test(`${manifest.name} syncedSegement capability: memberArrayParser.booleanMembershipPath should be specified when memberArrayPath is specified`, () => {
const rp = manifest.capabilities.syncedSegment?.requestParser;
if (!!rp?.memberArrayParser?.booleanMembershipPath) {
expect(rp.memberArrayPath).toBeDefined();
}
});
});
});