Skip to content

Commit

Permalink
Get first render experiments
Browse files Browse the repository at this point in the history
  • Loading branch information
nbierdeman committed May 2, 2024
1 parent 9eb713f commit af0683a
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 34 deletions.
2 changes: 1 addition & 1 deletion .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,6 @@ module.exports = {

// Experiment Variable
__DISABLE_SET_COOKIE__: true,
__EXPERIMENTATION__: true,
__FIRST_RENDER_EXPERIMENTS__: true,
},
};
9 changes: 4 additions & 5 deletions src/declarations.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import { ENV, COMPONENTS, PROTOCOL } from "@paypal/sdk-constants/src";

// $FlowFixMe[toplevel-library-import]
import type { FundingEligibilityType } from "./types";
import type { FundingEligibilityType, FirstRenderExperiments } from "./types";

declare var __PROTOCOL__: $Values<typeof PROTOCOL>;
declare var __HOST__: string;
Expand Down Expand Up @@ -33,7 +33,6 @@ declare var __FUNDING_ELIGIBILITY__: FundingEligibilityType;

// Experiment Variable
declare var __DISABLE_SET_COOKIE__: boolean;
declare var __EXPERIMENTATION__: {|
__EXPERIENCE__?: string,
__TREATMENT__?: string,
|};

// $FlowIgnore[value-as-type]
declare var __FIRST_RENDER_EXPERIMENTS__: FirstRenderExperiments;
18 changes: 4 additions & 14 deletions src/global.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import {
} from "@paypal/sdk-constants/src";
import { isDevice } from "@krakenjs/belter/src";

import type { Experimentation } from "./types";
import type { FirstRenderExperiments } from "./types";

export function getSDKHost(): string {
return __SDK_HOST__;
Expand Down Expand Up @@ -122,19 +122,9 @@ export function getDisableSetCookie(): boolean {
return false;
}

export function getExperimentation(): Experimentation | null {
if (typeof __EXPERIMENTATION__ !== "undefined") {
if (__EXPERIMENTATION__) {
const experimation: Experimentation = {};
if (__EXPERIMENTATION__.__EXPERIENCE__) {
experimation.experience = __EXPERIMENTATION__.__EXPERIENCE__;
}
if (__EXPERIMENTATION__.__TREATMENT__) {
experimation.treatment = __EXPERIMENTATION__.__TREATMENT__;
}
return experimation;
}
export function getFirstRenderExperiments(): FirstRenderExperiments | null {
if (typeof __FIRST_RENDER_EXPERIMENTS__ !== "undefined") {
return __FIRST_RENDER_EXPERIMENTS__;
}

return null;
}
20 changes: 9 additions & 11 deletions src/global.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import {
getVersion,
getCorrelationID,
getPlatform,
getExperimentation,
getFirstRenderExperiments,
} from "./global";

describe(`globals cases`, () => {
Expand Down Expand Up @@ -174,29 +174,27 @@ describe(`globals cases`, () => {
});

it("should successfully get experimation value", () => {
window.__EXPERIMENTATION__ = {
__EXPERIENCE__: "1234, 4321",
__TREATMENT__: "8765,7890",
window.__FIRST_RENDER_EXPERIMENTS__ = {
firstRenderExperiment: true,
};
const expectedResult = {
experience: "1234, 4321",
treatment: "8765,7890",
firstRenderExperiment: true,
};
const result = getExperimentation();
const result = getFirstRenderExperiments();
expect(result).toEqual(expectedResult);
});

it("should get experimation null value", () => {
window.__EXPERIMENTATION__ = null;
window.__FIRST_RENDER_EXPERIMENTS__ = null;
const expectedResult = null;
const result = getExperimentation();
const result = getFirstRenderExperiments();
expect(result).toEqual(expectedResult);
});

it("should get experimation empty value", () => {
window.__EXPERIMENTATION__ = {};
window.__FIRST_RENDER_EXPERIMENTS__ = {};
const expectedResult = {};
const result = getExperimentation();
const result = getFirstRenderExperiments();
expect(result).toEqual(expectedResult);
});
});
4 changes: 4 additions & 0 deletions src/types.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,7 @@ export type GetExperimentation = {
// eslint-disable-next-line flowtype/no-weak-types
[any]: empty,
};

export type FirstRenderExperiments = {
[key: string]: boolean,
};
5 changes: 2 additions & 3 deletions test/globals.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,8 @@ export const sdkClientTestGlobals = {
__PAYPAL_API_DOMAIN__: "mock://sandbox.paypal.com",
__COMPONENTS__: ["buttons"],
__DISABLE_SET_COOKIE__: true,
__EXPERIMENTATION__: {
__EXPERIENCE__: "1122",
__TREATMENT__: "1234",
__FIRST_RENDER_EXPERIMENTS__: {
firstRenderExperiment: true,
},
crypto: crypto.webcrypto,
};

0 comments on commit af0683a

Please sign in to comment.