Skip to content

Commit

Permalink
chore: another build
Browse files Browse the repository at this point in the history
  • Loading branch information
liviuciulinaru committed Oct 9, 2024
1 parent c75a52e commit a8dac19
Showing 1 changed file with 100 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,15 @@ const useMockFeature = useFeature as jest.Mock;
describe("useSwapLiveConfig", () => {
// Setup the mock for useFeatureFlags to return an object with getFeature
const setupFeatureFlagsMock = (
flags: Partial<{ enabled: boolean; params: { manifest_id: string } }>[],
flags: Partial<
{ enabled: boolean; params: { manifest_id: string; variant?: string } } | undefined
>[],
) => {
const flagsKeys = [
"ptxSwapLiveAppDemoZero",
"ptxSwapLiveAppDemoOne",
"ptxSwapLiveAppDemoThree",
"ptxSwapCoreExperiment",
];

useMockFeature.mockImplementation(flagName => flags[flagsKeys.indexOf(flagName)] ?? null);
Expand All @@ -40,7 +43,7 @@ describe("useSwapLiveConfig", () => {
expect(result.current).not.toBeNull();

// eslint-disable-next-line @typescript-eslint/no-explicit-any
expect((result.current?.params as any)?.manifest_id).toEqual("demo_3");
expect((result.current?.params as any)?.manifest_id).toEqual("demo_0");
});

it("should return null if both features are disabled", () => {
Expand Down Expand Up @@ -97,4 +100,99 @@ describe("useSwapLiveConfig", () => {
params: { manifest_id: "swap-live-app-demo-3" },
});
});

it("should return config when ptxSwapCoreExperiment has valid variant Demo0", () => {
const expected = {
enabled: true,
params: { manifest_id: "swap-live-app-demo-0", variant: "Demo0" },
};
setupFeatureFlagsMock([{ enabled: false }, { enabled: false }, { enabled: false }, expected]);
const { result } = renderHook(() => useSwapLiveConfig());
expect(result.current).toEqual(expected);
});

it("should return config when ptxSwapCoreExperiment has valid variant Demo3", () => {
setupFeatureFlagsMock([
{ enabled: false },
{ enabled: false },
{ enabled: false },
{ enabled: true, params: { manifest_id: "swap-live-app-demo-3", variant: "Demo3" } },
]);
const { result } = renderHook(() => useSwapLiveConfig());
expect(result.current).toEqual({
enabled: true,
params: { manifest_id: "swap-live-app-demo-3", variant: "Demo3" },
});
});

it("should return config when ptxSwapCoreExperiment has valid variant Demo3Thorswap", () => {
setupFeatureFlagsMock([
{ enabled: false },
{ enabled: false },
{ enabled: false },
{ enabled: true, params: { manifest_id: "swap-live-app-demo-3", variant: "Demo3Thorswap" } },
]);
const { result } = renderHook(() => useSwapLiveConfig());
expect(result.current).toEqual({
enabled: true,
params: { manifest_id: "swap-live-app-demo-3", variant: "Demo3Thorswap" },
});
});

it("should return demoZero if demoThree and are enabled", () => {
setupFeatureFlagsMock([
{ enabled: true, params: { manifest_id: "swap-live-app-demo-0" } },
{ enabled: false },
{ enabled: true, params: { manifest_id: "swap-live-app-demo-3" } },
]);
const { result } = renderHook(() => useSwapLiveConfig());
expect(result.current).toEqual({
enabled: true,
params: { manifest_id: "swap-live-app-demo-0" },
});
});

it("should return demoZero if all demo flags are enabled", () => {
setupFeatureFlagsMock([
{ enabled: true, params: { manifest_id: "swap-live-app-demo-0" } },
{ enabled: true, params: { manifest_id: "swap-live-app-demo-1" } },
{ enabled: true, params: { manifest_id: "swap-live-app-demo-3" } },
]);
const { result } = renderHook(() => useSwapLiveConfig());
expect(result.current).toEqual({
enabled: true,
params: { manifest_id: "swap-live-app-demo-0" },
});
});

it("should prioritize demoZero over demo flags if all are enabled", () => {
setupFeatureFlagsMock([
{ enabled: true, params: { manifest_id: "swap-live-app-demo-0" } },
{ enabled: true, params: { manifest_id: "swap-live-app-demo-1" } },
{ enabled: true, params: { manifest_id: "swap-live-app-demo-3" } },
{ enabled: true, params: { manifest_id: "swap-live-app-demo-3", variant: "Demo3" } },
]);
const { result } = renderHook(() => useSwapLiveConfig());
expect(result.current).toEqual({
enabled: true,
params: { manifest_id: "swap-live-app-demo-0" },
});
});

it("should return null when coreExperiment is enabled but has no variant", () => {
setupFeatureFlagsMock([
{ enabled: false },
{ enabled: false },
{ enabled: false },
{ enabled: true, params: { manifest_id: "core-experiment" } },
]);
const { result } = renderHook(() => useSwapLiveConfig());
expect(result.current).toBeNull();
});

it("should return null when all flags are undefined", () => {
setupFeatureFlagsMock([undefined, undefined, undefined, undefined]);
const { result } = renderHook(() => useSwapLiveConfig());
expect(result.current).toBeNull();
});
});

0 comments on commit a8dac19

Please sign in to comment.