Skip to content

Commit c4c1dd0

Browse files
[FSSDK-10439] testcase addition for decideForKeys, fetchQualifiedSegments
1 parent 619aeff commit c4c1dd0

File tree

1 file changed

+62
-2
lines changed

1 file changed

+62
-2
lines changed

src/client.spec.ts

Lines changed: 62 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1528,6 +1528,41 @@ describe('ReactSDKClient', () => {
15281528

15291529
it('decideForKeys returns correct value', () => {
15301530
const mockFn = mockOptimizelyUserContext.decideForKeys as jest.Mock;
1531+
1532+
mockFn.mockReturnValue({
1533+
theFlag1: {
1534+
enabled: true,
1535+
flagKey: 'theFlag1',
1536+
reasons: [],
1537+
ruleKey: '',
1538+
userContext: mockOptimizelyUserContext,
1539+
variables: {},
1540+
variationKey: 'varition1',
1541+
},
1542+
});
1543+
1544+
const result = instance.decideForKeys(['theFlag1']);
1545+
1546+
expect(result).toEqual({
1547+
theFlag1: {
1548+
enabled: true,
1549+
flagKey: 'theFlag1',
1550+
reasons: [],
1551+
ruleKey: '',
1552+
userContext: {
1553+
id: userId,
1554+
attributes: userAttributes,
1555+
},
1556+
variables: {},
1557+
variationKey: 'varition1',
1558+
},
1559+
});
1560+
expect(mockFn).toHaveBeenCalledTimes(1);
1561+
expect(mockFn).toHaveBeenCalledWith(['theFlag1'], []);
1562+
});
1563+
1564+
it('for overrides, decideForKeys creates new context and evaluates flags correctly', () => {
1565+
const mockFn = mockOptimizelyUserContext.decideForKeys as jest.Mock;
15311566
const mockCreateUserContext = mockInnerClient.createUserContext as jest.Mock;
15321567
mockFn.mockReturnValue({
15331568
theFlag1: {
@@ -1540,16 +1575,18 @@ describe('ReactSDKClient', () => {
15401575
variationKey: 'varition1',
15411576
},
15421577
});
1578+
15431579
let result = instance.decideForKeys(['theFlag1']);
1580+
15441581
expect(result).toEqual({
15451582
theFlag1: {
15461583
enabled: true,
15471584
flagKey: 'theFlag1',
15481585
reasons: [],
15491586
ruleKey: '',
15501587
userContext: {
1551-
id: 'user1',
1552-
attributes: { foo: 'bar' },
1588+
id: userId,
1589+
attributes: userAttributes,
15531590
},
15541591
variables: {},
15551592
variationKey: 'varition1',
@@ -1619,6 +1656,29 @@ describe('ReactSDKClient', () => {
16191656

16201657
expect(result).toEqual(true);
16211658
});
1659+
1660+
it('if odp is explicitly off, it should return true', async () => {
1661+
instance = createInstance({
1662+
...config,
1663+
odpOptions: {
1664+
disabled: true,
1665+
},
1666+
});
1667+
1668+
await instance.setUser({
1669+
id: userId,
1670+
attributes: userAttributes,
1671+
});
1672+
1673+
const result = await instance.fetchQualifiedSegments();
1674+
expect(result).toEqual(true);
1675+
});
1676+
1677+
it('if odp is not integrated, it should return true', async () => {
1678+
(mockInnerClient.isOdpIntegrated as jest.Mock).mockReturnValue(false);
1679+
const result = await instance.fetchQualifiedSegments();
1680+
expect(result).toEqual(true);
1681+
});
16221682
});
16231683

16241684
describe('removeAllForcedDecisions', () => {

0 commit comments

Comments
 (0)