From 4e3d5ccac99b24934c972e088cd7eb02bb95df06 Mon Sep 17 00:00:00 2001 From: Owen Jacobson Date: Tue, 17 Jun 2025 02:11:45 -0400 Subject: Handlers are _named operations_, which can be exposed via routes. Each domain module that exposes handlers does so through a `handlers` child module, ideally as a top-level symbol that can be plugged directly into Axum's `MethodRouter`. Modules could make exceptions to this - kill the doctrinaire inside yourself, after all - but none of the API modules that actually exist need such exceptions, and consistency is useful. The related details of request types, URL types, response types, errors, &c &c are then organized into modules under `handlers`, along with their respective tests. --- src/boot/routes/test.rs | 134 ------------------------------------------------ 1 file changed, 134 deletions(-) delete mode 100644 src/boot/routes/test.rs (limited to 'src/boot/routes/test.rs') diff --git a/src/boot/routes/test.rs b/src/boot/routes/test.rs deleted file mode 100644 index 55802fe..0000000 --- a/src/boot/routes/test.rs +++ /dev/null @@ -1,134 +0,0 @@ -use axum::extract::State; - -use super::get; -use crate::test::fixtures; - -#[tokio::test] -async fn returns_identity() { - let app = fixtures::scratch_app().await; - - let viewer = fixtures::identity::fictitious(); - let response = get::handler(State(app), viewer.clone()) - .await - .expect("boot always succeeds"); - - assert_eq!(viewer.user, response.user); -} - -#[tokio::test] -async fn includes_logins() { - let app = fixtures::scratch_app().await; - let spectator = fixtures::user::create(&app, &fixtures::now()).await; - - let viewer = fixtures::identity::fictitious(); - let response = get::handler(State(app), viewer) - .await - .expect("boot always succeeds"); - - assert!(response.snapshot.users.contains(&spectator)); -} - -#[tokio::test] -async fn includes_channels() { - let app = fixtures::scratch_app().await; - let channel = fixtures::channel::create(&app, &fixtures::now()).await; - - let viewer = fixtures::identity::fictitious(); - let response = get::handler(State(app), viewer) - .await - .expect("boot always succeeds"); - - assert!(response.snapshot.channels.contains(&channel)); -} - -#[tokio::test] -async fn includes_messages() { - let app = fixtures::scratch_app().await; - let sender = fixtures::user::create(&app, &fixtures::now()).await; - let channel = fixtures::channel::create(&app, &fixtures::now()).await; - let message = fixtures::message::send(&app, &channel, &sender, &fixtures::now()).await; - - let viewer = fixtures::identity::fictitious(); - let response = get::handler(State(app), viewer) - .await - .expect("boot always succeeds"); - - assert!(response.snapshot.messages.contains(&message)); -} - -#[tokio::test] -async fn excludes_expired_messages() { - let app = fixtures::scratch_app().await; - let sender = fixtures::user::create(&app, &fixtures::ancient()).await; - let channel = fixtures::channel::create(&app, &fixtures::ancient()).await; - let expired_message = - fixtures::message::send(&app, &channel, &sender, &fixtures::ancient()).await; - - app.messages() - .expire(&fixtures::now()) - .await - .expect("expiry never fails"); - - let viewer = fixtures::identity::fictitious(); - let response = get::handler(State(app), viewer) - .await - .expect("boot always succeeds"); - - assert!(!response.snapshot.messages.contains(&expired_message)); -} - -#[tokio::test] -async fn excludes_deleted_messages() { - let app = fixtures::scratch_app().await; - let sender = fixtures::user::create(&app, &fixtures::now()).await; - let channel = fixtures::channel::create(&app, &fixtures::now()).await; - let deleted_message = fixtures::message::send(&app, &channel, &sender, &fixtures::now()).await; - - app.messages() - .delete(&sender, &deleted_message.id, &fixtures::now()) - .await - .expect("deleting valid message succeeds"); - - let viewer = fixtures::identity::fictitious(); - let response = get::handler(State(app), viewer) - .await - .expect("boot always succeeds"); - - assert!(!response.snapshot.messages.contains(&deleted_message)); -} - -#[tokio::test] -async fn excludes_expired_channels() { - let app = fixtures::scratch_app().await; - let expired_channel = fixtures::channel::create(&app, &fixtures::ancient()).await; - - app.channels() - .expire(&fixtures::now()) - .await - .expect("expiry never fails"); - - let viewer = fixtures::identity::fictitious(); - let response = get::handler(State(app), viewer) - .await - .expect("boot always succeeds"); - - assert!(!response.snapshot.channels.contains(&expired_channel)); -} - -#[tokio::test] -async fn excludes_deleted_channels() { - let app = fixtures::scratch_app().await; - let deleted_channel = fixtures::channel::create(&app, &fixtures::now()).await; - - app.channels() - .delete(&deleted_channel.id, &fixtures::now()) - .await - .expect("deleting a valid channel succeeds"); - - let viewer = fixtures::identity::fictitious(); - let response = get::handler(State(app), viewer) - .await - .expect("boot always succeeds"); - - assert!(!response.snapshot.channels.contains(&deleted_channel)); -} -- cgit v1.2.3