Skip to content

Commit

Permalink
fix: make variant optional in exposure object for segment (#26)
Browse files Browse the repository at this point in the history
* fix: make variant optional in exposure object

* fix: dont set variant in unexposure

* fix: fix test

* fix: delete yarn lock

* fix: test
  • Loading branch information
bgiori committed Mar 10, 2022
1 parent 5ca7fb6 commit aa29994
Show file tree
Hide file tree
Showing 5 changed files with 376 additions and 332 deletions.
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,12 @@
"@rollup/plugin-typescript": "^8.2.0",
"@types/jest": "^26.0.21",
"@types/node": "^14.6.0",
"@typescript-eslint/eslint-plugin": "^3.9.1",
"@typescript-eslint/parser": "^3.9.1",
"@typescript-eslint/eslint-plugin": "3.9.1",
"@typescript-eslint/parser": "3.9.1",
"eslint": "^7.7.0",
"eslint-config-prettier": "^6.11.0",
"eslint-plugin-import": "^2.22.1",
"eslint-plugin-jest": "^24.3.2",
"eslint-plugin-jest": "24.3.2",
"eslint-plugin-prettier": "^3.1.4",
"jest": "^26.6.3",
"lerna": "^3.22.1",
Expand Down
2 changes: 1 addition & 1 deletion packages/browser/src/experimentClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -479,7 +479,7 @@ export class ExperimentClient implements Client {
if (isFallback(source) || !variant?.value) {
// fallbacks indicate not being allocated into an experiment, so
// we can unset the property
this.exposureTrackingProvider?.track({ flag_key: key, variant: null });
this.exposureTrackingProvider?.track({ flag_key: key });
this.analyticsProvider?.unsetUserProperty?.(event);
} else if (variant?.value) {
// only track when there's a value for a non fallback variant
Expand Down
2 changes: 1 addition & 1 deletion packages/browser/src/types/exposure.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
*/
export type Exposure = {
flag_key: string;
variant: string | null | undefined;
variant?: string;
};

/**
Expand Down
3 changes: 1 addition & 2 deletions packages/browser/test/client.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -251,12 +251,11 @@ test('ExperimentClient.variant, with exposure tracking provider, track called on
expect(trackSpy).toBeCalledTimes(1);
expect(trackSpy).toHaveBeenCalledWith({
flag_key: 'key-that-does-not-exist',
variant: null,
});
expect(logEventSpy).toBeCalledTimes(1);
expect(logEventSpy).toHaveBeenCalledWith({
eventType: '$exposure',
eventProperties: { flag_key: 'key-that-does-not-exist', variant: null },
eventProperties: { flag_key: 'key-that-does-not-exist' },
});

for (let i = 0; i < 10; i++) {
Expand Down

0 comments on commit aa29994

Please sign in to comment.