use quiverquant::{Client, ClientError}; const TEST_TICKERS: &[&str] = &["AMZN", "GME", "TSLA", "AMC", "MFST"]; /// Set up the client setting the API token from the ENV. fn setup_client() -> Client { let key = std::env::var("QQ_API_KEY").expect("API KEY is not set!"); Client::new(key) } #[tokio::test] async fn get_congress_trading() { let client = setup_client(); let result = client.congress_trades().await; println!("Result: {:?}", result); assert!(result.is_ok()); } #[tokio::test] /// Test that the API returns correctly when given a valid ticker async fn get_congress_trading_by_ticker() { let client = setup_client(); for ticker in TEST_TICKERS { let result = client.congress_trades_by_ticker(*ticker).await; println!("Ticker: {}, Result is OK: {:?}", *ticker, result.is_ok()); assert!(result.is_ok()); } } #[tokio::test] async fn get_senate_trading() { let client = setup_client(); let result = client.senate_trades().await; println!("Result: {:?}", result); assert!(result.is_ok()); } #[tokio::test] async fn get_senate_trading_by_ticker() { let client = setup_client(); for ticker in TEST_TICKERS { let result = client.senate_trades_by_ticker(*ticker).await; println!("Ticker: {}, Result is OK: {:?}", *ticker, result.is_ok()); assert!(result.is_ok()); } } #[tokio::test] async fn get_house_trading() { let client = setup_client(); let result = client.house_trades().await; println!("Result: {:?}", result); assert!(result.is_ok()); } #[tokio::test] async fn get_house_trading_by_ticker() { let client = setup_client(); for ticker in TEST_TICKERS { let result = client.house_trades_by_ticker(*ticker).await; println!("Ticker: {}, Result is OK: {:?}", *ticker, result.is_ok()); assert!(result.is_ok()); } } #[tokio::test] async fn get_gov_contracts() { let client = setup_client(); let result = client.gov_contracts().await; println!("Result: {:?}", result); assert!(result.is_ok()); } #[tokio::test] async fn get_gov_contracts_by_ticker() { let client = setup_client(); for ticker in TEST_TICKERS { let result = client.gov_contracts_by_ticker(*ticker).await; println!("Result: {:?}", result); assert!(result.is_ok()); } } #[tokio::test] async fn get_lobbying() { let client = setup_client(); let result = client.lobbying().await; println!("Result: {:?}", result); assert!(result.is_ok()); } #[tokio::test] async fn get_lobbying_by_ticker() { let client = setup_client(); for ticker in TEST_TICKERS { let result = client.lobbying_by_ticker(*ticker).await; println!("Ticker: {}, Result is OK: {:?}", *ticker, result.is_ok()); assert!(match result { Ok(_) => true, Err(error) => { match error { ClientError::InternalServerError => true, _ => false, } } }) } }