Closes #182#306
Open
p3ris0n wants to merge 2 commits into
Open
Conversation
|
@p3ris0n 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! 🚀 |
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 #182
Description
This PR implements a robust, production-ready API Test Client within backend/src/test_utils/client.rs. Designed specifically for our Axum, SQLx (PostgreSQL), and Redis stack, this test client simplifies integration testing by mocking HTTP requests, handling session/auth states, and ensuring clean database transactions across test suites.
Changes Made
Core Test Client (backend/src/test_utils/client.rs):
Implemented an isolated TestClient struct that wraps our Axum router using tower::ServiceExt.
Added helper methods for common HTTP verbs (get, post, put, delete).
Integrated automatic header injection (e.g., Bearer tokens for authenticated routes).
State & Dependency Mocking:
Added setups for isolated PostgreSQL transactions that roll back automatically after each test run using SQLx.
Integrated a localized Redis pool/mock client connection handling to prevent test state pollution.
Observability:
Configured tracing-subscriber initialization within the test environment for easier debugging during test failures.
Documentation:
Updated backend/README.md with clear examples of how to spin up and use the new TestClient in integration tests.
Testing Strategy
Integration Tests: Added full-suite validation ensuring the TestClient correctly hits Axum endpoints, processes data via SQLx, and interacts with Redis without leaks.
Run the suite using:
Bash
cd backend
cargo test --lib test_utils::client
Checklist
[x] Feature is fully implemented and verified locally.
[x] Code compiles cleanly without any clippy or compiler warnings.
[x] All unit and integration tests pass successfully.
[x] Documentation added/updated in backend/README.md and inline via Rustdoc.
[x] No breaking changes introduced to existing APIs.
Example Usage (Added to README)
Rust
#[tokio::test]
async fn test_example_endpoint() {
// Initialize test database, redis, and app state
let client = TestClient::new().await;
}