| 15 |
15 |
|
#[sqlx::test]
|
| 16 |
16 |
|
async fn admin_can_see_dashboard(_pool: sqlx::PgPool) {
|
| 17 |
17 |
|
let admin_id = Uuid::new_v4();
|
| 18 |
|
- |
let mut h = TestHarness::new_with_admin(admin_id).await;
|
| 19 |
|
- |
let _admin = h.login_as("admin").await;
|
| 20 |
|
- |
|
| 21 |
|
- |
// Re-login with the correct admin_id since login_as generates a random UUID
|
| 22 |
|
- |
sqlx::query("UPDATE users SET mnw_account_id = $1 WHERE username = 'admin'")
|
| 23 |
|
- |
.bind(admin_id)
|
| 24 |
|
- |
.execute(&h.db)
|
| 25 |
|
- |
.await
|
| 26 |
|
- |
.unwrap();
|
| 27 |
|
- |
|
| 28 |
|
- |
h.client.get("/").await;
|
| 29 |
|
- |
let body = serde_json::json!({
|
| 30 |
|
- |
"user_id": admin_id.to_string(),
|
| 31 |
|
- |
"username": "admin",
|
| 32 |
|
- |
});
|
| 33 |
|
- |
h.client.post_json("/_test/login", &body.to_string()).await;
|
|
18 |
+ |
let mut h = TestHarness::new_with_admin_session(admin_id).await;
|
| 34 |
19 |
|
|
| 35 |
20 |
|
let resp = h.client.get("/_admin").await;
|
| 36 |
21 |
|
assert_eq!(resp.status, axum::http::StatusCode::OK);
|
| 40 |
25 |
|
#[sqlx::test]
|
| 41 |
26 |
|
async fn admin_can_suspend_community(_pool: sqlx::PgPool) {
|
| 42 |
27 |
|
let admin_id = Uuid::new_v4();
|
| 43 |
|
- |
let mut h = TestHarness::new_with_admin(admin_id).await;
|
| 44 |
|
- |
|
| 45 |
|
- |
sqlx::query(
|
| 46 |
|
- |
"INSERT INTO users (mnw_account_id, username, display_name)
|
| 47 |
|
- |
VALUES ($1, 'admin', 'Admin') ON CONFLICT DO NOTHING",
|
| 48 |
|
- |
)
|
| 49 |
|
- |
.bind(admin_id)
|
| 50 |
|
- |
.execute(&h.db)
|
| 51 |
|
- |
.await
|
| 52 |
|
- |
.unwrap();
|
| 53 |
|
- |
h.client.get("/").await;
|
| 54 |
|
- |
let body = serde_json::json!({ "user_id": admin_id.to_string(), "username": "admin" });
|
| 55 |
|
- |
h.client.post_json("/_test/login", &body.to_string()).await;
|
|
28 |
+ |
let mut h = TestHarness::new_with_admin_session(admin_id).await;
|
| 56 |
29 |
|
|
| 57 |
30 |
|
let community_id = h.create_community("Test Community", "test").await;
|
| 58 |
31 |
|
|
| 77 |
50 |
|
#[sqlx::test]
|
| 78 |
51 |
|
async fn admin_can_unsuspend_community(_pool: sqlx::PgPool) {
|
| 79 |
52 |
|
let admin_id = Uuid::new_v4();
|
| 80 |
|
- |
let mut h = TestHarness::new_with_admin(admin_id).await;
|
| 81 |
|
- |
|
| 82 |
|
- |
sqlx::query(
|
| 83 |
|
- |
"INSERT INTO users (mnw_account_id, username, display_name)
|
| 84 |
|
- |
VALUES ($1, 'admin', 'Admin') ON CONFLICT DO NOTHING",
|
| 85 |
|
- |
)
|
| 86 |
|
- |
.bind(admin_id)
|
| 87 |
|
- |
.execute(&h.db)
|
| 88 |
|
- |
.await
|
| 89 |
|
- |
.unwrap();
|
| 90 |
|
- |
h.client.get("/").await;
|
| 91 |
|
- |
let body = serde_json::json!({ "user_id": admin_id.to_string(), "username": "admin" });
|
| 92 |
|
- |
h.client.post_json("/_test/login", &body.to_string()).await;
|
|
53 |
+ |
let mut h = TestHarness::new_with_admin_session(admin_id).await;
|
| 93 |
54 |
|
|
| 94 |
55 |
|
let community_id = h.create_community("Test", "test").await;
|
| 95 |
56 |
|
|
| 119 |
80 |
|
#[sqlx::test]
|
| 120 |
81 |
|
async fn admin_can_suspend_user(_pool: sqlx::PgPool) {
|
| 121 |
82 |
|
let admin_id = Uuid::new_v4();
|
| 122 |
|
- |
let mut h = TestHarness::new_with_admin(admin_id).await;
|
| 123 |
|
- |
|
| 124 |
|
- |
sqlx::query(
|
| 125 |
|
- |
"INSERT INTO users (mnw_account_id, username, display_name)
|
| 126 |
|
- |
VALUES ($1, 'admin', 'Admin') ON CONFLICT DO NOTHING",
|
| 127 |
|
- |
)
|
| 128 |
|
- |
.bind(admin_id)
|
| 129 |
|
- |
.execute(&h.db)
|
| 130 |
|
- |
.await
|
| 131 |
|
- |
.unwrap();
|
| 132 |
|
- |
h.client.get("/").await;
|
| 133 |
|
- |
let body = serde_json::json!({ "user_id": admin_id.to_string(), "username": "admin" });
|
| 134 |
|
- |
h.client.post_json("/_test/login", &body.to_string()).await;
|
|
83 |
+ |
let mut h = TestHarness::new_with_admin_session(admin_id).await;
|
| 135 |
84 |
|
|
| 136 |
85 |
|
let target_id = Uuid::new_v4();
|
| 137 |
86 |
|
sqlx::query(
|
| 163 |
112 |
|
#[sqlx::test]
|
| 164 |
113 |
|
async fn admin_can_unsuspend_user(_pool: sqlx::PgPool) {
|
| 165 |
114 |
|
let admin_id = Uuid::new_v4();
|
| 166 |
|
- |
let mut h = TestHarness::new_with_admin(admin_id).await;
|
| 167 |
|
- |
|
| 168 |
|
- |
sqlx::query(
|
| 169 |
|
- |
"INSERT INTO users (mnw_account_id, username, display_name)
|
| 170 |
|
- |
VALUES ($1, 'admin', 'Admin') ON CONFLICT DO NOTHING",
|
| 171 |
|
- |
)
|
| 172 |
|
- |
.bind(admin_id)
|
| 173 |
|
- |
.execute(&h.db)
|
| 174 |
|
- |
.await
|
| 175 |
|
- |
.unwrap();
|
| 176 |
|
- |
h.client.get("/").await;
|
| 177 |
|
- |
let body = serde_json::json!({ "user_id": admin_id.to_string(), "username": "admin" });
|
| 178 |
|
- |
h.client.post_json("/_test/login", &body.to_string()).await;
|
|
115 |
+ |
let mut h = TestHarness::new_with_admin_session(admin_id).await;
|
| 179 |
116 |
|
|
| 180 |
117 |
|
let target_id = Uuid::new_v4();
|
| 181 |
118 |
|
sqlx::query(
|
| 205 |
142 |
|
#[sqlx::test]
|
| 206 |
143 |
|
async fn admin_search_finds_users(_pool: sqlx::PgPool) {
|
| 207 |
144 |
|
let admin_id = Uuid::new_v4();
|
| 208 |
|
- |
let mut h = TestHarness::new_with_admin(admin_id).await;
|
| 209 |
|
- |
|
| 210 |
|
- |
sqlx::query(
|
| 211 |
|
- |
"INSERT INTO users (mnw_account_id, username, display_name)
|
| 212 |
|
- |
VALUES ($1, 'admin', 'Admin') ON CONFLICT DO NOTHING",
|
| 213 |
|
- |
)
|
| 214 |
|
- |
.bind(admin_id)
|
| 215 |
|
- |
.execute(&h.db)
|
| 216 |
|
- |
.await
|
| 217 |
|
- |
.unwrap();
|
| 218 |
|
- |
h.client.get("/").await;
|
| 219 |
|
- |
let body = serde_json::json!({ "user_id": admin_id.to_string(), "username": "admin" });
|
| 220 |
|
- |
h.client.post_json("/_test/login", &body.to_string()).await;
|
|
145 |
+ |
let mut h = TestHarness::new_with_admin_session(admin_id).await;
|
| 221 |
146 |
|
|
| 222 |
147 |
|
let target_id = Uuid::new_v4();
|
| 223 |
148 |
|
sqlx::query(
|
| 240 |
165 |
|
#[sqlx::test]
|
| 241 |
166 |
|
async fn admin_invalid_uuid_returns_404(_pool: sqlx::PgPool) {
|
| 242 |
167 |
|
let admin_id = Uuid::new_v4();
|
| 243 |
|
- |
let mut h = TestHarness::new_with_admin(admin_id).await;
|
| 244 |
|
- |
|
| 245 |
|
- |
sqlx::query(
|
| 246 |
|
- |
"INSERT INTO users (mnw_account_id, username, display_name)
|
| 247 |
|
- |
VALUES ($1, 'admin', 'Admin') ON CONFLICT DO NOTHING",
|
| 248 |
|
- |
)
|
| 249 |
|
- |
.bind(admin_id)
|
| 250 |
|
- |
.execute(&h.db)
|
| 251 |
|
- |
.await
|
| 252 |
|
- |
.unwrap();
|
| 253 |
|
- |
h.client.get("/").await;
|
| 254 |
|
- |
let body = serde_json::json!({ "user_id": admin_id.to_string(), "username": "admin" });
|
| 255 |
|
- |
h.client.post_json("/_test/login", &body.to_string()).await;
|
|
168 |
+ |
let mut h = TestHarness::new_with_admin_session(admin_id).await;
|
| 256 |
169 |
|
|
| 257 |
170 |
|
let resp = h
|
| 258 |
171 |
|
.client
|
| 265 |
178 |
|
#[sqlx::test]
|
| 266 |
179 |
|
async fn admin_suspend_creates_mod_log_entry(_pool: sqlx::PgPool) {
|
| 267 |
180 |
|
let admin_id = Uuid::new_v4();
|
| 268 |
|
- |
let mut h = TestHarness::new_with_admin(admin_id).await;
|
| 269 |
|
- |
|
| 270 |
|
- |
sqlx::query(
|
| 271 |
|
- |
"INSERT INTO users (mnw_account_id, username, display_name)
|
| 272 |
|
- |
VALUES ($1, 'admin', 'Admin') ON CONFLICT DO NOTHING",
|
| 273 |
|
- |
)
|
| 274 |
|
- |
.bind(admin_id)
|
| 275 |
|
- |
.execute(&h.db)
|
| 276 |
|
- |
.await
|
| 277 |
|
- |
.unwrap();
|
| 278 |
|
- |
h.client.get("/").await;
|
| 279 |
|
- |
let body = serde_json::json!({ "user_id": admin_id.to_string(), "username": "admin" });
|
| 280 |
|
- |
h.client.post_json("/_test/login", &body.to_string()).await;
|
|
181 |
+ |
let mut h = TestHarness::new_with_admin_session(admin_id).await;
|
| 281 |
182 |
|
|
| 282 |
183 |
|
let community_id = h.create_community("Test", "test").await;
|
| 283 |
184 |
|
|