use openfigi_rs::model::{
enums::{Currency, ExchCode, IdType, MarketSecDesc, SecurityType},
request::MappingRequest,
};
use serde_json::json;
use serial_test::serial;
mod common;
use common::{create_test_client, rate_limit_delay};
#[tokio::test]
#[serial]
async fn test_mapping_single_isin_request() {
let client = create_test_client();
let mapping_data = client
.mapping(IdType::IdIsin, "US4592001014")
.send()
.await
.expect("Mapping request should succeed");
let figi_result = mapping_data.data();
assert!(
!figi_result.is_empty(),
"Expected FIGI data, but received an empty response"
);
for data in figi_result {
assert!(!data.figi.is_empty(), "Expected FIGI field to be non-empty");
}
rate_limit_delay().await;
}
#[tokio::test]
#[serial]
async fn test_mapping_with_filters() {
let client = create_test_client();
let mapping_data = client
.mapping(IdType::Ticker, "IBM")
.currency(Currency::USD)
.exch_code(ExchCode::US)
.market_sec_des(MarketSecDesc::Equity)
.security_type(SecurityType::CommonStock)
.send()
.await
.expect("Mapping request with filters should succeed");
let figi_result = mapping_data.data();
assert!(
!figi_result.is_empty(),
"Expected FIGI data, but received an empty response"
);
for data in figi_result {
if let Some(exch_code) = &data.exch_code {
assert_eq!(exch_code, &ExchCode::US);
}
if let Some(security_type) = &data.security_type {
assert_eq!(security_type, &SecurityType::CommonStock);
}
}
rate_limit_delay().await;
}
#[tokio::test]
#[serial]
async fn test_mapping_bulk_request() {
let client = create_test_client();
let requests = vec![
MappingRequest::new(IdType::IdIsin, json!("US4592001014")),
MappingRequest::new(IdType::Ticker, json!("AAPL")),
MappingRequest::new(IdType::Ticker, json!("MSFT")),
];
let mapping_responses = client
.bulk_mapping()
.add_requests(requests)
.send()
.await
.expect("Bulk mapping should succeed");
assert_eq!(mapping_responses.len(), 3);
for (i, result) in mapping_responses.as_slice().iter().enumerate() {
match result {
Ok(data) => {
assert!(
!data.data().is_empty(),
"Expected non-empty data for index {i}"
);
}
Err(e) => {
panic!("Expected successful mapping for index {i}, but got error: {e}");
}
}
}
rate_limit_delay().await;
}
#[tokio::test]
#[serial]
async fn test_mapping_invalid_identifier() {
let client = create_test_client();
let mapping_data = client
.mapping(IdType::IdIsin, json!("INVALID_ISIN"))
.send()
.await;
match mapping_data {
Ok(_) => panic!("Expected error, got MappingData for invalid identifier"),
Err(e) => {
assert!(e.to_string().contains("Invalid idValue format."));
}
}
rate_limit_delay().await;
}