use axum::extract::{Json, State}; use crate::{ empty::Empty, test::{fixtures, verify}, token::app, }; #[tokio::test] async fn successful() { // Set up the environment let app = fixtures::scratch_app().await; let now = fixtures::now(); let creds = fixtures::user::create_with_password(&app, &fixtures::now()).await; let identity = fixtures::cookie::logged_in(&app, &creds, &now).await; // Call the endpoint let (response_identity, Empty) = super::handler( State(app.tokens()), fixtures::now(), identity.clone(), Json::default(), ) .await .expect("logged out with a valid token"); // Verify the return value's basic structure assert!(response_identity.secret().is_none()); // Verify the semantics verify::identity::invalid(&app, &identity).await; } #[tokio::test] async fn no_identity() { // Set up the environment let app = fixtures::scratch_app().await; // Call the endpoint let identity = fixtures::cookie::not_logged_in(); let (identity, Empty) = super::handler( State(app.tokens()), fixtures::now(), identity, Json::default(), ) .await .expect("logged out with no token succeeds"); // Verify the return value's basic structure assert!(identity.secret().is_none()); } #[tokio::test] async fn invalid_token() { // Set up the environment let app = fixtures::scratch_app().await; // Call the endpoint let identity = fixtures::cookie::fictitious(); let super::Error(error) = super::handler( State(app.tokens()), fixtures::now(), identity, Json::default(), ) .await .expect_err("logged out with an invalid token fails"); // Verify the return value's basic structure assert!(matches!(error, app::ValidateError::InvalidToken)); }