From 76240a90e3b5b17899c3009d3d7dd20cb0b1e672 Mon Sep 17 00:00:00 2001 From: Md Junaed Hossain <169046794+junaed-optimizely@users.noreply.github.com> Date: Wed, 6 Nov 2024 20:13:36 +0600 Subject: [PATCH 1/3] [FSSDK-8184] override attribute bug fix of track method --- src/client.spec.ts | 52 +++++++++++++++++++++++++++------------------- src/client.ts | 1 - 2 files changed, 31 insertions(+), 22 deletions(-) diff --git a/src/client.spec.ts b/src/client.spec.ts index 9948198..a5e4e1e 100644 --- a/src/client.spec.ts +++ b/src/client.spec.ts @@ -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' }); - // 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.only('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' }); + }); }); }); diff --git a/src/client.ts b/src/client.ts index d073f9b..6a7f8f7 100644 --- a/src/client.ts +++ b/src/client.ts @@ -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); From e851deb831b9379aa4861dc70777cb8010042ee4 Mon Sep 17 00:00:00 2001 From: Md Junaed Hossain <169046794+junaed-optimizely@users.noreply.github.com> Date: Wed, 6 Nov 2024 20:37:06 +0600 Subject: [PATCH 2/3] [FSSDK-8184] test only removal --- src/client.spec.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/client.spec.ts b/src/client.spec.ts index a5e4e1e..2dc98c1 100644 --- a/src/client.spec.ts +++ b/src/client.spec.ts @@ -1423,7 +1423,7 @@ describe('ReactSDKClient', () => { expect(mockFn).toHaveBeenCalledWith('evt1', 'user3', { bla: 'bla' }, { tagKey: 'tagVal' }); }); - it.only('track with event key, tags, and overrided attributes, calls inner client with valid arguments', () => { + 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' }); From 99c53b9f872fe64d867640825f2766ccb2a1a9a4 Mon Sep 17 00:00:00 2001 From: Md Junaed Hossain <169046794+junaed-optimizely@users.noreply.github.com> Date: Wed, 6 Nov 2024 22:41:29 +0600 Subject: [PATCH 3/3] [FSSDK-8184] new case addition --- src/client.spec.ts | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/client.spec.ts b/src/client.spec.ts index 2dc98c1..f5b67d2 100644 --- a/src/client.spec.ts +++ b/src/client.spec.ts @@ -1430,6 +1430,14 @@ describe('ReactSDKClient', () => { expect(mockFn).toHaveBeenCalledTimes(1); expect(mockFn).toHaveBeenCalledWith('evt1', 'user1', { bla: 'bla' }, { tagKey: 'tagVal' }); }); + + it('track with event key, userId undefined, attributes undefined, and event tags, calls inner client with valid arguments', () => { + const mockFn = mockInnerClient.track as jest.Mock; + instance.track('evt1', undefined, undefined, { tagKey: 'tagVal' }); + + expect(mockFn).toHaveBeenCalledTimes(1); + expect(mockFn).toHaveBeenCalledWith('evt1', 'user1', { foo: 'bar' }, { tagKey: 'tagVal' }); + }); }); });