test(axum): exercise interaction helper path
Move public axum response tests off direct HandlerRegistry construction so the checked test surface follows interactions()/on() just like canonical examples. req: axum_integration/003 req: ceremony/001 req: dx/003
This commit is contained in:
+13
-10
@@ -2,7 +2,7 @@ use axum::http::{header, HeaderMap};
|
|||||||
use axum::response::IntoResponse;
|
use axum::response::IntoResponse;
|
||||||
use scraper::{Html, Selector};
|
use scraper::{Html, Selector};
|
||||||
use slhx_axum::{
|
use slhx_axum::{
|
||||||
interactions, runtime_js, DispatchRejection, EffectResponse, HandlerRegistry, InteractionForm,
|
interactions, runtime_js, DispatchRejection, EffectResponse, InteractionForm,
|
||||||
InteractionFormRejection, InteractionRequest, PageMode, PageRequest, PageResponse,
|
InteractionFormRejection, InteractionRequest, PageMode, PageRequest, PageResponse,
|
||||||
SLHX_CONTENT_TYPE, SLHX_FINGERPRINT_HEADER, SLHX_PARTIAL_HEADER, SLHX_RUNTIME_CONTENT_TYPE,
|
SLHX_CONTENT_TYPE, SLHX_FINGERPRINT_HEADER, SLHX_PARTIAL_HEADER, SLHX_RUNTIME_CONTENT_TYPE,
|
||||||
SLHX_TITLE_HEADER,
|
SLHX_TITLE_HEADER,
|
||||||
@@ -169,16 +169,19 @@ fn interaction_request_dispatches_with_concise_handlers_helper() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn handler_registry_dispatches_by_checked_handle() {
|
fn interactions_dispatch_by_checked_handle() {
|
||||||
// req: ceremony/004 req: public_api/001
|
// req: ceremony/004 req: public_api/001
|
||||||
let title = Slot::<String>::new(7);
|
let title = Slot::<String>::new(7);
|
||||||
let create = Handle::<()>::new(42);
|
let create = Handle::<()>::new(42);
|
||||||
let registry = HandlerRegistry::new(BuildFingerprint(123)).register_handle(create, move |form| {
|
let request = InteractionRequest::from(InteractionForm::for_handle(
|
||||||
title.text(form.value("title").unwrap_or(""))
|
create,
|
||||||
});
|
[("title".into(), "Hello".into())],
|
||||||
|
));
|
||||||
|
|
||||||
let response = registry
|
let response = request
|
||||||
.dispatch(InteractionForm::for_handle(create, [("title".into(), "Hello".into())]))
|
.dispatch(interactions(BuildFingerprint(123)).on(create, move |form| {
|
||||||
|
title.text(form.value("title").unwrap_or(""))
|
||||||
|
}))
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
assert_eq!(response.batch.fingerprint, BuildFingerprint(123));
|
assert_eq!(response.batch.fingerprint, BuildFingerprint(123));
|
||||||
@@ -186,11 +189,11 @@ fn handler_registry_dispatches_by_checked_handle() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn handler_registry_rejects_unknown_handle_ids() {
|
fn interactions_reject_unknown_handle_ids() {
|
||||||
let registry = HandlerRegistry::new(BuildFingerprint(123));
|
let request = InteractionRequest::from(InteractionForm::new(9, []));
|
||||||
|
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
registry.dispatch(InteractionForm::new(9, [])).unwrap_err(),
|
request.dispatch(interactions(BuildFingerprint(123))).unwrap_err(),
|
||||||
DispatchRejection::UnknownHandle(9)
|
DispatchRejection::UnknownHandle(9)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user