From 3784046796a159511258e535c46e9d0ab550d2ed Mon Sep 17 00:00:00 2001 From: Tarek Date: Sat, 29 Jul 2023 19:48:40 +0300 Subject: [PATCH] feat(test): add assertions for search command and httpd endpoint Signed-off-by: Tarek --- tests/src/coffee_httpd_integration_tests.rs | 35 +++++++++++++++++++++ tests/src/coffee_integration_tests.rs | 13 +++++++- 2 files changed, 47 insertions(+), 1 deletion(-) diff --git a/tests/src/coffee_httpd_integration_tests.rs b/tests/src/coffee_httpd_integration_tests.rs index ed749534..8a4ecc4b 100644 --- a/tests/src/coffee_httpd_integration_tests.rs +++ b/tests/src/coffee_httpd_integration_tests.rs @@ -134,6 +134,41 @@ pub async fn httpd_add_remove_plugins() { // 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(), diff --git a/tests/src/coffee_integration_tests.rs b/tests/src/coffee_integration_tests.rs index eb1ffb28..d9faee89 100644 --- a/tests/src/coffee_integration_tests.rs +++ b/tests/src/coffee_integration_tests.rs @@ -84,7 +84,7 @@ pub async fn init_coffee_test_with_cln() -> anyhow::Result<()> { } #[tokio::test] -//#[ntest::timeout(120000)] +#[ntest::timeout(560000)] pub async fn init_coffee_test_add_remote() { init(); let mut cln = Node::tmp("regtest").await.unwrap(); @@ -240,6 +240,17 @@ pub async fn test_errors_and_show() { .await .unwrap(); + // Search for summary plugin + let result = manager.coffee().search("summary").await; + assert!(result.is_ok(), "{:?}", result); + let result = result.unwrap(); + let repo_url = result.repository_url.as_str(); + assert_eq!( + repo_url, "https://github.com/lightningd/plugins", + "{:?}", + repo_url + ); + // Install summary plugin let result = manager.coffee().install("summary", true, false).await; assert!(result.is_ok(), "{:?}", result);