use axum::extract::{Json, Path, State}; use crate::test::fixtures; #[tokio::test] async fn valid_invite() { // Set up the environment let app = fixtures::scratch_app().await; let issuer = fixtures::user::create(&app, &fixtures::now()).await; let invite = fixtures::invite::issue(&app, &issuer, &fixtures::now()).await; // Call endpoint let Json(response) = super::handler(State(app.invites()), Path(invite.id)) .await .expect("get for an existing invite succeeds"); // Verify response assert_eq!(issuer.name.display(), &response.issuer); assert_eq!(invite.issued_at, response.issued_at); } #[tokio::test] async fn nonexistent_invite() { // Set up the environment let app = fixtures::scratch_app().await; // Call endpoint let invite = fixtures::invite::fictitious(); let error = super::handler(State(app.invites()), Path(invite.clone())) .await .expect_err("get for a nonexistent invite fails"); // Verify response assert!(matches!(error, super::Error::NotFound(error_id) if invite == error_id)); } #[tokio::test] async fn expired_invite() { // Set up the environment let app = fixtures::scratch_app().await; let issuer = fixtures::user::create(&app, &fixtures::ancient()).await; let invite = fixtures::invite::issue(&app, &issuer, &fixtures::ancient()).await; app.invites() .expire(&fixtures::now()) .await .expect("expiring invites never fails"); // Call endpoint let error = super::handler(State(app.invites()), Path(invite.id.clone())) .await .expect_err("get for an expired invite fails"); // Verify response assert!(matches!(error, super::Error::NotFound(error_id) if invite.id == error_id)); }