From 93470526f03f460e42eb4b953c47d1279b5a29fb Mon Sep 17 00:00:00 2001 From: Diana Savatina Date: Fri, 6 Dec 2024 16:23:18 +0000 Subject: [PATCH 1/2] fix: fixed tests for Some error occurred --- apps/web/src/components/SendFlow/Tez/FormPage.test.tsx | 7 ++++++- .../components/SendFlow/Undelegation/FormPage.test.tsx | 10 ++++++++-- 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/apps/web/src/components/SendFlow/Tez/FormPage.test.tsx b/apps/web/src/components/SendFlow/Tez/FormPage.test.tsx index 795f8d4e47..c589812fd2 100644 --- a/apps/web/src/components/SendFlow/Tez/FormPage.test.tsx +++ b/apps/web/src/components/SendFlow/Tez/FormPage.test.tsx @@ -167,7 +167,12 @@ describe("
", () => { const submitButton = screen.getByText("Preview"); await waitFor(() => expect(submitButton).toBeEnabled()); const estimateMock = jest.mocked(estimate); - estimateMock.mockRejectedValue(new Error("Some error occurred")); + expect(mockToast).toHaveBeenCalledWith({ + description: + "Something went wrong. Please try again or contact support if the issue persists.", + status: "error", + isClosable: true, + }); await act(() => user.click(submitButton)); diff --git a/apps/web/src/components/SendFlow/Undelegation/FormPage.test.tsx b/apps/web/src/components/SendFlow/Undelegation/FormPage.test.tsx index 9be65808b9..f2ff9fd143 100644 --- a/apps/web/src/components/SendFlow/Undelegation/FormPage.test.tsx +++ b/apps/web/src/components/SendFlow/Undelegation/FormPage.test.tsx @@ -93,7 +93,12 @@ describe("", () => { ); const estimateMock = jest.mocked(estimate); - estimateMock.mockRejectedValue(new Error("Some error occurred")); + expect(mockToast).toHaveBeenCalledWith({ + description: + "Something went wrong. Please try again or contact support if the issue persists.", + status: "error", + isClosable: true, + }); const submitButton = screen.getByText("Preview"); await waitFor(() => expect(submitButton).toBeEnabled()); @@ -101,7 +106,8 @@ describe("", () => { expect(estimateMock).toHaveBeenCalledTimes(1); expect(mockToast).toHaveBeenCalledWith({ - description: "Some error occurred", + description: + "Something went wrong. Please try again or contact support if the issue persists.", status: "error", isClosable: true, }); From 8afad3b533658b0d79cd99d780dabf3bfcc542a2 Mon Sep 17 00:00:00 2001 From: Oleg Chendighelean Date: Mon, 9 Dec 2024 11:05:51 +0000 Subject: [PATCH 2/2] Fix custom errors handling --- .../restoreBackupFile/RestoreBackupFile.test.tsx | 5 ++++- .../components/SendFlow/Delegation/FormPage.test.tsx | 3 ++- .../src/components/SendFlow/Tez/FormPage.test.tsx | 3 ++- .../SendFlow/Undelegation/FormPage.test.tsx | 3 ++- .../src/utils/beacon/useHandleBeaconMessage.test.tsx | 3 ++- apps/desktop/src/views/batch/BatchView.test.tsx | 3 ++- .../components/SendFlow/Delegation/FormPage.test.tsx | 6 +++--- .../web/src/components/SendFlow/Tez/FormPage.test.tsx | 11 +++-------- .../SendFlow/Undelegation/FormPage.test.tsx | 11 +++-------- .../components/beacon/useHandleBeaconMessage.test.tsx | 3 ++- packages/tezos/src/helpers.ts | 2 +- 11 files changed, 26 insertions(+), 27 deletions(-) diff --git a/apps/desktop/src/components/Onboarding/restoreBackupFile/RestoreBackupFile.test.tsx b/apps/desktop/src/components/Onboarding/restoreBackupFile/RestoreBackupFile.test.tsx index 2b34f1ac28..790f198cf4 100644 --- a/apps/desktop/src/components/Onboarding/restoreBackupFile/RestoreBackupFile.test.tsx +++ b/apps/desktop/src/components/Onboarding/restoreBackupFile/RestoreBackupFile.test.tsx @@ -1,5 +1,6 @@ import { mockToast, useRestoreBackup } from "@umami/state"; import { fileUploadMock, umamiBackup } from "@umami/test-utils"; +import { CustomError } from "@umami/utils"; import { RestoreBackupFile } from "./RestoreBackupFile"; import { @@ -41,7 +42,9 @@ describe("", () => { it("shows error for wrong backup file format", async () => { jest .mocked(useRestoreBackup) - .mockImplementation(() => jest.fn(() => Promise.reject("Invalid backup file."))); + .mockImplementation(() => + jest.fn(() => Promise.reject(new CustomError("Invalid backup file."))) + ); const user = userEvent.setup(); render(); diff --git a/apps/desktop/src/components/SendFlow/Delegation/FormPage.test.tsx b/apps/desktop/src/components/SendFlow/Delegation/FormPage.test.tsx index c9e73e7d6b..f41a8b2468 100644 --- a/apps/desktop/src/components/SendFlow/Delegation/FormPage.test.tsx +++ b/apps/desktop/src/components/SendFlow/Delegation/FormPage.test.tsx @@ -8,6 +8,7 @@ import { } from "@umami/core"; import { type UmamiStore, addTestAccount, assetsActions, makeStore, mockToast } from "@umami/state"; import { executeParams } from "@umami/test-utils"; +import { CustomError } from "@umami/utils"; import { FormPage, type FormValues } from "./FormPage"; import { SignPage } from "./SignPage"; @@ -158,7 +159,7 @@ describe("", () => { }); const estimateMock = jest.mocked(estimate); - estimateMock.mockRejectedValue(new Error("Some error occurred")); + estimateMock.mockRejectedValue(new CustomError("Some error occurred")); await act(() => user.click(submitButton)); diff --git a/apps/desktop/src/components/SendFlow/Tez/FormPage.test.tsx b/apps/desktop/src/components/SendFlow/Tez/FormPage.test.tsx index 24cb6b3799..f6e390ce75 100644 --- a/apps/desktop/src/components/SendFlow/Tez/FormPage.test.tsx +++ b/apps/desktop/src/components/SendFlow/Tez/FormPage.test.tsx @@ -8,6 +8,7 @@ import { } from "@umami/core"; import { type UmamiStore, addTestAccount, makeStore, mockToast } from "@umami/state"; import { executeParams } from "@umami/test-utils"; +import { CustomError } from "@umami/utils"; import { FormPage, type FormValues } from "./FormPage"; import { SignPage } from "./SignPage"; @@ -241,7 +242,7 @@ describe("", () => { const submitButton = screen.getByText("Preview"); await waitFor(() => expect(submitButton).toBeEnabled()); const estimateMock = jest.mocked(estimate); - estimateMock.mockRejectedValue(new Error("Some error occurred")); + estimateMock.mockRejectedValue(new CustomError("Some error occurred")); await act(() => user.click(submitButton)); diff --git a/apps/desktop/src/components/SendFlow/Undelegation/FormPage.test.tsx b/apps/desktop/src/components/SendFlow/Undelegation/FormPage.test.tsx index 81c0f0fe1f..644d3f0e5c 100644 --- a/apps/desktop/src/components/SendFlow/Undelegation/FormPage.test.tsx +++ b/apps/desktop/src/components/SendFlow/Undelegation/FormPage.test.tsx @@ -15,6 +15,7 @@ import { } from "@umami/state"; import { executeParams } from "@umami/test-utils"; import { mockImplicitAddress } from "@umami/tezos"; +import { CustomError } from "@umami/utils"; import { FormPage, type FormValues } from "./FormPage"; import { SignPage } from "./SignPage"; @@ -98,7 +99,7 @@ describe("", () => { ); const estimateMock = jest.mocked(estimate); - estimateMock.mockRejectedValue(new Error("Some error occurred")); + estimateMock.mockRejectedValue(new CustomError("Some error occurred")); const submitButton = screen.getByText("Preview"); await waitFor(() => expect(submitButton).toBeEnabled()); diff --git a/apps/desktop/src/utils/beacon/useHandleBeaconMessage.test.tsx b/apps/desktop/src/utils/beacon/useHandleBeaconMessage.test.tsx index 0347013a1c..05f3a45112 100644 --- a/apps/desktop/src/utils/beacon/useHandleBeaconMessage.test.tsx +++ b/apps/desktop/src/utils/beacon/useHandleBeaconMessage.test.tsx @@ -12,6 +12,7 @@ import { estimate, makeAccountOperations, mockImplicitAccount } from "@umami/cor import { type UmamiStore, WalletClient, addTestAccount, makeStore, mockToast } from "@umami/state"; import { executeParams } from "@umami/test-utils"; import { mockImplicitAddress } from "@umami/tezos"; +import { CustomError } from "@umami/utils"; import { useHandleBeaconMessage } from "./useHandleBeaconMessage"; import { BatchSignPage } from "../../components/SendFlow/Beacon/BatchSignPage"; @@ -251,7 +252,7 @@ describe("", () => { }); it("doesn't open a modal on an error while estimating the fee", async () => { - jest.mocked(estimate).mockRejectedValueOnce(new Error("Something went very wrong!")); + jest.mocked(estimate).mockRejectedValueOnce(new CustomError("Something went very wrong!")); const message: BeaconRequestOutputMessage = { type: BeaconMessageType.OperationRequest, diff --git a/apps/desktop/src/views/batch/BatchView.test.tsx b/apps/desktop/src/views/batch/BatchView.test.tsx index 333aaee8e3..9567a18565 100644 --- a/apps/desktop/src/views/batch/BatchView.test.tsx +++ b/apps/desktop/src/views/batch/BatchView.test.tsx @@ -9,6 +9,7 @@ import { } from "@umami/core"; import { type UmamiStore, addTestAccount, makeStore, mockToast } from "@umami/state"; import { executeParams } from "@umami/test-utils"; +import { CustomError } from "@umami/utils"; import { BatchView } from "./BatchView"; import { act, render, screen, userEvent, within } from "../../mocks/testUtils"; @@ -85,7 +86,7 @@ describe("", () => { it("doesn't show up if the estimation fails with an unknown error", async () => { const user = userEvent.setup(); - jest.mocked(estimate).mockRejectedValue(new Error("something went wrong")); + jest.mocked(estimate).mockRejectedValue(new CustomError("something went wrong")); render(, { store }); diff --git a/apps/web/src/components/SendFlow/Delegation/FormPage.test.tsx b/apps/web/src/components/SendFlow/Delegation/FormPage.test.tsx index a1b70e6df7..9eccca1c64 100644 --- a/apps/web/src/components/SendFlow/Delegation/FormPage.test.tsx +++ b/apps/web/src/components/SendFlow/Delegation/FormPage.test.tsx @@ -8,6 +8,7 @@ import { mockToast, } from "@umami/state"; import { executeParams } from "@umami/test-utils"; +import { CustomError } from "@umami/utils"; import { FormPage, type FormValues } from "./FormPage"; import { SignPage } from "./SignPage"; @@ -112,14 +113,13 @@ describe("", () => { }); const estimateMock = jest.mocked(estimate); - estimateMock.mockRejectedValue(new Error("Some error occurred")); + estimateMock.mockRejectedValue(new CustomError("Some error occurred")); await act(() => user.click(submitButton)); expect(estimateMock).toHaveBeenCalledTimes(1); expect(mockToast).toHaveBeenCalledWith({ - description: - "Something went wrong. Please try again or contact support if the issue persists.", + description: "Some error occurred", status: "error", isClosable: true, }); diff --git a/apps/web/src/components/SendFlow/Tez/FormPage.test.tsx b/apps/web/src/components/SendFlow/Tez/FormPage.test.tsx index c589812fd2..182a36d5b3 100644 --- a/apps/web/src/components/SendFlow/Tez/FormPage.test.tsx +++ b/apps/web/src/components/SendFlow/Tez/FormPage.test.tsx @@ -7,6 +7,7 @@ import { } from "@umami/core"; import { type UmamiStore, addTestAccount, makeStore, mockToast } from "@umami/state"; import { executeParams } from "@umami/test-utils"; +import { CustomError } from "@umami/utils"; import { FormPage } from "./FormPage"; import { SignPage } from "./SignPage"; @@ -167,19 +168,13 @@ describe("", () => { const submitButton = screen.getByText("Preview"); await waitFor(() => expect(submitButton).toBeEnabled()); const estimateMock = jest.mocked(estimate); - expect(mockToast).toHaveBeenCalledWith({ - description: - "Something went wrong. Please try again or contact support if the issue persists.", - status: "error", - isClosable: true, - }); + estimateMock.mockRejectedValue(new CustomError("Some error occurred")); await act(() => user.click(submitButton)); expect(estimateMock).toHaveBeenCalledTimes(1); expect(mockToast).toHaveBeenCalledWith({ - description: - "Something went wrong. Please try again or contact support if the issue persists.", + description: "Some error occurred", status: "error", isClosable: true, }); diff --git a/apps/web/src/components/SendFlow/Undelegation/FormPage.test.tsx b/apps/web/src/components/SendFlow/Undelegation/FormPage.test.tsx index f2ff9fd143..d71e2b16a4 100644 --- a/apps/web/src/components/SendFlow/Undelegation/FormPage.test.tsx +++ b/apps/web/src/components/SendFlow/Undelegation/FormPage.test.tsx @@ -14,6 +14,7 @@ import { } from "@umami/state"; import { executeParams } from "@umami/test-utils"; import { mockImplicitAddress } from "@umami/tezos"; +import { CustomError } from "@umami/utils"; import { FormPage, type FormValues } from "./FormPage"; import { SignPage } from "./SignPage"; @@ -93,12 +94,7 @@ describe("", () => { ); const estimateMock = jest.mocked(estimate); - expect(mockToast).toHaveBeenCalledWith({ - description: - "Something went wrong. Please try again or contact support if the issue persists.", - status: "error", - isClosable: true, - }); + estimateMock.mockRejectedValue(new CustomError("Some error occurred")); const submitButton = screen.getByText("Preview"); await waitFor(() => expect(submitButton).toBeEnabled()); @@ -106,8 +102,7 @@ describe("", () => { expect(estimateMock).toHaveBeenCalledTimes(1); expect(mockToast).toHaveBeenCalledWith({ - description: - "Something went wrong. Please try again or contact support if the issue persists.", + description: "Some error occurred", status: "error", isClosable: true, }); diff --git a/apps/web/src/components/beacon/useHandleBeaconMessage.test.tsx b/apps/web/src/components/beacon/useHandleBeaconMessage.test.tsx index b1a16cd6f9..75144ee224 100644 --- a/apps/web/src/components/beacon/useHandleBeaconMessage.test.tsx +++ b/apps/web/src/components/beacon/useHandleBeaconMessage.test.tsx @@ -12,6 +12,7 @@ import { estimate, makeAccountOperations, mockImplicitAccount } from "@umami/cor import { type UmamiStore, WalletClient, addTestAccount, makeStore, mockToast } from "@umami/state"; import { executeParams } from "@umami/test-utils"; import { mockImplicitAddress } from "@umami/tezos"; +import { CustomError } from "@umami/utils"; import { useHandleBeaconMessage } from "./useHandleBeaconMessage"; import { BatchSignPage } from "../../components/SendFlow/Beacon/BatchSignPage"; @@ -251,7 +252,7 @@ describe("", () => { }); it("doesn't open a modal on an error while estimating the fee", async () => { - jest.mocked(estimate).mockRejectedValueOnce(new Error("Something went very wrong!")); + jest.mocked(estimate).mockRejectedValueOnce(new CustomError("Something went very wrong!")); const message: BeaconRequestOutputMessage = { type: BeaconMessageType.OperationRequest, diff --git a/packages/tezos/src/helpers.ts b/packages/tezos/src/helpers.ts index ae873ab577..3e2f5ad4bf 100644 --- a/packages/tezos/src/helpers.ts +++ b/packages/tezos/src/helpers.ts @@ -130,6 +130,6 @@ export const decryptSecretKey = async (secretKey: string, password: string) => { throw new CustomError("Invalid secret key: checksum doesn't match"); } - throw error; + throw new CustomError(error.message); } };