From 6cd8cc6ff5bffb9bc2da2d6e702c9906af26f959 Mon Sep 17 00:00:00 2001 From: Bendik Aagaard Lynghaug Date: Sun, 23 Aug 2026 11:27:49 +0200 Subject: [PATCH] Showcase jq test tracks Gitea repo shape and website-first links Mirrors the index.yaml filter change in uhhm/questions: fixture now carries Gitea 1.27's actual fields (stars_count, website, private) and the test covers all three link outcomes - public repo without a website links to the repo, private with a website links there, and private without one gets url: null so the card renders unlinked instead of 404ing for visitors. Co-Authored-By: Claude Fable 5 --- src/resource.rs | 43 +++++++++++++++++++++++++++++++++---------- 1 file changed, 33 insertions(+), 10 deletions(-) diff --git a/src/resource.rs b/src/resource.rs index 4eb14d4..b2d8ebb 100644 --- a/src/resource.rs +++ b/src/resource.rs @@ -442,10 +442,14 @@ mod tests { use super::*; /// A canned, Gitea-API-shaped fixture - the same fields the real - /// `/users/{username}/starred` endpoint returns - run through the + /// `/users/{username}/starred` endpoint returns (Gitea 1.27: + /// `stars_count`, not GitHub's `stargazers_count`; `website` is "" + /// when the repo's Website setting is empty) - run through the /// filter `index.yaml`'s "What we've built" resource actually /// declares, confirming the `jaq` integration produces the shape - /// the frontend showcase card expects. + /// the frontend showcase card expects: the Website setting wins + /// over the repo url, and a private repo without one gets a null + /// url (unlinked card) instead of a link that 404s for visitors. #[test] fn jq_shapes_gitea_repo_list_for_the_showcase() { let input = serde_json::json!([ @@ -453,25 +457,44 @@ mod tests { "name": "cnats", "description": "A NATS-backed chat client", "html_url": "https://project.uhhm.no/bl/cnats", - "stargazers_count": 3, + "website": "", + "stars_count": 3, "private": false }, { - "name": "portal", - "description": "This app", - "html_url": "https://project.uhhm.no/uhhm/portal", - "stargazers_count": 1, - "private": false + "name": "secret-product", + "description": "Private repo advertised via its homepage", + "html_url": "https://project.uhhm.no/uhhm/secret-product", + "website": "https://secret-product.example", + "stars_count": 2, + "private": true + }, + { + "name": "internal-tool", + "description": "Private repo with no homepage", + "html_url": "https://project.uhhm.no/uhhm/internal-tool", + "website": "", + "stars_count": 1, + "private": true } ]); - let filter = ".[] | {name: .name, description: .description, url: .html_url, stars: .stargazers_count}"; + let filter = r#".[] | {name: .name, description: .description, + stars: .stars_count, + url: (if .website != null and .website != "" then .website + elif .private then null + else .html_url end)}"#; let shaped = apply_jq(filter, &input).expect("filter runs"); let items = shaped.as_array().expect("array output"); - assert_eq!(items.len(), 2); + assert_eq!(items.len(), 3); + // Public without a website still links to the repo. assert_eq!(items[0]["name"], "cnats"); assert_eq!(items[0]["url"], "https://project.uhhm.no/bl/cnats"); assert_eq!(items[0]["stars"], 3); + // Private with a website links there, never to the repo. + assert_eq!(items[1]["url"], "https://secret-product.example"); + // Private without a website gets no link at all. + assert_eq!(items[2]["url"], serde_json::Value::Null); // The filter never mentions `private` - confirms shaping // actually drops fields, not just passes the object through. assert!(items[0].get("private").is_none());