test: add unit tests for Freighter error mapping - #1024
Open
Queen-T16 wants to merge 1 commit into
Open
Conversation
Extend src/utils/freighterErrors.ts so it can be fully tested and matches
the spirit of contractErrors.ts:
- Add isExtensionNotInstalled() and FreighterExtensionNotInstalledError to
detect the extension-not-installed case.
- Add parseFreighterError() to map any thrown value to a user-facing
message, falling back to a generic message for unrecognized error objects
instead of crashing.
- Error messages are now centralized as exported constants and reuse a
shared errorMessage() extractor (handles Error, string, flat objects, and
nested { error: { message } } shapes).
- wrapFreighterError() now re-throws typed errors for both known cases and
re-throws unrecognized errors unchanged.
Add src/__tests__/utils/freighterErrors.test.ts covering user-rejected
signature errors, extension-not-installed errors, and unrecognized error
objects falling back to a generic message.
Closes Iris-IV#800
Contributor
|
Auto-review failed (API error). Leaving PR for human review. |
|
@Queen-T16 Great news! 🎉 Based on an automated assessment of this PR, the linked Wave issue(s) no longer count against your application limits. You can now already apply to more issues while waiting for a review of this PR. Keep up the great work! 🚀 |
Contributor
|
solid coverage: the new
gate: branch is behind main; rebase and rerun CI, then good to merge. (no stacking concerns with your #1023/#1025, the files are disjoint.) |
3 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Closes #800 — [Testing] Add unit tests for
freighterErrorsmapping.src/utils/freighterErrors.tspreviously had no dedicated test coverage. This PR adds a full unit-test suite and extends the module (in the spirit of the already-testedcontractErrors.ts) so the required cases are both testable and mapped to user-facing messages.Changes
src/utils/freighterErrors.tsisExtensionNotInstalled(error)— detects the "Freighter extension not installed / unavailable" case (patterns likenot installed,is not defined,window.freighter,no freighter).FreighterExtensionNotInstalledError— typed error thrown bywrapFreighterError()for the missing-extension case.parseFreighterError(error): string— maps any thrown value to a user-facing message:USER_CANCELLED_MESSAGEFREIGHTER_NOT_INSTALLED_MESSAGE{},{ code: 4001 }),null,undefined→GENERIC_FREIGHTER_ERROR_MESSAGE(no crash)errorMessage()extractor handlesError, strings, flat objects, and nested{ error: { message } }shapes.wrapFreighterError()now re-throws typed errors for both known cases and re-throws unrecognized errors unchanged (existing callers incontractClient.ts/offchainApiClient.tsare unaffected).src/__tests__/utils/freighterErrors.test.ts(new)Acceptance criteria
src/tests/utils/freighterErrors.test.ts(see note above — added undersrc/__tests__/utils/per repo convention).Verification
npx jest src/__tests__/utils/freighterErrors.test.ts).eslintclean on both touched files.WalletContextsurfaces errors (out of scope).Pre-existing failures unrelated to this change (verified on
main):src/__tests__/lib/contractClient.test.ts(1 test) and the typecheck errors inCauseDetailClient.tsx/WalletContext.tsx.Out of scope
Changing how
WalletContextsurfaces these errors in the UI (explicitly out of scope in the issue).