-
Notifications
You must be signed in to change notification settings - Fork 77
Expand file tree
/
Copy pathtest_toggle_webhook.rs
More file actions
106 lines (93 loc) · 3.65 KB
/
test_toggle_webhook.rs
File metadata and controls
106 lines (93 loc) · 3.65 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
use helius::config::Config;
use helius::error::Result;
use helius::rpc_client::RpcClient;
use helius::types::{ApiKey, Cluster, HeliusEndpoints, ToggleWebhookRequest, TransactionType, Webhook, WebhookType};
use helius::Helius;
use mockito::Server;
use reqwest::Client;
use std::sync::Arc;
#[tokio::test]
async fn test_toggle_webhook_success() {
let mut server: Server = Server::new_with_opts_async(mockito::ServerOpts::default()).await;
let url: String = format!("{}/", server.url());
let mock_response: Webhook = Webhook {
webhook_url: "https://webhook.site/0e8250a1-ceec-4757-ad69-cc6473085bfc".to_string(),
transaction_types: vec![TransactionType::Any],
account_addresses: vec![],
webhook_type: WebhookType::Enhanced,
auth_header: None,
webhook_id: "0e8250a1-ceec-4757-ad69".to_string(),
wallet: "9Jt8mC9HXvh2g5s3PbTsNU71RS9MXUbhEMEmLTixYirb".to_string(),
project: "Mockito".to_string(),
active: false,
..Default::default()
};
server
.mock("PATCH", "/v0/webhooks/0e8250a1-ceec-4757-ad69?api-key=fake_api_key")
.with_status(200)
.with_header("Content-Type", "application/json")
.with_body(serde_json::to_string(&mock_response).unwrap())
.create();
let config: Arc<Config> = Arc::new(Config {
api_key: Some(ApiKey::new("fake_api_key").unwrap()),
cluster: Cluster::Devnet,
endpoints: HeliusEndpoints {
api: url.to_string(),
rpc: url.to_string(),
},
custom_url: None,
});
let client: Client = Client::new();
let rpc_client: Arc<RpcClient> = Arc::new(RpcClient::new(Arc::new(client.clone()), Arc::clone(&config)).unwrap());
let helius: Helius = Helius {
config,
client,
rpc_client,
async_rpc_client: None,
ws_client: None,
};
let request: ToggleWebhookRequest = ToggleWebhookRequest {
webhook_id: "0e8250a1-ceec-4757-ad69".to_string(),
active: false,
};
let response: Result<Webhook> = helius.toggle_webhook(request).await;
assert!(response.is_ok(), "The API call failed: {:?}", response.err());
let webhook_response: Webhook = response.unwrap();
assert_eq!(webhook_response.webhook_id, "0e8250a1-ceec-4757-ad69");
assert!(!webhook_response.active);
}
#[tokio::test]
async fn test_toggle_webhook_failure() {
let mut server: Server = Server::new_with_opts_async(mockito::ServerOpts::default()).await;
let url: String = format!("{}/", server.url());
server
.mock("PATCH", "/v0/webhooks/0e8250a1-ceec-4757-ad69?api-key=fake_api_key")
.with_status(500)
.with_header("Content-Type", "application/json")
.with_body(r#"{"error":"Internal Server Error"}"#)
.create();
let config: Arc<Config> = Arc::new(Config {
api_key: Some(ApiKey::new("fake_api_key").unwrap()),
cluster: Cluster::Devnet,
endpoints: HeliusEndpoints {
api: url.to_string(),
rpc: url.to_string(),
},
custom_url: None,
});
let client: Client = Client::new();
let rpc_client: Arc<RpcClient> = Arc::new(RpcClient::new(Arc::new(client.clone()), Arc::clone(&config)).unwrap());
let helius: Helius = Helius {
config,
client,
rpc_client,
async_rpc_client: None,
ws_client: None,
};
let request: ToggleWebhookRequest = ToggleWebhookRequest {
webhook_id: "0e8250a1-ceec-4757-ad69".to_string(),
active: true,
};
let response: Result<Webhook> = helius.toggle_webhook(request).await;
assert!(response.is_err(), "Expected an error due to server failure");
}