test(frontend): add spec for BlobErrorHttpInterceptor#5461
Open
mengw15 wants to merge 7 commits into
Open
Conversation
Cover every branch of intercept(): pass-through on success; re-throw unchanged for a non-HttpErrorResponse error, a non-Blob error, and a non-json Blob; parse an application/json Blob error into a structured HttpErrorResponse with the original status/statusText/url preserved; and fall back to the original error on malformed JSON or a FileReader failure. The interceptor is driven directly with a stub HttpHandler rather than through HttpClient, because the non-HttpErrorResponse and FileReader- failure branches cannot be produced through HttpClient. Closes apache#5455.
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #5461 +/- ##
============================================
- Coverage 54.11% 53.94% -0.18%
+ Complexity 2819 2787 -32
============================================
Files 1103 1101 -2
Lines 42650 42590 -60
Branches 4588 4587 -1
============================================
- Hits 23079 22974 -105
- Misses 18226 18279 +53
+ Partials 1345 1337 -8
*This pull request uses carry forward flags. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
Contributor
There was a problem hiding this comment.
Pull request overview
Adds a Vitest unit spec for the Angular BlobErrorHttpInterceptor to validate how it handles responseType: "blob" error responses (especially JSON-in-Blob parsing and fallback behavior).
Changes:
- Introduces
blob-error-http-interceptor.service.spec.tscovering success passthrough and multiple error rethrow/parse branches. - Uses a stub
HttpHandlerand directintercept()invocation to reach branches not realistically producible viaHttpClient(non-HttpErrorResponse,FileReaderfailure).
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com> Signed-off-by: Meng Wang <mengw15@uci.edu>
The existing JSON-Blob test used a non-null url, leaving the `err.url !== null ? err.url : undefined` false branch uncovered. Add a case where the original HttpErrorResponse has no url so the resulting error's url is null.
…erceptor spec Address review feedback: rename the two structured-error tests to match what they assert, verify the interceptor returns a *new* HttpErrorResponse (not the original), and assert the original headers are preserved on the parsed error.
Contributor
Automated Reviewer SuggestionsBased on the
|
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.
What changes were proposed in this PR?
Adds a unit spec for
BlobErrorHttpInterceptor, which previously had none. Covers every branch ofintercept():HttpErrorResponseerror, anHttpErrorResponsewhoseerroris not aBlob, and aBloberror whose type is notapplication/jsonapplication/jsonBloberror → parsed into a structuredHttpErrorResponsewith the originalstatus/statusText/urlpreservedFileReaderfailure → falls back to the original errorThe interceptor is driven directly with a stub
HttpHandlerrather than throughHttpClient/HTTP_INTERCEPTORS. Two branches — a non-HttpErrorResponseerror and aFileReaderfailure — cannot be produced throughHttpClient(it always wraps errors asHttpErrorResponse, and a readableBlobnever triggersFileReader.onerror), so direct invocation is the only way to cover them. Followsfrontend/TESTING.md(Vitest).Any related issues, documentation, discussions?
Closes #5455.
How was this PR tested?
yarn test --include='**/blob-error-http-interceptor.service.spec.ts'→ 7 passed.prettier --checkclean.Was this PR authored or co-authored using generative AI tooling?
Generated-by: Claude Code (claude-opus-4-7)