summaryrefslogtreecommitdiff
path: root/src/setup/routes/test.rs
diff options
context:
space:
mode:
authorOwen Jacobson <owen@grimoire.ca>2025-06-17 02:11:45 -0400
committerOwen Jacobson <owen@grimoire.ca>2025-06-18 18:31:40 -0400
commit4e3d5ccac99b24934c972e088cd7eb02bb95df06 (patch)
treec94f5a42f7e734b81892c1289a1d2b566706ba7c /src/setup/routes/test.rs
parent5ed96f8e8b9d9f19ee249f5c73a5a21ef6bca09f (diff)
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.
Diffstat (limited to 'src/setup/routes/test.rs')
-rw-r--r--src/setup/routes/test.rs94
1 files changed, 0 insertions, 94 deletions
diff --git a/src/setup/routes/test.rs b/src/setup/routes/test.rs
deleted file mode 100644
index e9f5cd6..0000000
--- a/src/setup/routes/test.rs
+++ /dev/null
@@ -1,94 +0,0 @@
-use axum::extract::{Json, State};
-
-use super::post;
-use crate::{setup::app, test::fixtures};
-
-#[tokio::test]
-async fn fresh_instance() {
- // Set up the environment
-
- let app = fixtures::scratch_app().await;
-
- // Call the endpoint
- let identity = fixtures::cookie::not_logged_in();
- let (name, password) = fixtures::user::propose();
- let request = post::Request {
- name: name.clone(),
- password: password.clone(),
- };
- let (identity, Json(response)) =
- post::handler(State(app.clone()), fixtures::now(), identity, Json(request))
- .await
- .expect("setup in a fresh app succeeds");
-
- // Verify the response
-
- assert_eq!(name, response.name);
-
- // Verify that the issued token is valid
-
- let secret = identity
- .secret()
- .expect("newly-issued identity has a token secret");
- let (_, login) = app
- .tokens()
- .validate(&secret, &fixtures::now())
- .await
- .expect("newly-issued identity cookie is valid");
- assert_eq!(response, login);
-
- // Verify that the given credentials can log in
-
- let (login, _) = app
- .tokens()
- .login(&name, &password, &fixtures::now())
- .await
- .expect("credentials given on signup are valid");
- assert_eq!(response, login);
-}
-
-#[tokio::test]
-async fn login_exists() {
- // Set up the environment
-
- let app = fixtures::scratch_app().await;
- fixtures::user::create(&app, &fixtures::now()).await;
-
- // Call the endpoint
- let identity = fixtures::cookie::not_logged_in();
- let (name, password) = fixtures::user::propose();
- let request = post::Request { name, password };
- let post::Error(error) =
- post::handler(State(app.clone()), fixtures::now(), identity, Json(request))
- .await
- .expect_err("setup in a populated app fails");
-
- // Verify the response
-
- assert!(matches!(error, app::Error::SetupCompleted));
-}
-
-#[tokio::test]
-async fn invalid_name() {
- // Set up the environment
-
- let app = fixtures::scratch_app().await;
-
- // Call the endpoint
-
- let name = fixtures::user::propose_invalid_name();
- let password = fixtures::user::propose_password();
- let identity = fixtures::cookie::not_logged_in();
- let request = post::Request {
- name: name.clone(),
- password: password.clone(),
- };
- let post::Error(error) =
- post::handler(State(app.clone()), fixtures::now(), identity, Json(request))
- .await
- .expect_err("setup with an invalid name fails");
-
- // Verify the response
-
- assert!(matches!(error, app::Error::InvalidName(error_name) if name == error_name));
-}