use crate::harness::TestHarness; #[tokio::test] async fn upload_requires_login() { let mut h = TestHarness::new().await; // Don't log in — just establish session h.client.get("/").await; let resp = h.client.post_multipart("/p/test/upload", b"fake", "image/png", "test.png").await; // Should be 401 (unauthorized) — not 200 assert_eq!(resp.status.as_u16(), 401, "Upload without login should return 401"); } #[tokio::test] async fn upload_returns_503_without_s3() { let mut h = TestHarness::new().await; let user_id = h.login_as("uploader").await; let comm_id = h.create_community("UploadComm", "upload-comm").await; h.add_membership(user_id, comm_id, "member").await; let resp = h.client.post_multipart("/p/upload-comm/upload", b"fake png data", "image/png", "test.png").await; assert_eq!(resp.status.as_u16(), 503, "Should return 503 when S3 is not configured"); } #[tokio::test] async fn serve_image_nonexistent_returns_404() { let mut h = TestHarness::new().await; let fake_id = uuid::Uuid::new_v4(); let resp = h.client.get(&format!("/uploads/{fake_id}")).await; assert_eq!(resp.status.as_u16(), 404, "Nonexistent image should return 404"); } #[tokio::test] async fn serve_image_invalid_uuid_returns_404() { let mut h = TestHarness::new().await; let resp = h.client.get("/uploads/not-a-uuid").await; assert_eq!(resp.status.as_u16(), 404, "Invalid UUID should return 404"); }