Skip to content

Commit

Permalink
Charms info recursive
Browse files Browse the repository at this point in the history
  • Loading branch information
elocremarc committed Oct 7, 2024
1 parent f1c1ee5 commit 500f19e
Showing 1 changed file with 32 additions and 0 deletions.
32 changes: 32 additions & 0 deletions src/subcommand/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,7 @@ impl Server {
"/r/inscription/:inscription_id",
get(Self::inscription_recursive),
)
.route("/r/charms", get(Self::charms))
.route("/r/children/:inscription_id", get(Self::children_recursive))
.route(
"/r/children/:inscription_id/:page",
Expand Down Expand Up @@ -1739,6 +1740,15 @@ impl Server {
})
}

async fn charms() -> ServerResult {
let charms_map: HashMap<String, String> = Charm::ALL
.iter()
.map(|charm| (charm.icon().to_string(), charm.to_string()))
.collect();

Ok(Json(charms_map).into_response())
}

async fn collections(
Extension(server_config): Extension<Arc<ServerConfig>>,
Extension(index): Extension<Arc<Index>>,
Expand Down Expand Up @@ -6242,6 +6252,28 @@ next
.is_none());
}

#[test]
fn charms_recursive() {
let server = TestServer::new();

let charms_response = server.get_json::<HashMap<String, String>>("/r/charms");

assert!(!charms_response.is_empty());

for charm in Charm::ALL {
let icon = charm.icon();
let name = charm.to_string();
assert_eq!(charms_response.get(icon), Some(&name));
}

assert_eq!(charms_response.len(), Charm::ALL.len());

for value in charms_response.values() {
assert!(Charm::ALL.iter().any(|c| c.to_string() == *value));
}
}


#[test]
fn children_recursive_endpoint() {
let server = TestServer::builder().chain(Chain::Regtest).build();
Expand Down

0 comments on commit 500f19e

Please sign in to comment.