| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
use crate::harness::TestHarness; |
| 5 |
use serde_json::Value; |
| 6 |
|
| 7 |
#[tokio::test] |
| 8 |
async fn create_project_and_publish_item() { |
| 9 |
let mut h = TestHarness::new().await; |
| 10 |
|
| 11 |
|
| 12 |
let user_id = h.signup("creator1", "creator1@example.com", "password123").await; |
| 13 |
h.grant_creator(user_id).await; |
| 14 |
|
| 15 |
|
| 16 |
h.client.post_form("/logout", "").await; |
| 17 |
h.login("creator1", "password123").await; |
| 18 |
|
| 19 |
|
| 20 |
let resp = h |
| 21 |
.client |
| 22 |
.post_form("/api/projects", "slug=test-project&title=Test+Project") |
| 23 |
.await; |
| 24 |
assert!( |
| 25 |
resp.status.is_success(), |
| 26 |
"Create project failed: {} {}", |
| 27 |
resp.status, |
| 28 |
resp.text |
| 29 |
); |
| 30 |
let project: Value = resp.json(); |
| 31 |
let project_id = project["id"].as_str().expect("project should have id"); |
| 32 |
|
| 33 |
|
| 34 |
let resp = h |
| 35 |
.client |
| 36 |
.post_form( |
| 37 |
&format!("/api/projects/{}/items", project_id), |
| 38 |
"title=Test+Item&price_cents=0&item_type=digital", |
| 39 |
) |
| 40 |
.await; |
| 41 |
assert!( |
| 42 |
resp.status.is_success(), |
| 43 |
"Create item failed: {} {}", |
| 44 |
resp.status, |
| 45 |
resp.text |
| 46 |
); |
| 47 |
let item: Value = resp.json(); |
| 48 |
let item_id = item["id"].as_str().expect("item should have id"); |
| 49 |
|
| 50 |
|
| 51 |
let resp = h |
| 52 |
.client |
| 53 |
.put_json( |
| 54 |
&format!("/api/projects/{}", project_id), |
| 55 |
r#"{"is_public": true}"#, |
| 56 |
) |
| 57 |
.await; |
| 58 |
assert!( |
| 59 |
resp.status.is_success(), |
| 60 |
"Make project public failed: {} {}", |
| 61 |
resp.status, |
| 62 |
resp.text |
| 63 |
); |
| 64 |
|
| 65 |
|
| 66 |
let resp = h |
| 67 |
.client |
| 68 |
.put_form(&format!("/api/items/{}", item_id), "is_public=true") |
| 69 |
.await; |
| 70 |
assert!( |
| 71 |
resp.status.is_success(), |
| 72 |
"Make item public failed: {} {}", |
| 73 |
resp.status, |
| 74 |
resp.text |
| 75 |
); |
| 76 |
|
| 77 |
|
| 78 |
let resp = h.client.get("/discover").await; |
| 79 |
assert_eq!(resp.status, 200, "Discover page should load"); |
| 80 |
assert!( |
| 81 |
resp.text.contains("Test Project"), |
| 82 |
"Discover page should show the published project" |
| 83 |
); |
| 84 |
|
| 85 |
|
| 86 |
let resp = h.client.get("/discover?mode=items").await; |
| 87 |
assert_eq!(resp.status, 200, "Discover items mode should load"); |
| 88 |
assert!( |
| 89 |
resp.text.contains("Test Item"), |
| 90 |
"Discover items mode should show the published item" |
| 91 |
); |
| 92 |
} |
| 93 |
|