Repository navigation
test(web): cover request() ApiError and empty-body handling (#678) - #1258
Merged
vjuliaife merged 2 commits intoOct 18, 2026
Merged
Conversation
…vjuliaife#678) Mock fetch through api.login (request() is private): a 422 with {error, details} yields ApiError(422, 'validation failed', details); an empty-body 500 and an error body without an error field fall back to 'HTTP <status>'.
|
Deployment failed for project tariff-shield-web with the following error: Learn More: https://vercel.com/docs/concepts/projects/project-configuration |
|
@oluwarantimini 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! 🚀 |
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
This branch had an error being deployed
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 #678
Closes #665
Closes #677
Closes #672
Adds unit tests for
apps/web/lib/api.ts'srequest(): how it parses response bodies and how it throwsApiErroron non-2xx responses.Changes
apps/web/lib/api-request.test.ts(new)request()isn't exported, so the tests go through the publicapi.login, which callsrequest()withauth: false(no token or localStorage needed). They mockglobalThis.fetch, the same pattern asimporter-prefetch.test.ts, and restore it after each test.422{ error: 'validation failed', details: { field: 'amount' } }ApiError(also anError) withstatus 422,message 'validation failed',details { field: 'amount' }500, no bodymessagefalls back to'HTTP 500',detailsundefined, noJSON.parsecrasherror(extra edge case)503{ details: { retryAfter: 30 } }message 'HTTP 503',detailspreserved200with JSON204, no bodynull, noJSON.parsecrashAcceptance criteria
{error, details}→ApiErrorwith status 422, message'validation failed', matching details'HTTP 500'null, not aJSON.parsecrashTesting
Tests only; no production code changes.