Skip to content

Commit

Permalink
feat(test): add assertions for search command and httpd endpoint
Browse files Browse the repository at this point in the history
Signed-off-by: Tarek <[email protected]>
  • Loading branch information
tareknaser authored and vincenzopalazzo committed Jul 29, 2023
1 parent 3692a02 commit 3784046
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 1 deletion.
35 changes: 35 additions & 0 deletions tests/src/coffee_httpd_integration_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand Down
13 changes: 12 additions & 1 deletion tests/src/coffee_integration_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit 3784046

Please sign in to comment.