fn setup() -> (String, String) { match ( std::env::var("ZIPWHIP_SESSION_KEY"), std::env::var("ZIPWHIP_TEST_NUMBER"), ) { (Ok(key), Ok(number)) => (key, number), (_, _) => panic!("Missing either ZIPWHIP_TEST_NUMBER or ZIPWHIP_SESSION_KEY"), } } #[tokio::test] async fn login() { assert!(zipwhip_rs::Client::login( std::env::var("ZIPWHIP_USERNAME").expect("ZIPWHIP_USERNAME not set"), std::env::var("ZIPWHIP_PASSWORD").expect("ZIPWHIP_PASSWORD not set") ) .await .is_ok()); } #[tokio::test] async fn logout() { let acc = zipwhip_rs::Client::login( std::env::var("ZIPWHIP_USERNAME").expect("ZIPWHIP_USERNAME not set"), std::env::var("ZIPWHIP_PASSWORD").expect("ZIPWHIP_PASSWORD not set"), ) .await; assert!(acc.is_ok()); let acc = acc.unwrap(); assert!(acc.logout().await.is_ok()); } #[tokio::test] async fn send_sms() { let (key, number) = setup(); let body = "Test"; let zw_client = zipwhip_rs::Client::with_key(key); assert!(zw_client.send_sms(number, body).await.is_ok()) } #[tokio::test] async fn send_group_sms() { let (key, number) = setup(); let body = "Testing Group SMS"; let zw_client = zipwhip_rs::Client::with_key(key); assert!(zw_client.group_sms(vec![number], body).await.is_ok()) } #[tokio::test] async fn send_bulk_sms() { let (key, number) = setup(); let body = "Bulk SMS Test"; let zw_client = zipwhip_rs::Client::with_key(key); zw_client .bulk_sms(vec![number], body) .await .iter() .for_each(|r| assert!(r.is_ok())) } #[tokio::test] async fn send_mms() { let (key, number) = setup(); let zw_client = zipwhip_rs::Client::with_key(key); let result = zw_client.send_mms(number, "Test MMS").await; eprintln!("Result: {:?}", result); assert!(result.is_ok()) } #[tokio::test] async fn send_group_mms() { let (key, number) = setup(); let zw_client = zipwhip_rs::Client::with_key(key); let result = zw_client.group_mms(vec![number], "Test Group MMS").await; eprintln!("Result: {:?}", result); assert!(result.is_ok()) } #[tokio::test] async fn send_bulk_mms() { let (key, number) = setup(); let zw_client = zipwhip_rs::Client::with_key(key); zw_client .bulk_mms(vec![number], "Test Bulk MMS") .await .iter() .for_each(|r| assert!(r.is_ok())) } #[tokio::test] async fn webhooks() { let (key, _number) = setup(); let zw_client = zipwhip_rs::Client::with_key(key); let add_result = zw_client .add_webhook(zipwhip_rs::WebhookEvent::Receive, "test.zipwhip.com") .await; eprintln!("Add Result: {:?}", add_result); assert!(add_result.is_ok()); let list_result = zw_client.list_webhooks().await; eprintln!("List Result: {:?}", list_result); assert!(list_result.is_ok()); let del_result = zw_client.remove_webhook(add_result.unwrap()).await; eprintln!("Delete Result: {:?}", del_result); assert!(del_result.is_ok()); }