Skip to content

Commit

Permalink
[FSSDK-10880] override initial user bug adjustment
Browse files Browse the repository at this point in the history
  • Loading branch information
junaed-optimizely committed Nov 7, 2024
1 parent 33b4344 commit b8d9765
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/Provider.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,8 @@ describe('OptimizelyProvider', () => {
});

it('should render successfully without user or userId provided', () => {
// @ts-ignore
mockReactClient.user = undefined;
render(<OptimizelyProvider optimizely={mockReactClient} />);

expect(mockReactClient.setUser).toHaveBeenCalledWith(DefaultUser);
Expand All @@ -95,6 +97,8 @@ describe('OptimizelyProvider', () => {
});

it('should succeed just userAttributes provided', () => {
// @ts-ignore
mockReactClient.user = undefined;
render(<OptimizelyProvider optimizely={mockReactClient} userAttributes={{ attr1: 'value1' }} />);

expect(mockReactClient.setUser).toHaveBeenCalledWith({
Expand Down
5 changes: 5 additions & 0 deletions src/Provider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,11 @@ export class OptimizelyProvider extends React.Component<OptimizelyProviderProps,
};
// deprecation warning
logger.warn('Passing userId and userAttributes as props is deprecated, please switch to using `user` prop');
} else if (optimizely.user) {
finalUser = {
id: optimizely.user.id,
attributes: optimizely.user.attributes || userAttributes || {},

Check warning on line 79 in src/Provider.tsx

View workflow job for this annotation

GitHub Actions / Coverage annotations (🧪 jest-coverage-report-action)

🌿 Branch is not covered

Warning! Not covered branch

Check warning on line 79 in src/Provider.tsx

View workflow job for this annotation

GitHub Actions / Coverage annotations (🧪 jest-coverage-report-action)

🌿 Branch is not covered

Warning! Not covered branch
};
} else {
finalUser = {
id: DefaultUser.id,
Expand Down

0 comments on commit b8d9765

Please sign in to comment.