Skip to content

test: add unit tests for frontend api client wrapper#551

Open
Kishalll wants to merge 3 commits into
param20h:devfrom
Kishalll:test/450-api-client-tests
Open

test: add unit tests for frontend api client wrapper#551
Kishalll wants to merge 3 commits into
param20h:devfrom
Kishalll:test/450-api-client-tests

Conversation

@Kishalll

Copy link
Copy Markdown
Contributor

🔗 Related Issue

Closes #450

📝 What does this PR do?

Adds comprehensive unit tests for the frontend API client (frontend/src/lib/api.ts).

Specifically, this PR introduces frontend/src/lib/__tests__/api.test.ts which successfully mocks
global.fetch and localStorage to thoroughly verify:
- Proper formatting and injection of Authorization Bearer tokens.
- Parameter and body serialization for both JSON requests and FormData payloads (without manually
overriding the Content-Type boundary).
- Error handlers correctly identifying and throwing connection errors and custom server errors.
- Automatic token refresh logic properly catching 401s and retrying the failed request with newly
provisioned tokens.

🗂️ Type of Change

  • 🐛 Bug fix

  • ✨ New feature

  • 🔧 Refactor / code cleanup

  • 📝 Documentation update

  • 🎨 UI / styling change

  • ⚙️ CI / tooling / config change

  • 🧪 Tests


    🧪 How was this tested?

    • Ran the backend locally (uvicorn app.main:app --reload)
    • Ran the frontend locally (npm run dev inside frontend/)
    • Tested the affected API endpoints manually
    • Added / updated tests

    📸 Screenshots (if UI change)

    N/A


    ⚠️ Anything to flag for reviewers?

    No major flags! I leveraged the jsdom Vitest environment previously introduced in dev to properly
    simulate browser objects like localStorage and FormData in the testing framework.


    ✅ Self-Review Checklist

    • My branch is based on dev, not main
    • I have not added any secrets / API keys
    • I have not modified main branch or any HuggingFace deployment config
    • My code follows the existing style (no unnecessary formatting changes)
    • I have updated relevant docs / comments if needed

@Kishalll Kishalll requested a review from param20h as a code owner June 10, 2026 07:14
@Kishalll

Copy link
Copy Markdown
Contributor Author

@param20h resolved conflicts pls review

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.

test(frontend): Add unit tests for API client helper functions

1 participant