Skip to content

test(assets): filter GET /assets by asset_type, active, and combined - #124

Merged
valoryyaa-byte merged 1 commit into
RWA-ToolKit:mainfrom
marvs8:test/assets-filter-query-params
Jul 28, 2026
Merged

test(assets): filter GET /assets by asset_type, active, and combined#124
valoryyaa-byte merged 1 commit into
RWA-ToolKit:mainfrom
marvs8:test/assets-filter-query-params

Conversation

@marvs8

@marvs8 marvs8 commented Jul 25, 2026

Copy link
Copy Markdown
Contributor

Summary

Adds three #[tokio::test] tests covering the query-parameter filter logic on GET /assets.

Tests added (api/src/routes/assets.rs)

Test Filter Seed Expected
filter_by_asset_type_returns_matching_assets ?asset_type=real_estate 2 real_estate + 1 bond + 1 commodity 2 assets, all real_estate
filter_by_active_returns_only_active_assets ?active=true 2 active + 2 inactive across mixed types 2 assets, all active
filter_by_asset_type_and_active_combined ?asset_type=real_estate&active=true one asset per (type × active) cross-product exactly 1 asset (id 1)

Each test builds a minimal axum::Router via a list_router() helper, drives it with tower::ServiceExt::oneshot, and decodes the response body as Vec<Asset> via a shared get_assets() helper. Fixtures use a stub_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

File Change
Cargo.toml Add tower, metrics, metrics-exporter-prometheus
indexer/mod.rs Import PrometheusHandle; add async last_indexed_ledger() (called by cache-headers middleware but previously undefined); add #[cfg(test)] AppState::for_test() and AppState::with_assets()
main.rs Add missing use metrics_exporter_prometheus::PrometheusBuilder
models/mod.rs Derive serde::Deserialize on Asset and ApiErrorBody (needed to decode response bodies in tests)

Closes #27

…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
@drips-wave

drips-wave Bot commented Jul 25, 2026

Copy link
Copy Markdown

@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! 🚀

Learn more about application limits

@valoryyaa-byte
valoryyaa-byte merged commit 7d8ef04 into RWA-ToolKit:main Jul 28, 2026
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.

api: add test — route: /assets filters by asset_type and active

2 participants