Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FSSDK-10880] override initial user bug adjustment #292

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@
};
// 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 || {},

Check warning on line 80 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
Loading