diff --git a/src/client.spec.ts b/src/client.spec.ts index 5f92f58..6aa2b82 100644 --- a/src/client.spec.ts +++ b/src/client.spec.ts @@ -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); diff --git a/src/client.ts b/src/client.ts index b743021..468f4f4 100644 --- a/src/client.ts +++ b/src/client.ts @@ -382,6 +382,10 @@ class OptimizelyReactSDKClient implements ReactSDKClient { } public async setUser(userInfo: UserInfo): Promise { + // 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,