Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 15 additions & 1 deletion src/publish.rs
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,18 @@ fn visibility_arg(v: &str) -> Result<&str, String> {
})
}

/// What the new visibility means, from the server's `status`.
fn visibility_note(visibility: &str, status: Option<&str>) -> &'static str {
match (visibility, status) {
("public", Some("pending_review")) => ": pending review before it is listed publicly",
("public", Some("accepted")) => ": listed publicly",
("public", Some("rejected")) => ": rejected in review, so it is not listed",
("unlisted", _) => ": anyone with the link can open it; not listed",
("private", _) => ": only you can open it",
_ => "",
}
}

/// Server message for a failed call, plus the exit code it maps to.
fn failure(status: u16, text: &str, what: &str) -> (String, i32) {
let v: Value = serde_json::from_str(text).unwrap_or(Value::Null);
Expand Down Expand Up @@ -458,7 +470,9 @@ fn apps_inner(parsed: &ParsedArgs, env: &BTreeMap<String, String>) -> Result<i32
if parsed.flag_true("json") {
println!("{}", serde_json::to_string_pretty(&v).unwrap_or_default());
} else {
eprintln!("{app}/{id} is now {want}");
let got = v.get("visibility").and_then(Value::as_str).unwrap_or(want);
let status = v.get("status").and_then(Value::as_str);
eprintln!("{app}/{id} is now {got}{}", visibility_note(got, status));
}
Ok(0)
}
Expand Down
43 changes: 43 additions & 0 deletions tests/publish.rs
Original file line number Diff line number Diff line change
Expand Up @@ -297,6 +297,10 @@ fn apps_verbs_hit_the_generic_routes() {
let cmd = cli(&base, &["apps", "visibility", "demo", "k1", "private"]);
let (code, _, err) = run(cmd);
assert_eq!(code, 0, "{err}");
assert!(
err.contains("demo/k1 is now private: only you can open it"),
"{err}"
);
let seen = rx.recv().unwrap();
assert!(
seen.starts_with("PATCH /api/v1/apps/demo/submissions/k1"),
Expand All @@ -314,6 +318,45 @@ fn apps_verbs_hit_the_generic_routes() {
.starts_with("DELETE /api/v1/apps/demo/submissions/k1"));
}

#[test]
fn apps_visibility_public_says_whether_it_waits_for_review_or_is_listed() {
let (base, _rx) = serve(vec![(
200,
r#"{"id":"k1","visibility":"public","status":"pending_review"}"#,
)]);
let cmd = cli(&base, &["apps", "visibility", "demo", "k1", "public"]);
let (code, _, err) = run(cmd);
assert_eq!(code, 0, "{err}");
assert!(
err.contains("demo/k1 is now public: pending review before it is listed publicly"),
"{err}"
);

// Already approved: going public again lists it with no second review.
let (base, _rx) = serve(vec![(
200,
r#"{"id":"k1","visibility":"public","status":"accepted"}"#,
)]);
let cmd = cli(&base, &["apps", "visibility", "demo", "k1", "public"]);
let (code, _, err) = run(cmd);
assert_eq!(code, 0, "{err}");
assert!(
err.contains("demo/k1 is now public: listed publicly"),
"{err}"
);

let (base, _rx) = serve(vec![(
200,
r#"{"id":"k1","visibility":"unlisted","status":"accepted"}"#,
)]);
let cmd = cli(&base, &["apps", "visibility", "demo", "k1", "unlisted"]);
let (_, _, err) = run(cmd);
assert!(
err.contains("demo/k1 is now unlisted: anyone with the link can open it; not listed"),
"{err}"
);
}

#[test]
fn apps_rm_without_yes_refuses_when_not_interactive() {
let (base, rx) = serve(vec![]);
Expand Down
Loading