Repository navigation
Fix: 4 issues (#933, #934, #935, #936) - #1017
Merged
Merged
Conversation
Co-authored-by: Simple Agent <agent@simple.dev>
|
@temma02 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! 🚀 |
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.
Closes #933
Closes #934
Closes #935
Closes #936
Issues
#933 Test escapeHtml in receipt-utils (XSS safety)
#934 Test generateReceiptHTML
#935 Test custom token storage in lib/stellar.ts
#936 Test favorite tokens in lib/stellar.ts
Summary
Both target test files already exist and are collected by Vitest, so extend them rather than creating new files.
escapeHtmlinlib/receipt-utils.tsis currently a module-private function (noexport); to test it directly you would need to addexport— prefer testing it indirectly throughgenerateReceiptHTMLto honor the 'no production code changes' acceptance criterion, and note the choice in the PR.lib/stellar.tsusestypeof window === 'undefined'guards, so tests must run in the jsdom environment (Vitest default for this repo) and clearlocalStorageinbeforeEachto avoid cross-test leakage. The custom-token storage key isflowstar:custom-tokens:<network>and the favorites key isflowstar:favorite-tokens; use these exact keys when seeding corrupt JSON.saveCustomTokencaps the list at 10 entries — not required by the issues but a useful extra assertion if convenient.Changes
escapeHtmlandgenerateReceiptHTMLfrom@/lib/receipt-utils. Import both functions (note:escapeHtmlis not currently exported — if it isn't exported, either test it indirectly throughgenerateReceiptHTMLor addexportto the function; prefer indirect testing to avoid production changes, and note any export change in the PR). Reuse the existingmakeStreamfixture andbuildReceiptDatato constructReceiptData. ForescapeHtml(issue Test escapeHtml in receipt-utils (XSS safety) #933): assert each of&,<,>,",'is converted to&,<,>,",'respectively; assert plain text like'hello world'is returned unchanged; and build a stream whoseidis<img src=x onerror=alert(1)>, generate the HTML, and assert the output contains<img src=x onerror=alert(1)>and does NOT contain the raw<img src=x onerror=alert(1)>tag. ForgenerateReceiptHTML(issue Test generateReceiptHTML #934): build a receipt viabuildReceiptData(makeStream(), 'creation-tx', ['withdraw-tx-1'], 'cancel-tx')and assert the HTML contains the stream id (stream-123), sender (GSENDER123), recipient (GRECIPIENT456), token symbol (USDC), and formatted amounts (e.g.100for total,0for withdrawn,100for remaining with 7-decimal token). Add a fixture with a non-round amount (e.g.depositedAmount: 2_500_000_000n→250) to verify decimal formatting. Add separate active vs cancelled fixtures: assert the active receipt containsstatus-activeandActive, and the cancelled receipt containsstatus-cancelledandCancelled(and does not containstatus-active). Runnpm testto confirm all new tests pass. (tests/lib/receipt-utils.test.ts)@/lib/stellar. ImportgetCustomTokens,saveCustomToken,getFavoriteTokens,toggleFavoriteToken, andisFavoriteToken. Add a top-levelbeforeEachthat clearslocalStorage(jsdom is available via Vitest) so tests are isolated. For custom tokens (issue Test custom token storage in lib/stellar.ts #935): assertgetCustomTokens('testnet')returns[]when storage is empty; callsaveCustomToken('testnet', { address: 'CABC', symbol: 'TKN', decimals: 7 })thengetCustomTokens('testnet')and expect the token back; save the same token twice and assert the list length is 1 (no duplicates); write invalid JSON to the keyflowstar:custom-tokens:testnetvialocalStorage.setItemand assertgetCustomTokens('testnet')returns[]without throwing. Also verify network isolation (saving ontestnetdoes not appear onmainnet). For favorite tokens (issue Test favorite tokens in lib/stellar.ts #936): assertgetFavoriteTokens()returns[]initially andisFavoriteToken('CABC')is false; calltoggleFavoriteToken('CABC')and assertisFavoriteToken('CABC')is true andgetFavoriteTokens()includes'CABC'; calltoggleFavoriteToken('CABC')again and assertisFavoriteToken('CABC')is false andgetFavoriteTokens()no longer includes it; toggle two tokens and re-readgetFavoriteTokens()to confirm persistence across reads. Runnpm testto confirm all new tests pass. (tests/lib/stellar.test.ts)