Skip to content

Commit 8375101

Browse files
[FSSDK-10980] set user logic adjustment
1 parent 0dffba5 commit 8375101

File tree

2 files changed

+26
-1
lines changed

2 files changed

+26
-1
lines changed

src/client.spec.ts

+19
Original file line numberDiff line numberDiff line change
@@ -315,6 +315,25 @@ describe('ReactSDKClient', () => {
315315
expect(instance.getUserContext()).toBe(null);
316316
});
317317

318+
it('if user id is not present, and ODP is explicitly off, user promise will be pending', async () => {
319+
jest.spyOn(mockInnerClient, 'onReady').mockResolvedValue({ success: true });
320+
321+
instance = createInstance({
322+
...config,
323+
odpOptions: {
324+
disabled: true,
325+
},
326+
});
327+
328+
await instance.setUser(DefaultUser);
329+
expect(instance.isReady()).toBe(false);
330+
331+
await instance.setUser({ id: 'user123' });
332+
await instance.onReady();
333+
334+
expect(instance.isReady()).toBe(true);
335+
});
336+
318337
it('can be called with no/default user set', async () => {
319338
jest.spyOn(mockOptimizelyUserContext, 'getUserId').mockReturnValue(validVuid);
320339

src/client.ts

+7-1
Original file line numberDiff line numberDiff line change
@@ -242,14 +242,16 @@ class OptimizelyReactSDKClient implements ReactSDKClient {
242242
this._client = optimizely.createInstance(configWithClientInfo);
243243
this.isClientReady = !!this.getOptimizelyConfig();
244244
this.isUsingSdkKey = !!configWithClientInfo.sdkKey;
245-
245+
console.log('I am in the constructor', this.isClientReady, this.isUsingSdkKey);
246246
if (this._client) {
247247
const clientReadyPromise = this._client.onReady();
248248

249249
this.clientAndUserReadyPromise = Promise.all([userReadyPromise, clientReadyPromise]).then(
250250
([userResult, clientResult]) => {
251251
this.isClientReady = clientResult.success;
252252
this.isUserReady = userResult.success;
253+
console.log('isClientReady', this.isClientReady);
254+
console.log('isUserReady', this.isUserReady);
253255
const clientAndUserReady = this.isReady();
254256
this.clientAndUserReadyPromiseFulfilled = true;
255257

@@ -382,6 +384,10 @@ class OptimizelyReactSDKClient implements ReactSDKClient {
382384
}
383385

384386
public async setUser(userInfo: UserInfo): Promise<void> {
387+
// If user id is not present and ODP is explicitly off, user promise will be pending
388+
if (userInfo?.id === null && this.odpExplicitlyOff) {
389+
return;
390+
}
385391
this.user = {
386392
id: userInfo.id || DefaultUser.id,
387393
attributes: userInfo.attributes || DefaultUser.attributes,

0 commit comments

Comments
 (0)