Skip to content

Commit

Permalink
feat(httpd): add an endpoint for coffee_list_plugins_remote
Browse files Browse the repository at this point in the history
Signed-off-by: Tarek <tareknaser360@gmail.com>
  • Loading branch information
tareknaser committed Oct 2, 2023
1 parent d1f4383 commit 7e788c3
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 0 deletions.
15 changes: 15 additions & 0 deletions coffee_httpd/src/httpd/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ pub async fn run_httpd<T: ToSocketAddrs>(
.service(coffee_remote_list)
.service(coffee_show)
.service(coffee_search)
.service(coffee_list_plugins_in_remote)
.with_json_spec_at("/api/v1")
.build()
})
Expand Down Expand Up @@ -158,6 +159,20 @@ async fn coffee_remote_list(data: web::Data<AppState>) -> Result<Json<Value>, Er
handle_httpd_response!(result)
}

#[api_v2_operation]
#[get("/remote/list_plugins")]
async fn coffee_list_plugins_in_remote(
data: web::Data<AppState>,
body: Json<RemotePluginsList>,
) -> Result<Json<Value>, Error> {
let repository_name = &body.repository_name;

let coffee = data.coffee.lock().await;
let result = coffee.get_plugins_in_remote(repository_name).await;

handle_httpd_response!(result)
}

#[api_v2_operation]
#[get("/show")]
async fn coffee_show(data: web::Data<AppState>, body: Json<Show>) -> Result<Json<Value>, Error> {
Expand Down
31 changes: 31 additions & 0 deletions tests/src/coffee_httpd_integration_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,37 @@ pub async fn httpd_add_remove_plugins() {
let body = response.text().await.unwrap();
log::info!("/remote/add response: {}", body);

// Define the request body to be sent to the /remote/list_plugins endpoint
let remote_plugins_list_request = RemotePluginsList {
repository_name: "lightningd".to_string(),
};

let response = client
.get(format!("{}/remote/list_plugins", url))
.json(&remote_plugins_list_request)
.send()
.await;
assert!(response.is_ok(), "{:?}", response);
let response = response.unwrap();

let body = response.json::<serde_json::Value>().await;
assert!(body.is_ok(), "{:?}", body);
let body = body.unwrap();

// Log the response body
log::info!("/remote/list_plugins response: {}", body);

// Assert the response plugin list is not empty
let plugins = body["plugins"].as_array();
assert!(plugins.is_some(), "{:?}", plugins);
let plugins = plugins.unwrap();

// Assert that the "helpme" plugin exists in the response
assert!(
plugins.iter().any(|plugin| plugin["name"] == "helpme"),
"helpme plugin not found in the response"
);

// Define the request body to be sent to the /show endpoint
let show_request = Show {
plugin: "helpme".to_string(),
Expand Down

0 comments on commit 7e788c3

Please sign in to comment.