Skip to content

test(api): unit tests for error mapping and Authorization header#562

Open
playmaker410 wants to merge 1 commit into
ritik4ever:mainfrom
Rich-Angel-Gold-Resources:feat/api-service-unit-tests
Open

test(api): unit tests for error mapping and Authorization header#562
playmaker410 wants to merge 1 commit into
ritik4ever:mainfrom
Rich-Angel-Gold-Resources:feat/api-service-unit-tests

Conversation

@playmaker410
Copy link
Copy Markdown

@playmaker410 playmaker410 commented Jun 1, 2026

Summary

Extends frontend/src/services/api.test.ts with explicit test coverage for error response mapping and request header construction, as specified in issue #259.

Changes

  • 400 validation error → asserts ApiError is thrown with statusCode: 400, correct message, and details payload
  • 404 not found → asserts ApiError with statusCode: 404 and message from response body
  • 500 internal server error → asserts generic ApiError with statusCode: 500; plain-text body is not leaked as structured details
  • Authorization header → asserts Authorization: Bearer <token> is sent on createStream when a token is set via setAuthToken

Also fixes the pre-existing payload shape bug in the auth test (amount/asset/durationtotalAmount/assetCode/durationSeconds) that would have caused a TypeScript compile error.

Test results

All 4 tests in src/services/api.test.ts pass. No other tests were affected.

Closes #259

Summary by CodeRabbit

Release Notes

This update includes internal test improvements only. No user-facing features, bug fixes, or changes are included in this release.

- Assert ApiError with statusCode + details on 400 validation error
- Assert ApiError with 404 status on not-found response
- Assert generic ApiError on 500 plain-text response
- Assert Authorization: Bearer header is sent when token is set

Closes ritik4ever#259
@vercel
Copy link
Copy Markdown

vercel Bot commented Jun 1, 2026

@playmaker410 is attempting to deploy a commit to the ritik4ever's projects Team on Vercel.

A member of the Team first needs to authorize it.

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Jun 1, 2026

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: b745062d-d2d2-490c-ab80-08bd8f9c682f

📥 Commits

Reviewing files that changed from the base of the PR and between eb79b4f and d502490.

📒 Files selected for processing (1)
  • frontend/src/services/api.test.ts

📝 Walkthrough

Walkthrough

The PR updates a single API service authentication test to align with the current request parameter shape, changing the createStream call to use full parameter names (sender, recipient, assetCode, totalAmount, durationSeconds) while verifying the Bearer token is included in the Authorization header.

Changes

API Service Test

Layer / File(s) Summary
createStream authentication test with updated parameters
frontend/src/services/api.test.ts
Test call parameters are updated to match the current API contract shape, passing explicit sender, full recipient, assetCode, totalAmount, and durationSeconds while confirming the Authorization: Bearer <token> header is sent.

Estimated code review effort

🎯 1 (Trivial) | ⏱️ ~2 minutes

Possibly related PRs

  • ritik4ever/stellar-stream#320: Both PRs modify frontend/src/services/api.test.ts to adjust authentication-related createStream test assertions, specifically verifying that the Authorization: Bearer <token> header is included in the fetch request with the updated request shape.

Poem

🐰 A test, so small, yet vital true,
Parameter shapes aligned anew,
Bearer tokens, headers bright,
Authentication flowing right! ✨

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately reflects the main changes: adding unit tests for error mapping (400, 404, 500 responses) and Authorization header validation in the api service.
Linked Issues check ✅ Passed The PR implements all acceptance criteria from issue #259: tests for 400/404/500 error mapping, Authorization header verification, and fixes the payload shape bug to meet test requirements.
Out of Scope Changes check ✅ Passed All changes are directly scoped to issue #259: updating the authentication test parameter names and adding error mapping test cases; no unrelated modifications.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add unit tests for api.ts service – request construction and error mapping

1 participant