Skip to content

Commit

Permalink
http: Add node endpoint tests
Browse files Browse the repository at this point in the history
  • Loading branch information
sebastinez committed Jun 27, 2024
1 parent df5044f commit 4dcaa2e
Showing 1 changed file with 102 additions and 0 deletions.
102 changes: 102 additions & 0 deletions radicle-httpd/src/api/v1/node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -136,3 +136,105 @@ async fn node_policies_unseed_handler(

Ok::<_, Error>((StatusCode::OK, Json(json!({ "success": true }))))
}

#[cfg(test)]
mod routes {
use std::net::SocketAddr;

use axum::extract::connect_info::MockConnectInfo;
use axum::http::StatusCode;
use pretty_assertions::assert_eq;
use serde_json::json;

use crate::test::*;

#[tokio::test]
async fn test_node_repos_policies() {
let tmp = tempfile::tempdir().unwrap();
let seed = seed(tmp.path());
let app = super::router(seed.clone())
.layer(MockConnectInfo(SocketAddr::from(([127, 0, 0, 1], 8080))));
let response = get(&app, "/node/policies/repos").await;

assert_eq!(response.status(), StatusCode::OK);
assert_eq!(
response.json().await,
json!([
{
"rid": "rad:zLuTzcmoWMcdK37xqArS8eckp9vK",
"policy": {
"scope": "all",
"policy": "allow",
}
},
{
"rid": "rad:z4FucBZHZMCsxTyQE1dfE2YR59Qbp",
"policy": {
"scope": "all",
"policy": "allow",
}
},
{
"rid": "rad:z4GypKmh1gkEfmkXtarcYnkvtFUfE",
"policy": {
"scope": "all",
"policy": "allow",
}
},
])
);
}

#[tokio::test]
async fn test_node_repo_policies() {
let tmp = tempfile::tempdir().unwrap();
let seed = seed(tmp.path());
let app = super::router(seed.clone())
.layer(MockConnectInfo(SocketAddr::from(([127, 0, 0, 1], 8080))));
let response = get(
&app,
"/node/policies/repos/rad:zLuTzcmoWMcdK37xqArS8eckp9vK",
)
.await;

assert_eq!(response.status(), StatusCode::OK);
assert_eq!(
response.json().await,
json!({
"scope": "all",
"policy": "allow",
})
);
}

#[tokio::test]
async fn test_nodes() {
let tmp = tempfile::tempdir().unwrap();
let seed = seed(tmp.path());
let app = super::router(seed.clone())
.layer(MockConnectInfo(SocketAddr::from(([127, 0, 0, 1], 8080))));
let nid = seed.profile().id();
let response = get(&app, format!("/nodes/{nid}")).await;

assert_eq!(response.status(), StatusCode::OK);
assert_eq!(
response.json().await,
json!({
"alias": "seed",
})
);
}

#[tokio::test]
async fn test_nodes_inventory() {
let tmp = tempfile::tempdir().unwrap();
let seed = seed(tmp.path());
let app = super::router(seed.clone())
.layer(MockConnectInfo(SocketAddr::from(([127, 0, 0, 1], 8080))));
let nid = seed.profile().public_key;
let response = get(&app, format!("/nodes/{nid}/inventory")).await;

assert_eq!(response.status(), StatusCode::OK);
assert_eq!(response.json().await, json!([]));
}
}

0 comments on commit 4dcaa2e

Please sign in to comment.