Skip to content

Commit

Permalink
Junaed/fssdk 10980 optimizely onready always returns false (#302)
Browse files Browse the repository at this point in the history
  • Loading branch information
junaed-optimizely authored Jan 6, 2025
1 parent 0dffba5 commit c50e7b8
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
19 changes: 19 additions & 0 deletions src/client.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -315,6 +315,25 @@ describe('ReactSDKClient', () => {
expect(instance.getUserContext()).toBe(null);
});

it('if user id is not present, and ODP is explicitly off, user promise will be pending', async () => {
jest.spyOn(mockInnerClient, 'onReady').mockResolvedValue({ success: true });

instance = createInstance({
...config,
odpOptions: {
disabled: true,
},
});

await instance.setUser(DefaultUser);
expect(instance.isReady()).toBe(false);

await instance.setUser({ id: 'user123' });
await instance.onReady();

expect(instance.isReady()).toBe(true);
});

it('can be called with no/default user set', async () => {
jest.spyOn(mockOptimizelyUserContext, 'getUserId').mockReturnValue(validVuid);

Expand Down
4 changes: 4 additions & 0 deletions src/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -382,6 +382,10 @@ class OptimizelyReactSDKClient implements ReactSDKClient {
}

public async setUser(userInfo: UserInfo): Promise<void> {
// If user id is not present and ODP is explicitly off, user promise will be pending until setUser is called again with proper user id
if (userInfo.id === null && this.odpExplicitlyOff) {
return;
}
this.user = {
id: userInfo.id || DefaultUser.id,
attributes: userInfo.attributes || DefaultUser.attributes,
Expand Down

1 comment on commit c50e7b8

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Jest Coverage Report

St.
Category Percentage Covered / Total
🟢 Statements 98.95% 851/860
🟢 Branches 91.51% 345/377
🟢 Functions 97.52% 157/161
🟢 Lines 99.1% 769/776

Test suite run success

266 tests passing in 10 suites.

Report generated by 🧪jest coverage report action from c50e7b8

Please sign in to comment.