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-8184] override attribute bug fix of track method #287

Merged
merged 3 commits into from
Nov 6, 2024
Merged
Show file tree
Hide file tree
Changes from 2 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
52 changes: 31 additions & 21 deletions src/client.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1390,36 +1390,46 @@ describe('ReactSDKClient', () => {
expect(mockFn).toHaveBeenCalledTimes(0);
});

it('track works as expected', () => {
const mockFn = mockInnerClient.track as jest.Mock;

instance.track('evt1');

expect(mockFn).toHaveBeenCalledTimes(1);
expect(mockFn).toHaveBeenCalledWith('evt1', 'user1', { foo: 'bar' }, undefined);
describe('track with different parameters', () => {
it('track with only event key, calls inner client with valid arguments', () => {
const mockFn = mockInnerClient.track as jest.Mock;
instance.track('evt1');

mockFn.mockReset();
expect(mockFn).toHaveBeenCalledTimes(1);
expect(mockFn).toHaveBeenCalledWith('evt1', 'user1', { foo: 'bar' }, undefined);
});

instance.track('evt1', 'user2', { bar: 'baz' });
it('track with event key and overrided user id and attributes, calls inner client with valid arguments', () => {
const mockFn = mockInnerClient.track as jest.Mock;
instance.track('evt1', 'user2', { bar: 'baz' });

expect(mockFn).toHaveBeenCalledTimes(1);
expect(mockFn).toHaveBeenCalledWith('evt1', 'user2', { bar: 'baz' }, undefined);
expect(mockFn).toHaveBeenCalledTimes(1);
expect(mockFn).toHaveBeenCalledWith('evt1', 'user2', { bar: 'baz' }, undefined);
});

mockFn.mockReset();
it('track with event key and event tags, calls inner client with valid arguments', () => {
const mockFn = mockInnerClient.track as jest.Mock;
instance.track('evt1', { tagKey: 'tagVal' });
junaed-optimizely marked this conversation as resolved.
Show resolved Hide resolved

// Use pre-set user with event tags
instance.track('evt1', { tagKey: 'tagVal' });
expect(mockFn).toHaveBeenCalledTimes(1);
expect(mockFn).toHaveBeenCalledWith('evt1', 'user1', { foo: 'bar' }, { tagKey: 'tagVal' });
});

expect(mockFn).toHaveBeenCalledTimes(1);
expect(mockFn).toHaveBeenCalledWith('evt1', 'user1', { foo: 'bar' }, { tagKey: 'tagVal' });
it('track with event key, overrided user id and attributes and event tags, calls inner client with valid arguments', () => {
const mockFn = mockInnerClient.track as jest.Mock;
instance.track('evt1', 'user3', { bla: 'bla' }, { tagKey: 'tagVal' });

mockFn.mockReset();
expect(mockFn).toHaveBeenCalledTimes(1);
expect(mockFn).toHaveBeenCalledWith('evt1', 'user3', { bla: 'bla' }, { tagKey: 'tagVal' });
});

// Use overrides with event tags
instance.track('evt1', 'user3', { bla: 'bla' }, { tagKey: 'tagVal' });
it('track with event key, tags, and overrided attributes, calls inner client with valid arguments', () => {
const mockFn = mockInnerClient.track as jest.Mock;
instance.track('evt1', { tagKey: 'tagVal' }, { bla: 'bla' });

expect(mockFn).toHaveBeenCalledTimes(1);
expect(mockFn).toHaveBeenCalledWith('evt1', 'user3', { bla: 'bla' }, { tagKey: 'tagVal' });
expect(mockFn).toHaveBeenCalledTimes(1);
expect(mockFn).toHaveBeenCalledWith('evt1', 'user1', { bla: 'bla' }, { tagKey: 'tagVal' });
});
});
});

Expand Down
1 change: 0 additions & 1 deletion src/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -635,7 +635,6 @@ class OptimizelyReactSDKClient implements ReactSDKClient {
if (typeof overrideUserId !== 'undefined' && typeof overrideUserId !== 'string') {
eventTags = overrideUserId;
overrideUserId = undefined;
overrideAttributes = undefined;
}

const user = this.getUserWithOverrides(overrideUserId, overrideAttributes);
Expand Down
Loading