Skip to content

Commit

Permalink
Add fetchsegments on setuser test
Browse files Browse the repository at this point in the history
  • Loading branch information
rafinutshaw-optimizely committed Jul 20, 2023
1 parent 887d912 commit 3a40344
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 4 deletions.
21 changes: 18 additions & 3 deletions src/client.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -220,11 +220,11 @@ describe('ReactSDKClient', () => {
});
});

it('adds and removes update handlers', () => {
it('adds and removes update handlers', async () => {
const instance = createInstance(config);
const onUserUpdateListener = jest.fn();
const dispose = instance.onUserUpdate(onUserUpdateListener);
instance.setUser({
await instance.setUser({
id: 'newUser',
});
expect(onUserUpdateListener).toBeCalledTimes(1);
Expand All @@ -233,12 +233,27 @@ describe('ReactSDKClient', () => {
attributes: {},
});
dispose();
instance.setUser({
await instance.setUser({
id: 'newUser2',
});
expect(onUserUpdateListener).toBeCalledTimes(1);
});

it('calls fetchqualifiedsegements internally on each setuser call', async () => {
const instance = createInstance(config);
jest.spyOn(instance, 'fetchQualifiedSegments').mockImplementation(async () => true);

await instance.setUser({
id: 'xxfueaojfe8&86',
});

await instance.setUser({
id: 'xxfueaojfe8&87',
});

expect(instance.fetchQualifiedSegments).toBeCalledTimes(2);
});

describe('pre-set user and user overrides', () => {
let instance: ReactSDKClient;
beforeEach(() => {
Expand Down
2 changes: 1 addition & 1 deletion src/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ export interface ReactSDKClient extends Omit<optimizely.Client, 'createUserConte
user: UserInfo;

onReady(opts?: { timeout?: number }): Promise<any>;
setUser(userInfo: UserInfo): void;
setUser(userInfo: UserInfo): Promise<void>;
onUserUpdate(handler: OnUserUpdateHandler): DisposeFn;
isReady(): boolean;
getIsReadyPromiseFulfilled(): boolean;
Expand Down

0 comments on commit 3a40344

Please sign in to comment.