The easy-to-use open source Business Intelligence and Embedded Analytics tool that lets everyone work with data :bar_chart:
TypeScript analyticsbibusiness-intelligencebusinessintelligenceclojuredashboarddatadata-analysisdata-visualizationdatabasemetabasemysqlpostgrespostgresqlreportingslacksql-editorvisualization
GDGT-1859: Fix enabling Advanced Transforms (#70183)
Stas Gavrylov5c6250fe4dd6
diff --git a/enterprise/frontend/src/metabase-enterprise/transforms-python/upsells/PythonTransformsUpsellModal/CloudPurchaseContent.tsx b/enterprise/frontend/src/metabase-enterprise/transforms-python/upsells/PythonTransformsUpsellModal/CloudPurchaseContent.tsxindex e107cecfeea..550c5932faa 100644--- a/enterprise/frontend/src/metabase-enterprise/transforms-python/upsells/PythonTransformsUpsellModal/CloudPurchaseContent.tsx+++ b/enterprise/frontend/src/metabase-enterprise/transforms-python/upsells/PythonTransformsUpsellModal/CloudPurchaseContent.tsx@@ -30,8 +30,8 @@ export const CloudPurchaseContent = (props: CloudPurchaseContentProps) => {const handleCloudPurchase = useCallback(async () => {trackUpsellClicked({ location: LOCATION, campaign: CAMPAIGN });+settingUpModalHandlers.open();- handleModalClose();try {await purchaseCloudAddOn({product_type: "transforms-advanced",@@ -41,7 +41,9 @@ export const CloudPurchaseContent = (props: CloudPurchaseContentProps) => {sendErrorToast(t`It looks like something went wrong. Please refresh the page and try again.`,);+ } finally {settingUpModalHandlers.close();+ handleModalClose();}}, [handleModalClose,diff --git a/enterprise/frontend/src/metabase-enterprise/transforms-python/upsells/PythonTransformsUpsellModal/CloudPurchaseContent.unit.spec.tsx b/enterprise/frontend/src/metabase-enterprise/transforms-python/upsells/PythonTransformsUpsellModal/CloudPurchaseContent.unit.spec.tsxindex 88cc7a96ede..d2cc0810cb4 100644--- a/enterprise/frontend/src/metabase-enterprise/transforms-python/upsells/PythonTransformsUpsellModal/CloudPurchaseContent.unit.spec.tsx+++ b/enterprise/frontend/src/metabase-enterprise/transforms-python/upsells/PythonTransformsUpsellModal/CloudPurchaseContent.unit.spec.tsx@@ -2,7 +2,7 @@ import userEvent from "@testing-library/user-event";import fetchMock from "fetch-mock";import { setupPropertiesEndpoints } from "__support__/server-mocks";-import { renderWithProviders, screen } from "__support__/ui";+import { act, renderWithProviders, screen, waitFor } from "__support__/ui";import {createMockSettings,createMockTokenFeatures,@@ -71,7 +71,38 @@ describe("CloudPurchaseContent", () => {).toBeInTheDocument();});- it("purchases transforms-advanced and closes parent modal on confirm", async () => {+ it("shows setting up modal while purchase is in progress", async () => {+ let resolveRequest!: (value: unknown) => void;+ const pendingResponse = new Promise((resolve) => {+ resolveRequest = resolve;+ });++ fetchMock.post(+ "path:/api/ee/cloud-add-ons/transforms-advanced",+ pendingResponse,+ );++ setup({+ isTrialFlow: false,+ pythonPrice: 250,+ });++ await userEvent.click(+ screen.getByRole("button", { name: "Confirm purchase" }),+ );++ // While the request is in-flight, the setting up modal should be visible+ expect(+ screen.getByText("Setting up Python transforms, please wait"),+ ).toBeInTheDocument();++ // Resolve the request+ await act(async () => {+ resolveRequest(200);+ });+ });++ it("calls the API and closes parent modal on successful purchase", async () => {fetchMock.post("path:/api/ee/cloud-add-ons/transforms-advanced", 200);const { handleModalClose } = setup({@@ -83,22 +114,44 @@ describe("CloudPurchaseContent", () => {screen.getByRole("button", { name: "Confirm purchase" }),);- await fetchMock.callHistory.flush();+ await waitFor(() => {+ expect(+ fetchMock.callHistory+ .calls()+ .some(+ (call) =>+ call.url.endsWith("/api/ee/cloud-add-ons/transforms-advanced") &&+ call.options.method === "POST",+ ),+ ).toBe(true);+ });- expect(- fetchMock.callHistory- .calls()- .some(- (call) =>- call.url.endsWith("/api/ee/cloud-add-ons/transforms-advanced") &&- call.options.method === "POST",- ),- ).toBe(true);+ // After success, the finally block closes the parent modal+ await waitFor(() => {+ expect(handleModalClose).toHaveBeenCalled();+ });+ });++ it("closes setting up modal and parent modal on error", async () => {+ fetchMock.post("path:/api/ee/cloud-add-ons/transforms-advanced", 500);++ const { handleModalClose } = setup({+ isTrialFlow: false,+ pythonPrice: 250,+ });- expect(handleModalClose).toHaveBeenCalled();+ await userEvent.click(+ screen.getByRole("button", { name: "Confirm purchase" }),+ );+ // After error, finally block closes the parent modal+ await waitFor(() => {+ expect(handleModalClose).toHaveBeenCalled();+ });++ // Setting up modal should be closed (not visible)expect(- screen.getByText("Setting up Python transforms, please wait"),- ).toBeInTheDocument();+ screen.queryByText("Setting up Python transforms, please wait"),+ ).not.toBeInTheDocument();});});diff --git a/enterprise/frontend/src/metabase-enterprise/transforms/upsells/pages/TransformsUpsellPage/components/PricingSummary.tsx b/enterprise/frontend/src/metabase-enterprise/transforms/upsells/pages/TransformsUpsellPage/components/PricingSummary.tsxindex 185175caa8b..dae99e7221c 100644--- a/enterprise/frontend/src/metabase-enterprise/transforms/upsells/pages/TransformsUpsellPage/components/PricingSummary.tsx+++ b/enterprise/frontend/src/metabase-enterprise/transforms/upsells/pages/TransformsUpsellPage/components/PricingSummary.tsx@@ -6,6 +6,7 @@ import { useMetadataToasts } from "metabase/metadata/hooks";import { Button, Divider, Group, Text } from "metabase/ui";import { usePurchaseCloudAddOnMutation } from "metabase-enterprise/api";import { TransformsSettingUpModal } from "metabase-enterprise/transforms/upsells/components/TransformsSettingUpModal";+import { Urls } from "metabase-enterprise/urls";import type { TransformTier } from "./TierSelection";@@ -30,6 +31,7 @@ export const PricingSummary = (props: PricingSummaryProps) => {await purchaseCloudAddOn({product_type: productType,}).unwrap();+ window.location.href = Urls.transformList(); // On success, do a full-page redirect to transforms list} catch {sendErrorToast(t`It looks like something went wrong. Please refresh the page and try again.`,diff --git a/enterprise/frontend/src/metabase-enterprise/transforms/upsells/pages/TransformsUpsellPage/components/PricingSummary.unit.spec.tsx b/enterprise/frontend/src/metabase-enterprise/transforms/upsells/pages/TransformsUpsellPage/components/PricingSummary.unit.spec.tsxindex fc1800cb889..bf89ac36ca1 100644--- a/enterprise/frontend/src/metabase-enterprise/transforms/upsells/pages/TransformsUpsellPage/components/PricingSummary.unit.spec.tsx+++ b/enterprise/frontend/src/metabase-enterprise/transforms/upsells/pages/TransformsUpsellPage/components/PricingSummary.unit.spec.tsx@@ -3,7 +3,7 @@ import fetchMock from "fetch-mock";import type { ComponentProps } from "react";import { setupPropertiesEndpoints } from "__support__/server-mocks";-import { renderWithProviders, screen } from "__support__/ui";+import { renderWithProviders, screen, waitFor } from "__support__/ui";import { createMockSettings } from "metabase-types/api/mocks";import { PricingSummary } from "./PricingSummary";@@ -18,6 +18,7 @@ describe("PricingSummary", () => {beforeEach(() => {fetchMock.post("path:/api/ee/cloud-add-ons/transforms-advanced", 200);fetchMock.post("path:/api/ee/cloud-add-ons/transforms-basic", 200);+ fetchMock.post("path:/api/premium-features/token/refresh", 200);setupPropertiesEndpoints(createMockSettings());});@@ -71,4 +72,28 @@ describe("PricingSummary", () => {).toBeInTheDocument();});});++ describe("purchase flow", () => {+ it("closes setting up modal on error without redirecting", async () => {+ fetchMock.removeRoutes();+ fetchMock.post("path:/api/ee/cloud-add-ons/transforms-basic", 500);+ fetchMock.post("path:/api/premium-features/token/refresh", 200);+ setupPropertiesEndpoints(createMockSettings());++ renderWithProviders(+ <PricingSummary {...defaultProps} selectedTier="basic" />,+ );++ await userEvent.click(+ screen.getByRole("button", { name: "Confirm purchase" }),+ );++ // Setting up modal should be dismissed after error+ await waitFor(() => {+ expect(+ screen.queryByText("Setting up transforms, please wait"),+ ).not.toBeInTheDocument();+ });+ });+ });});