Skip to content

Commit fba169a

Browse files
committed
test(get): cover UUID-by-UUID paid-required path on public proxy
`get_uuid_paid_patch_via_public_proxy_emits_paid_required_envelope` in `get_invariants.rs`: mocks the public-proxy `/patch/view/<uuid>` endpoint to serve `tier: "paid"` and asserts the JSON envelope shape (`status: paid_required`, `found:1, downloaded:0, applied:0`, `patches[0].tier: "paid"`). The existing paid-required test covered the package-name search path; this one closes the UUID-fetch branch in `commands/get.rs:756-768` that was never driven. Assisted-by: Claude Code:claude-opus-4-7
1 parent 8843e67 commit fba169a

1 file changed

Lines changed: 61 additions & 0 deletions

File tree

crates/socket-patch-cli/tests/get_invariants.rs

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -337,6 +337,67 @@ async fn get_multiple_patches_in_json_mode_returns_selection_required() {
337337
// Paid patch path
338338
// ---------------------------------------------------------------------------
339339

340+
/// UUID-by-UUID fetch via public proxy when the patch is paid:
341+
/// the binary recognises the identifier as a UUID, hits the
342+
/// `/patch/view/<uuid>` endpoint on the proxy, sees `tier: "paid"`
343+
/// in the response, and emits a `paid_required` JSON envelope.
344+
/// Covers the UUID-specific branch of the paid path in
345+
/// `commands::get::run`.
346+
#[tokio::test]
347+
async fn get_uuid_paid_patch_via_public_proxy_emits_paid_required_envelope() {
348+
let mock = MockServer::start().await;
349+
350+
// Public-proxy view-by-UUID endpoint.
351+
Mock::given(method("GET"))
352+
.and(path(format!("/patch/view/{UUID}")))
353+
.respond_with(ResponseTemplate::new(200).set_body_json(serde_json::json!({
354+
"uuid": UUID,
355+
"purl": "pkg:npm/paid-by-uuid@1.0.0",
356+
"publishedAt": "2024-01-01T00:00:00Z",
357+
"files": {},
358+
"vulnerabilities": {},
359+
"description": "Paid patch fetched by UUID",
360+
"license": "MIT",
361+
"tier": "paid",
362+
})))
363+
.mount(&mock)
364+
.await;
365+
366+
let tmp = tempfile::tempdir().expect("tempdir");
367+
let out = Command::new(binary())
368+
.args([
369+
"get",
370+
UUID,
371+
"--json",
372+
"--save-only",
373+
"--yes",
374+
"--api-url",
375+
&mock.uri(),
376+
])
377+
.current_dir(tmp.path())
378+
.env("SOCKET_PATCH_PROXY_URL", mock.uri())
379+
.env_remove("SOCKET_API_TOKEN")
380+
.output()
381+
.expect("run socket-patch");
382+
383+
let stdout = String::from_utf8_lossy(&out.stdout);
384+
let v: serde_json::Value = serde_json::from_str(stdout.trim()).unwrap_or_else(|e| {
385+
panic!("invalid JSON envelope: {e}\nstdout:\n{stdout}\nstderr:\n{}",
386+
String::from_utf8_lossy(&out.stderr))
387+
});
388+
assert_eq!(
389+
v["status"], "paid_required",
390+
"UUID-fetched paid patch via public proxy must emit paid_required; got {v}"
391+
);
392+
assert_eq!(v["found"], 1);
393+
assert_eq!(v["downloaded"], 0);
394+
assert_eq!(v["applied"], 0);
395+
let patches = v["patches"].as_array().expect("patches array");
396+
assert_eq!(patches.len(), 1);
397+
assert_eq!(patches[0]["uuid"], UUID);
398+
assert_eq!(patches[0]["tier"], "paid");
399+
}
400+
340401
#[tokio::test]
341402
async fn get_paid_patch_via_public_proxy_returns_paid_required() {
342403
// When using the public proxy (no api-token + no org), a paid patch

0 commit comments

Comments
 (0)