| 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!( |
| 17 |
resp.status.is_client_error() || resp.status.is_redirection(), |
| 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.signup("appealok", "appealok@test.com", "password123").await; |
| 27 |
|
| 28 |
let resp = h |
| 29 |
.client |
| 30 |
.post_form("/api/users/me/appeal", "appeal_text=I+want+to+appeal") |
| 31 |
.await; |
| 32 |
assert!( |
| 33 |
resp.status.is_client_error(), |
| 34 |
"Non-suspended user appeal should be rejected: {} {}", |
| 35 |
resp.status, resp.text |
| 36 |
); |
| 37 |
} |
| 38 |
|
| 39 |
#[tokio::test] |
| 40 |
async fn appeal_empty_text_rejected() { |
| 41 |
let mut h = TestHarness::new().await; |
| 42 |
let user_id = h.signup("appealempty", "appealempty@test.com", "password123").await; |
| 43 |
h.suspend_user(user_id).await; |
| 44 |
|
| 45 |
h.client.post_form("/logout", "").await; |
| 46 |
h.login("appealempty", "password123").await; |
| 47 |
|
| 48 |
let resp = h |
| 49 |
.client |
| 50 |
.post_form("/api/users/me/appeal", "appeal_text=") |
| 51 |
.await; |
| 52 |
assert!( |
| 53 |
resp.status.is_client_error(), |
| 54 |
"Empty appeal text should be rejected: {} {}", |
| 55 |
resp.status, resp.text |
| 56 |
); |
| 57 |
} |
| 58 |
|
| 59 |
#[tokio::test] |
| 60 |
async fn appeal_too_long_rejected() { |
| 61 |
let mut h = TestHarness::new().await; |
| 62 |
let user_id = h.signup("appeallong", "appeallong@test.com", "password123").await; |
| 63 |
h.suspend_user(user_id).await; |
| 64 |
h.client.post_form("/logout", "").await; |
| 65 |
h.login("appeallong", "password123").await; |
| 66 |
|
| 67 |
let long_text = "a".repeat(2001); |
| 68 |
let resp = h |
| 69 |
.client |
| 70 |
.post_form( |
| 71 |
"/api/users/me/appeal", |
| 72 |
&format!("appeal_text={}", long_text), |
| 73 |
) |
| 74 |
.await; |
| 75 |
assert!( |
| 76 |
resp.status.is_client_error(), |
| 77 |
"Appeal text >2000 chars should be rejected: {} {}", |
| 78 |
resp.status, resp.text |
| 79 |
); |
| 80 |
} |
| 81 |
|
| 82 |
#[tokio::test] |
| 83 |
async fn appeal_suspended_user_succeeds() { |
| 84 |
let mut h = TestHarness::new().await; |
| 85 |
let _user_id = h.signup("appealgood", "appealgood@test.com", "password123").await; |
| 86 |
h.suspend_user(_user_id).await; |
| 87 |
h.client.post_form("/logout", "").await; |
| 88 |
h.login("appealgood", "password123").await; |
| 89 |
|
| 90 |
let resp = h |
| 91 |
.client |
| 92 |
.post_form( |
| 93 |
"/api/users/me/appeal", |
| 94 |
"appeal_text=I+believe+this+was+a+mistake", |
| 95 |
) |
| 96 |
.await; |
| 97 |
assert!( |
| 98 |
resp.status.is_success() || resp.status == 204, |
| 99 |
"Suspended user appeal should succeed: {} {}", |
| 100 |
resp.status, resp.text |
| 101 |
); |
| 102 |
} |
| 103 |
|