Docs / ArchitectureKit / Rust / Guides / Testing Queries

Testing Queries

A query needs no test helpers of its own, since a test can call the function that answers it directly.

To test a query, call the function that answers it directly, with a view filled by a projection, for example with project (see Testing Projections). The view in memory never fails while it is read, so the result is always Ok:

let query = ListBooks { only_available: true, limit: None };
let Ok(books) = list_books(&catalog, query).await;

To test the handlers of queries without a database, build the router with a store whose database is never asked. Creating a client and a store connects to nothing, so a router with such a store answers queries from its views, while a command, which needs the database, fails with 503 Service Unavailable if none answers at the address:

use architecturekit::{Store, eventsourcingdb::Client};

let client = Client::new("http://localhost:3000".parse()?, "secret");
let store = Store::builder(client, "https://library.eventsourcingdb.io").build();