| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
use crate::harness::TestHarness; |
| 7 |
|
| 8 |
#[tokio::test] |
| 9 |
async fn appeal_requires_auth() { |
| 10 |
let mut h = TestHarness::new().await; |
| 11 |
|
| 12 |
let resp = h |
| 13 |
.client |
| 14 |
.post_form("/api/users/me/appeal", "appeal_text=Please+unsuspend+me") |
| 15 |
.await; |
| 16 |
assert_eq!( |
| 17 |
resp.status, 403, |
| 18 |
"Unauthenticated appeal should be rejected: {} {}", |
| 19 |
resp.status, resp.text |
| 20 |
); |
| 21 |
} |
| 22 |
|
| 23 |
#[tokio::test] |
| 24 |
async fn appeal_non_suspended_user_rejected() { |
| 25 |
let mut h = TestHarness::new().await; |
| 26 |
let _user_id = h |
| 27 |
.signup("appealok", "appealok@test.com", "password123") |
| 28 |
.await; |
| 29 |
|
| 30 |
let resp = h |
| 31 |
.client |
| 32 |
.post_form("/api/users/me/appeal", "appeal_text=I+want+to+appeal") |
| 33 |
.await; |
| 34 |
assert_eq!( |
| 35 |
resp.status, 400, |
| 36 |
"Non-suspended user appeal should be rejected: {} {}", |
| 37 |
resp.status, resp.text |
| 38 |
); |
| 39 |
} |
| 40 |
|
| 41 |
#[tokio::test] |
| 42 |
async fn appeal_empty_text_rejected() { |
| 43 |
let mut h = TestHarness::new().await; |
| 44 |
let user_id = h |
| 45 |
.signup("appealempty", "appealempty@test.com", "password123") |
| 46 |
.await; |
| 47 |
h.suspend_user(user_id).await; |
| 48 |
|
| 49 |
h.client.post_form("/logout", "").await; |
| 50 |
h.login("appealempty", "password123").await; |
| 51 |
|
| 52 |
let resp = h |
| 53 |
.client |
| 54 |
.post_form("/api/users/me/appeal", "appeal_text=") |
| 55 |
.await; |
| 56 |
assert_eq!( |
| 57 |
resp.status, 422, |
| 58 |
"Empty appeal text should be rejected: {} {}", |
| 59 |
resp.status, resp.text |
| 60 |
); |
| 61 |
} |
| 62 |
|
| 63 |
#[tokio::test] |
| 64 |
async fn appeal_too_long_rejected() { |
| 65 |
let mut h = TestHarness::new().await; |
| 66 |
let user_id = h |
| 67 |
.signup("appeallong", "appeallong@test.com", "password123") |
| 68 |
.await; |
| 69 |
h.suspend_user(user_id).await; |
| 70 |
h.client.post_form("/logout", "").await; |
| 71 |
h.login("appeallong", "password123").await; |
| 72 |
|
| 73 |
let long_text = "a".repeat(2001); |
| 74 |
let resp = h |
| 75 |
.client |
| 76 |
.post_form("/api/users/me/appeal", &format!("appeal_text={long_text}")) |
| 77 |
.await; |
| 78 |
assert_eq!( |
| 79 |
resp.status, 422, |
| 80 |
"Appeal text >2000 chars should be rejected: {} {}", |
| 81 |
resp.status, resp.text |
| 82 |
); |
| 83 |
} |
| 84 |
|
| 85 |
#[tokio::test] |
| 86 |
async fn appeal_suspended_user_succeeds() { |
| 87 |
let mut h = TestHarness::new().await; |
| 88 |
let user_id = h |
| 89 |
.signup("appealgood", "appealgood@test.com", "password123") |
| 90 |
.await; |
| 91 |
h.suspend_user(user_id).await; |
| 92 |
h.client.post_form("/logout", "").await; |
| 93 |
h.login("appealgood", "password123").await; |
| 94 |
|
| 95 |
let resp = h |
| 96 |
.client |
| 97 |
.post_form( |
| 98 |
"/api/users/me/appeal", |
| 99 |
"appeal_text=I+believe+this+was+a+mistake", |
| 100 |
) |
| 101 |
.await; |
| 102 |
assert_eq!( |
| 103 |
resp.status, 204, |
| 104 |
"Suspended user appeal should succeed: {} {}", |
| 105 |
resp.status, resp.text |
| 106 |
); |
| 107 |
} |
| 108 |
|