1#![doc = include_str!("../README.md")]
2
3pub use oanda_v20_openapi::*;
4
5#[cfg(test)]
6mod tests {
7 use super::*;
8 use serde_json::json;
9 use wiremock::{
10 Mock, MockServer, ResponseTemplate,
11 matchers::{header, method, path},
12 };
13
14 #[tokio::test]
15 async fn create_practice_context() {
16 let svr = MockServer::start().await;
17 Mock::given(method("GET"))
18 .and(path("/accounts"))
19 .and(header("Authorization", "Bearer TEST_TOKEN"))
20 .respond_with(ResponseTemplate::new(200).set_body_json(json!(
21 {
22 "accounts": [
23 {"id": "001-011-5838423-001", "tags": ["tag1", "tag2"]},
24 {"id": "001-011-5838423-002", "mt4AccountID": 42, "tags": []},
25 ]
26 }
27 )))
28 .expect(1)
29 .mount(&svr)
30 .await;
31
32 let config = apis::configuration::Configuration {
33 base_path: svr.uri(),
34 bearer_access_token: Some("TEST_TOKEN".to_string()),
35 ..Default::default()
36 };
37 let response = apis::account_api::get_accounts(&config).await.unwrap();
38 let Some(accs) = response.accounts else {
39 panic!("No accounts");
40 };
41
42 assert_eq!(accs[0].id, Some("001-011-5838423-001".to_string()));
43 assert_eq!(accs[0].mt4_account_id, None);
44 assert_eq!(accs[0].tags, Some(vec!["tag1".to_string(), "tag2".to_string()]));
45 assert_eq!(accs[1].id, Some("001-011-5838423-002".to_string()));
46 assert_eq!(accs[1].mt4_account_id, Some(42));
47 assert_eq!(accs[1].tags, Some(Vec::new()));
48 }
49}