diff --git a/coffee_lib/src/types/mod.rs b/coffee_lib/src/types/mod.rs index 5ff63f36..19ead44b 100644 --- a/coffee_lib/src/types/mod.rs +++ b/coffee_lib/src/types/mod.rs @@ -6,44 +6,6 @@ pub mod request { use paperclip::actix::Apiv2Schema; use serde::{Deserialize, Serialize}; - #[cfg(not(feature = "open-api"))] - #[derive(Debug, Deserialize, Serialize)] - pub struct Install { - pub plugin: String, - pub try_dynamic: bool, - } - - #[cfg(not(feature = "open-api"))] - #[derive(Debug, Deserialize, Serialize)] - pub struct Remove { - pub plugin: String, - } - - #[cfg(not(feature = "open-api"))] - #[derive(Debug, Deserialize, Serialize)] - pub struct RemoteAdd { - pub repository_name: String, - pub repository_url: String, - } - - #[cfg(not(feature = "open-api"))] - #[derive(Debug, Deserialize, Serialize)] - pub struct RemoteRm { - pub repository_name: String, - } - - #[cfg(not(feature = "open-api"))] - #[derive(Debug, Deserialize, Serialize)] - pub struct Show { - pub plugin: String, - } - - #[cfg(not(feature = "open-api"))] - #[derive(Debug, Deserialize, Serialize)] - pub struct Search { - pub plugin: String, - } - #[cfg(feature = "open-api")] #[derive(Debug, Deserialize, Apiv2Schema, Serialize)] pub struct Install { diff --git a/tests/src/coffee_httpd_integration_tests.rs b/tests/src/coffee_httpd_integration_tests.rs index 8708df78..7e6d799f 100644 --- a/tests/src/coffee_httpd_integration_tests.rs +++ b/tests/src/coffee_httpd_integration_tests.rs @@ -103,103 +103,6 @@ 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::().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(), - }; - - let response = client - .get(format!("{}/show", url)) - .json(&show_request) - .send() - .await; - assert!(response.is_ok(), "{:?}", response); - let response = response.unwrap(); - - // Check the response status code, log the body. - assert!(response.status().is_success()); - let body = response.text().await.unwrap(); - log::info!("/show response: {}", body); - - // Parse the response body - let response_json = serde_json::from_str(&body); - assert!(response_json.is_ok(), "{:?}", response_json); - let response_json: serde_json::Value = response_json.unwrap(); - - // Extract the `readme` field from the response JSON - let readme = response_json["readme"].as_str(); - assert!(readme.is_some(), "{:?}", readme); - let readme = readme.unwrap(); - - // Assert that the `readme` starts with the expected content - assert!(readme.starts_with("# Helpme plugin"), "{:?}", readme); - - // Define the request body to be sent to the /search endpoint - let search_request = Search { - plugin: "summary".to_string(), - }; - - let response = client - .get(format!("{}/search", url)) - .json(&search_request) - .send() - .await; - assert!(response.is_ok(), "{:?}", response); - let response = response.unwrap(); - - // Check the response status code, log the body. - assert!(response.status().is_success()); - let body = response.text().await.unwrap(); - log::info!("/search response: {}", body); - - // Parse the response body - let response_json = serde_json::from_str(&body); - assert!(response_json.is_ok(), "{:?}", response_json); - let response_json: serde_json::Value = response_json.unwrap(); - - // Extract the `repository_url` field from the response JSON - let repository_url = response_json["repository_url"].as_str(); - assert!(repository_url.is_some(), "{:?}", repository_url); - let repository_url = repository_url.unwrap(); - - // Assert that repository_url is the expected value - assert_eq!( - repository_url, "https://github.com/lightningd/plugins", - "{:?}", - repository_url - ); - // Define the request body to be sent to the /install endpoint let install_request = Install { plugin: "summary".to_string(), @@ -218,24 +121,6 @@ pub async fn httpd_add_remove_plugins() { let body = response.text().await.unwrap(); log::info!("/install response: {}", body); - // Define the request body to be sent to the /install endpoint - let install_request = Install { - plugin: "helpme".to_string(), - try_dynamic: false, - }; - - let response = client - .post(format!("{}/install", url)) - .json(&install_request) - .send() - .await; - assert!(response.is_ok(), "{:?}", response); - let response = response.unwrap(); - - // Check the response status code, log the body. - let body = response.text().await.unwrap(); - log::info!("/install response: {}", body); - let body = reqwest::get(format!("{}/remote/list", url)).await; assert!(body.is_ok(), "{:?}", body); let body = body.unwrap().json::().await; @@ -265,14 +150,10 @@ pub async fn httpd_add_remove_plugins() { // Log the response body log::info!("/list response: {}", body); - // Assert that the "helpme" and "summary" plugin exist in the response + // Assert that the "summary" plugin exist in the response let plugins = body["plugins"].as_array(); assert!(plugins.is_some(), "{:?}", plugins); let plugins = plugins.unwrap(); - assert!( - plugins.iter().any(|plugin| plugin["name"] == "helpme"), - "helpme plugin not found in the response" - ); assert!( plugins.iter().any(|plugin| plugin["name"] == "summary"), "summary plugin not found in the response" @@ -296,24 +177,6 @@ pub async fn httpd_add_remove_plugins() { let body = response.text().await.unwrap(); log::info!("Response body: {}", body); - let body = reqwest::get(format!("{}/list", url)).await; - assert!(body.is_ok(), "{:?}", body); - let body = body.unwrap().json::().await; - assert!(body.is_ok(), "{:?}", body); - let body = body.unwrap(); - - // Log the response body - log::info!("/list response: {}", body); - - // Assert that the "summary" plugin was removed - let plugins = body["plugins"].as_array(); - assert!(plugins.is_some(), "{:?}", plugins); - let plugins = plugins.unwrap(); - assert!( - !(plugins.iter().any(|plugin| plugin["name"] == "summary")), - "summary plugin is found in the list response while it should have been removed" - ); - // Define the request body to be sent let remote_rm_request = RemoteRm { repository_name: "lightningd".to_string(), @@ -333,24 +196,6 @@ pub async fn httpd_add_remove_plugins() { let body = response.text().await.unwrap(); log::info!("/remote/rm response: {}", body); - let body = reqwest::get(format!("{}/list", url)).await; - assert!(body.is_ok(), "{:?}", body); - let body = body.unwrap().json::().await; - assert!(body.is_ok(), "{:?}", body); - let body = body.unwrap(); - - // Log the response body - log::info!("/list response: {}", body); - - // Assert that the "helpme" plugin was removed - let plugins = body["plugins"].as_array(); - assert!(plugins.is_some(), "{:?}", plugins); - let plugins = plugins.unwrap(); - assert!( - !(plugins.iter().any(|plugin| plugin["name"] == "helpme")), - "helpme plugin is found in the list response while it should have been removed" - ); - let body = reqwest::get(format!("{}/remote/list", url)).await; assert!(body.is_ok(), "{:?}", body); let body = body.unwrap().json::().await; @@ -373,3 +218,137 @@ pub async fn httpd_add_remove_plugins() { cln.stop().await.unwrap(); } + +#[tokio::test(flavor = "multi_thread")] +#[ntest::timeout(560000)] +pub async fn httpd_search_list_plugins() { + init(); + + let mut cln = Node::tmp("regtest").await.unwrap(); + let lightning_dir = cln.rpc().getinfo().unwrap().ligthning_dir; + let lightning_dir = lightning_dir.strip_suffix("/regtest").unwrap(); + let manager = CoffeeHTTPDTesting::tmp(lightning_dir.to_string()).await; + assert!(manager.is_ok(), "{:?}", manager); + let manager = manager.unwrap(); + log::info!("lightning path: {lightning_dir}"); + let url = manager.url(); + log::info!("base url: {url}"); + let client = reqwest::Client::new(); + + // Define the request body to be sent to the /remote/add endpoint + let remote_add_request = RemoteAdd { + repository_name: "lightningd".to_string(), + repository_url: "https://github.com/lightningd/plugins.git".to_string(), + }; + + let response = client + .post(format!("{}/remote/add", url)) + .json(&remote_add_request) + .send() + .await; + assert!(response.is_ok(), "{:?}", response); + let response = response.unwrap(); + + // Check the response status code, log the body. + assert!(response.status().is_success()); + 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::().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(), + }; + + let response = client + .get(format!("{}/show", url)) + .json(&show_request) + .send() + .await; + assert!(response.is_ok(), "{:?}", response); + let response = response.unwrap(); + + // Check the response status code, log the body. + assert!(response.status().is_success()); + let body = response.text().await.unwrap(); + log::info!("/show response: {}", body); + + // Parse the response body + let response_json = serde_json::from_str(&body); + assert!(response_json.is_ok(), "{:?}", response_json); + let response_json: serde_json::Value = response_json.unwrap(); + + // Extract the `readme` field from the response JSON + let readme = response_json["readme"].as_str(); + assert!(readme.is_some(), "{:?}", readme); + let readme = readme.unwrap(); + + // Assert that the `readme` starts with the expected content + assert!(readme.starts_with("# Helpme plugin"), "{:?}", readme); + + // Define the request body to be sent to the /search endpoint + let search_request = Search { + plugin: "summary".to_string(), + }; + + let response = client + .get(format!("{}/search", url)) + .json(&search_request) + .send() + .await; + assert!(response.is_ok(), "{:?}", response); + let response = response.unwrap(); + + // Check the response status code, log the body. + assert!(response.status().is_success()); + let body = response.text().await.unwrap(); + log::info!("/search response: {}", body); + + // Parse the response body + let response_json = serde_json::from_str(&body); + assert!(response_json.is_ok(), "{:?}", response_json); + let response_json: serde_json::Value = response_json.unwrap(); + + // Extract the `repository_url` field from the response JSON + let repository_url = response_json["repository_url"].as_str(); + assert!(repository_url.is_some(), "{:?}", repository_url); + let repository_url = repository_url.unwrap(); + + // Assert that repository_url is the expected value + assert_eq!( + repository_url, "https://github.com/lightningd/plugins", + "{:?}", + repository_url + ); + cln.stop().await.unwrap(); +}