Skip to content

Commit

Permalink
Merge branch 'master' into dependabot/npm_and_yarn/rollup-3.29.5
Browse files Browse the repository at this point in the history
  • Loading branch information
junaed-optimizely authored Nov 7, 2024
2 parents 914b1a7 + fcedfe9 commit 3d72c6a
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 1 deletion.
2 changes: 1 addition & 1 deletion .github/workflows/integration_test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ jobs:
- name: Checkout branch
uses: actions/checkout@v3
with:
token: ${{ secrets.CI_USER_TOKEN }}
token: ${{ secrets.CI_USER_TOKEN || secrets.GITHUB_TOKEN }}
repository: 'optimizely/travisci-tools'
path: 'home/runner/travisci-tools'
ref: 'master'
Expand Down
19 changes: 19 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 All @@ -103,6 +107,21 @@ describe('OptimizelyProvider', () => {
});
});

it('should succeed with the initial user available in client', () => {
render(<OptimizelyProvider optimizely={mockReactClient} />);

expect(mockReactClient.setUser).toHaveBeenCalledWith(user1);
});

it('should succeed with the initial user id and newly passed attributes', () => {
render(<OptimizelyProvider optimizely={mockReactClient} userAttributes={{ attr1: 'value2' }} />);

expect(mockReactClient.setUser).toHaveBeenCalledWith({
id: user1.id,
attributes: { attr1: 'value2' },
});
});

it('should not update when isServerSide is true', () => {
// Initial render
const { rerender } = render(<OptimizelyProvider optimizely={mockReactClient} isServerSide={true} user={user1} />);
Expand Down
6 changes: 6 additions & 0 deletions src/Provider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,12 @@ 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) {
const { id, attributes } = optimizely.user;
finalUser = {
id,
attributes: userAttributes || attributes || {},
};
} else {
finalUser = {
id: DefaultUser.id,
Expand Down

0 comments on commit 3d72c6a

Please sign in to comment.