diff --git a/packages/node/src/remote/client.ts b/packages/node/src/remote/client.ts index b35794e..f09c115 100644 --- a/packages/node/src/remote/client.ts +++ b/packages/node/src/remote/client.ts @@ -118,14 +118,20 @@ export class RemoteEvaluationClient { flagKeys: options?.flagKeys, timeoutMillis: timeoutMillis, }; - if (options?.tracksAssignment) { - getVariantsOptions.trackingOption = options?.tracksAssignment + if ( + options?.tracksAssignment !== undefined && + options?.tracksAssignment !== null + ) { + getVariantsOptions.trackingOption = options.tracksAssignment ? 'track' : 'no-track'; } - if (options?.tracksExposure) { + if ( + options?.tracksExposure !== undefined && + options?.tracksExposure !== null + ) { (getVariantsOptions as any).exposureTrackingOption = - options?.tracksExposure ? 'track' : 'no-track'; + options.tracksExposure ? 'track' : 'no-track'; } const results = await this.evaluationApi.getVariants( userContext, diff --git a/packages/node/test/remote/client.test.ts b/packages/node/test/remote/client.test.ts index f541100..2e44c11 100644 --- a/packages/node/test/remote/client.test.ts +++ b/packages/node/test/remote/client.test.ts @@ -104,6 +104,26 @@ describe('ExperimentClient.fetch', () => { }), ); }); + + test('ExperimentClient.fetch, v2 tracksAssignment false and tracksExposure false', async () => { + const client = new RemoteEvaluationClient(API_KEY, {}); + const getVariantsSpy = jest.spyOn( + (client as any).evaluationApi, + 'getVariants', + ); + const variants = await client.fetchV2(testUser, { + tracksAssignment: false, + tracksExposure: false, + }); + expect(variants['sdk-ci-test'].key).toEqual('on'); + expect(getVariantsSpy).toHaveBeenCalledWith( + expect.objectContaining(testUser), + expect.objectContaining({ + trackingOption: 'no-track', + exposureTrackingOption: 'no-track', + }), + ); + }); }); describe('ExperimentClient.fetch, retry with different response codes', () => {