test(assets): filter GET /assets by asset_type, active, and combined - #124
Merged
valoryyaa-byte merged 1 commit intoJul 28, 2026
Merged
Conversation
…oth combined
Add three #[tokio::test]s covering the query-param filter logic on
the GET /assets list endpoint:
filter_by_asset_type_returns_matching_assets
Seeds 4 assets (2 real_estate, 1 bond, 1 commodity) and asserts
?asset_type=real_estate returns exactly the 2 matching assets.
filter_by_active_returns_only_active_assets
Seeds 4 assets (2 active, 2 inactive) across mixed types and
asserts ?active=true returns exactly the 2 active ones.
filter_by_asset_type_and_active_combined
Seeds 4 assets covering every true/false cross product of
(real_estate|bond|commodity) × (active|inactive) and asserts
?asset_type=real_estate&active=true returns exactly the one
asset satisfying both predicates.
Each test builds a minimal axum::Router via list_router(), sends the
request with tower::ServiceExt::oneshot, and decodes the JSON body
as Vec<Asset> via a shared get_assets() helper.
Supporting changes required to compile:
- Cargo.toml: add tower, metrics, metrics-exporter-prometheus
- indexer/mod.rs: import PrometheusHandle; add async
last_indexed_ledger() (used by cache_headers middleware); add
#[cfg(test)] AppState::for_test() and AppState::with_assets()
constructors
- main.rs: add missing use metrics_exporter_prometheus::PrometheusBuilder
- models/mod.rs: derive serde::Deserialize on Asset and ApiErrorBody
so tests can decode response bodies
Closes RWA-ToolKit#27
|
@marvs8 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.
Summary
Adds three
#[tokio::test]tests covering the query-parameter filter logic onGET /assets.Tests added (
api/src/routes/assets.rs)filter_by_asset_type_returns_matching_assets?asset_type=real_estatefilter_by_active_returns_only_active_assets?active=truefilter_by_asset_type_and_active_combined?asset_type=real_estate&active=trueEach test builds a minimal
axum::Routervia alist_router()helper, drives it withtower::ServiceExt::oneshot, and decodes the response body asVec<Asset>via a sharedget_assets()helper. Fixtures use astub_asset(id, type, active)factory that fills all required fields with inert dummy values so each test only varies the dimensions under test.Supporting changes
Cargo.tomltower,metrics,metrics-exporter-prometheusindexer/mod.rsPrometheusHandle; addasync last_indexed_ledger()(called by cache-headers middleware but previously undefined); add#[cfg(test)] AppState::for_test()andAppState::with_assets()main.rsuse metrics_exporter_prometheus::PrometheusBuildermodels/mod.rsserde::DeserializeonAssetandApiErrorBody(needed to decode response bodies in tests)Closes #27