mod test_util;
use assert_cmd::Command;
use httpmock::prelude::HttpMockRequest;
use std::env;
use std::fs;
use test_util::*;
static COMPONENT_CONTENT: &str = "return <>hello</>";
#[test]
fn test_bos_components_deploy_with_mocked_rpc() {
let mut server = setup_mock_server();
let broadcast_tx_commit_matcher = move |req: &HttpMockRequest| {
if let Some(body) = &req.body {
return match_broadcast_tx_commit_for_component_content(body, COMPONENT_CONTENT);
}
false
};
server = mock_broadcast_tx_commit(server, COMPONENT_CONTENT, broadcast_tx_commit_matcher);
server = mock_unmatched(server);
let temp_dir = setup_temp_dir();
unsafe {
env::set_var("XDG_CONFIG_HOME", temp_dir.path());
env::set_var("HOME", temp_dir.path());
}
let config_dir = dirs::config_dir().unwrap().join("near-cli");
setup_config(&config_dir, &server.url("/"));
let component_path = temp_dir.path().join("src").join("example_component.jsx");
fs::write(&component_path, COMPONENT_CONTENT).unwrap();
env::set_current_dir(&temp_dir).unwrap();
let mut cmd = Command::cargo_bin("bos").unwrap();
cmd.args([
"components",
"deploy",
"test.near",
"sign-as",
"test.near",
"network-config",
"mainnet", "sign-with-plaintext-private-key",
"ed25519:VzeoRptTNGWeXwq3JNLdo8XqoBKvjSXyV5VxjvxPyzsiGmwo2Vu6LTiBujoQSXYjF8khQS5r3SSQK3xV8uomjv7",
"send",
])
.assert()
.success()
.stdout(predicates::str::contains("components were successfully deployed"));
}