use crate::TestServer; use crate::ADMIN; #[tokio::test] async fn add() -> anyhow::Result<()> { let mut server = TestServer::new().await?; let user = &server.next_user_name(); server.api.user_login(ADMIN, ADMIN).await?; let status = server.api.admin_user_add(user, user).await?; assert_eq!(status, 201); Ok(()) } #[tokio::test] async fn add_existing() -> anyhow::Result<()> { let mut server = TestServer::new().await?; let user = &server.next_user_name(); server.api.user_login(ADMIN, ADMIN).await?; server.api.admin_user_add(user, user).await?; let status = server .api .admin_user_add(user, user) .await .unwrap_err() .status; assert_eq!(status, 463); Ok(()) } #[tokio::test] async fn name_too_short() -> anyhow::Result<()> { let mut server = TestServer::new().await?; server.api.user_login(ADMIN, ADMIN).await?; let status = server .api .admin_user_add("a", "password123") .await .unwrap_err() .status; assert_eq!(status, 462); Ok(()) } #[tokio::test] async fn password_too_short() -> anyhow::Result<()> { let mut server = TestServer::new().await?; server.api.user_login(ADMIN, ADMIN).await?; let status = server .api .admin_user_add("user123", "pswd") .await .unwrap_err() .status; assert_eq!(status, 461); Ok(()) } #[tokio::test] async fn non_admin() -> anyhow::Result<()> { let mut server = TestServer::new().await?; let user = &server.next_user_name(); server.api.user_login(ADMIN, ADMIN).await?; server.api.admin_user_add(user, user).await?; server.api.user_login(user, user).await?; let status = server .api .admin_user_add(user, user) .await .unwrap_err() .status; assert_eq!(status, 401); Ok(()) } #[tokio::test] async fn no_token() -> anyhow::Result<()> { let server = TestServer::new().await?; let status = server .api .admin_user_add("user", "password123") .await .unwrap_err() .status; assert_eq!(status, 401); Ok(()) }