#![allow(unused_imports)]
use crate::sdk::{self, types};
use crate::support;
#[tokio::test]
async fn reports_api_errors() {
let body = support::json(r#"{"code":"not_found","message":"No such resource.","details":{"field":"id"}}"#);
let reply = support::Reply::json(404, body).header("x-request-id", "req_test");
let api = support::MockApi::start(vec![reply]).await;
let error = api.client().me().await.unwrap_err();
assert!(matches!(error, sdk::Error::Api { .. }), "{error:?}");
assert_eq!(error.status(), Some(404));
assert_eq!(error.code(), "not_found");
assert_eq!(error.request_id(), Some("req_test"));
assert_eq!(error.details().and_then(|d| d.get("field")), Some(&"id".into()));
assert_eq!(error.to_string(), "No such resource. (404 not_found, request req_test)");
assert_eq!(api.calls().await.len(), 1);
}
#[tokio::test]
async fn me() {
let response = support::json(r#"{
"object": "auth_context",
"organization": {
"object": "organization",
"id": "id 1",
"name": "name 1"
},
"apiKey": {
"object": "api_key",
"id": "id 1",
"name": "name 1",
"projectId": "projectId 1",
"keyPrefix": "keyPrefix 1",
"last4": "last4 1",
"createdAt": "2026-09-24T09:00:00.000Z",
"lastUsedAt": "2026-09-24T09:00:00.000Z",
"revokedAt": "2026-09-24T09:00:00.000Z"
},
"project": {
"object": "project",
"id": "id 1",
"name": "name 1",
"externalId": "externalId 1",
"metadata": {
"key": "value 1"
},
"status": "active",
"maxAccounts": 1,
"accountCount": 1,
"createdAt": "2026-09-24T09:00:00.000Z",
"updatedAt": "2026-09-24T09:00:00.000Z"
}
}"#);
let api = support::MockApi::start(vec![support::Reply::json(200, response.clone())]).await;
let result = api.client().me().await.unwrap();
support::assert_json(&result, &response);
let calls = api.calls().await;
assert_eq!(calls.len(), 1);
assert_eq!(calls[0].method, "GET");
assert_eq!(calls[0].path, "/v1/me");
assert_eq!(calls[0].query, support::pairs(&[]));
assert!(calls[0].body.is_none());
assert!(calls[0].header(sdk::IDEMPOTENCY_HEADER).is_none());
}
mod accounts {
use super::*;
#[tokio::test]
async fn list_streams_every_page() {
let first = support::json(r#"{
"object": "list",
"items": [
{
"object": "account",
"id": "id 1",
"projectId": "projectId 1",
"name": "name 1",
"status": "initializing",
"reconnecting": true,
"phone": "phone 1",
"profileName": "profileName 1",
"proxyLocation": {
"country": "country 1",
"city": "city 1",
"strictCity": false
},
"qrCodeUrl": "qrCodeUrl 1",
"pairingCode": "pairingCode 1",
"pairingCodeExpiresAt": "2026-09-24T09:00:00.000Z",
"billable": true,
"disconnectReason": "disconnectReason 1",
"lastError": "lastError 1",
"rejectCalls": true,
"rejectCallsMessage": "rejectCallsMessage 1",
"pacing": {
"messagesPerMinute": 0,
"firstContactPerMinute": 0,
"typing": {
"enabled": true,
"minMs": 0,
"maxMs": 0,
"charsPerSecond": 5
},
"queueTimeoutMinutes": 1,
"custom": true
},
"historySync": "none",
"mediaAutoDownload": "none",
"imageQuality": "standard",
"metadata": {
"key": "value 1"
},
"linkedAt": "2026-09-24T09:00:00.000Z",
"lastConnectedAt": "2026-09-24T09:00:00.000Z",
"createdAt": "2026-09-24T09:00:00.000Z",
"updatedAt": "2026-09-24T09:00:00.000Z"
}
],
"nextCursor": "cursor_2"
}"#);
let last = support::json(r#"{
"object": "list",
"items": [
{
"object": "account",
"id": "id 1",
"projectId": "projectId 1",
"name": "name 1",
"status": "initializing",
"reconnecting": true,
"phone": "phone 1",
"profileName": "profileName 1",
"proxyLocation": {
"country": "country 1",
"city": "city 1",
"strictCity": false
},
"qrCodeUrl": "qrCodeUrl 1",
"pairingCode": "pairingCode 1",
"pairingCodeExpiresAt": "2026-09-24T09:00:00.000Z",
"billable": true,
"disconnectReason": "disconnectReason 1",
"lastError": "lastError 1",
"rejectCalls": true,
"rejectCallsMessage": "rejectCallsMessage 1",
"pacing": {
"messagesPerMinute": 0,
"firstContactPerMinute": 0,
"typing": {
"enabled": true,
"minMs": 0,
"maxMs": 0,
"charsPerSecond": 5
},
"queueTimeoutMinutes": 1,
"custom": true
},
"historySync": "none",
"mediaAutoDownload": "none",
"imageQuality": "standard",
"metadata": {
"key": "value 1"
},
"linkedAt": "2026-09-24T09:00:00.000Z",
"lastConnectedAt": "2026-09-24T09:00:00.000Z",
"createdAt": "2026-09-24T09:00:00.000Z",
"updatedAt": "2026-09-24T09:00:00.000Z"
}
],
"nextCursor": null
}"#);
let api = support::MockApi::start(vec![
support::Reply::json(200, first),
support::Reply::json(200, last),
])
.await;
let params: types::AccountsListParams = support::from_json(r#"{"limit":50,"cursor":"cursor 1","projectId":"ext:customer_8812"}"#);
let items = api.client().accounts().list(params).to_vec().await.unwrap();
support::assert_json(&items, &support::json(r#"[
{
"object": "account",
"id": "id 1",
"projectId": "projectId 1",
"name": "name 1",
"status": "initializing",
"reconnecting": true,
"phone": "phone 1",
"profileName": "profileName 1",
"proxyLocation": {
"country": "country 1",
"city": "city 1",
"strictCity": false
},
"qrCodeUrl": "qrCodeUrl 1",
"pairingCode": "pairingCode 1",
"pairingCodeExpiresAt": "2026-09-24T09:00:00.000Z",
"billable": true,
"disconnectReason": "disconnectReason 1",
"lastError": "lastError 1",
"rejectCalls": true,
"rejectCallsMessage": "rejectCallsMessage 1",
"pacing": {
"messagesPerMinute": 0,
"firstContactPerMinute": 0,
"typing": {
"enabled": true,
"minMs": 0,
"maxMs": 0,
"charsPerSecond": 5
},
"queueTimeoutMinutes": 1,
"custom": true
},
"historySync": "none",
"mediaAutoDownload": "none",
"imageQuality": "standard",
"metadata": {
"key": "value 1"
},
"linkedAt": "2026-09-24T09:00:00.000Z",
"lastConnectedAt": "2026-09-24T09:00:00.000Z",
"createdAt": "2026-09-24T09:00:00.000Z",
"updatedAt": "2026-09-24T09:00:00.000Z"
},
{
"object": "account",
"id": "id 1",
"projectId": "projectId 1",
"name": "name 1",
"status": "initializing",
"reconnecting": true,
"phone": "phone 1",
"profileName": "profileName 1",
"proxyLocation": {
"country": "country 1",
"city": "city 1",
"strictCity": false
},
"qrCodeUrl": "qrCodeUrl 1",
"pairingCode": "pairingCode 1",
"pairingCodeExpiresAt": "2026-09-24T09:00:00.000Z",
"billable": true,
"disconnectReason": "disconnectReason 1",
"lastError": "lastError 1",
"rejectCalls": true,
"rejectCallsMessage": "rejectCallsMessage 1",
"pacing": {
"messagesPerMinute": 0,
"firstContactPerMinute": 0,
"typing": {
"enabled": true,
"minMs": 0,
"maxMs": 0,
"charsPerSecond": 5
},
"queueTimeoutMinutes": 1,
"custom": true
},
"historySync": "none",
"mediaAutoDownload": "none",
"imageQuality": "standard",
"metadata": {
"key": "value 1"
},
"linkedAt": "2026-09-24T09:00:00.000Z",
"lastConnectedAt": "2026-09-24T09:00:00.000Z",
"createdAt": "2026-09-24T09:00:00.000Z",
"updatedAt": "2026-09-24T09:00:00.000Z"
}
]"#));
let calls = api.calls().await;
assert_eq!(calls.len(), 2);
assert_eq!(calls[0].method, "GET");
assert_eq!(calls[0].path, "/v1/accounts");
assert_eq!(calls[0].query, support::pairs(&[("limit", "50"), ("projectId", "ext:customer_8812"), ("cursor", "cursor 1")]));
assert_eq!(calls[1].query, support::pairs(&[("limit", "50"), ("projectId", "ext:customer_8812"), ("cursor", "cursor_2")]));
}
#[tokio::test]
async fn list_fetches_one_page() {
let page = support::json(r#"{
"object": "list",
"items": [
{
"object": "account",
"id": "id 1",
"projectId": "projectId 1",
"name": "name 1",
"status": "initializing",
"reconnecting": true,
"phone": "phone 1",
"profileName": "profileName 1",
"proxyLocation": {
"country": "country 1",
"city": "city 1",
"strictCity": false
},
"qrCodeUrl": "qrCodeUrl 1",
"pairingCode": "pairingCode 1",
"pairingCodeExpiresAt": "2026-09-24T09:00:00.000Z",
"billable": true,
"disconnectReason": "disconnectReason 1",
"lastError": "lastError 1",
"rejectCalls": true,
"rejectCallsMessage": "rejectCallsMessage 1",
"pacing": {
"messagesPerMinute": 0,
"firstContactPerMinute": 0,
"typing": {
"enabled": true,
"minMs": 0,
"maxMs": 0,
"charsPerSecond": 5
},
"queueTimeoutMinutes": 1,
"custom": true
},
"historySync": "none",
"mediaAutoDownload": "none",
"imageQuality": "standard",
"metadata": {
"key": "value 1"
},
"linkedAt": "2026-09-24T09:00:00.000Z",
"lastConnectedAt": "2026-09-24T09:00:00.000Z",
"createdAt": "2026-09-24T09:00:00.000Z",
"updatedAt": "2026-09-24T09:00:00.000Z"
}
],
"nextCursor": null
}"#);
let api = support::MockApi::start(vec![support::Reply::json(200, page.clone())]).await;
let result = api.client().accounts().list(Default::default()).page().await.unwrap();
support::assert_json(&result, &page);
let calls = api.calls().await;
assert_eq!(calls.len(), 1);
assert_eq!(calls[0].method, "GET");
assert_eq!(calls[0].path, "/v1/accounts");
assert_eq!(calls[0].query, support::pairs(&[]));
}
#[tokio::test]
async fn create() {
let response = support::json(r#"{
"object": "account",
"id": "id 1",
"projectId": "projectId 1",
"name": "name 1",
"status": "initializing",
"reconnecting": true,
"phone": "phone 1",
"profileName": "profileName 1",
"proxyLocation": {
"country": "country 1",
"city": "city 1",
"strictCity": false
},
"qrCodeUrl": "qrCodeUrl 1",
"pairingCode": "pairingCode 1",
"pairingCodeExpiresAt": "2026-09-24T09:00:00.000Z",
"billable": true,
"disconnectReason": "disconnectReason 1",
"lastError": "lastError 1",
"rejectCalls": true,
"rejectCallsMessage": "rejectCallsMessage 1",
"pacing": {
"messagesPerMinute": 0,
"firstContactPerMinute": 0,
"typing": {
"enabled": true,
"minMs": 0,
"maxMs": 0,
"charsPerSecond": 5
},
"queueTimeoutMinutes": 1,
"custom": true
},
"historySync": "none",
"mediaAutoDownload": "none",
"imageQuality": "standard",
"metadata": {
"key": "value 1"
},
"linkedAt": "2026-09-24T09:00:00.000Z",
"lastConnectedAt": "2026-09-24T09:00:00.000Z",
"createdAt": "2026-09-24T09:00:00.000Z",
"updatedAt": "2026-09-24T09:00:00.000Z"
}"#);
let api = support::MockApi::start(vec![support::Reply::json(201, response.clone())]).await;
let params: types::AccountsCreateParams = support::from_json(r#"{
"name": "name 1",
"proxyLocation": {
"country": "country 1",
"city": "city 1",
"strictCity": false
},
"pairingPhone": "pairingPhone 1",
"projectId": "projectId 1",
"historySync": "none"
}"#);
let result = api.client().accounts().create(params).await.unwrap();
support::assert_json(&result, &response);
let calls = api.calls().await;
assert_eq!(calls.len(), 1);
assert_eq!(calls[0].method, "POST");
assert_eq!(calls[0].path, "/v1/accounts");
assert_eq!(calls[0].query, support::pairs(&[]));
support::assert_json(&calls[0].body, &support::json(r#"{
"name": "name 1",
"proxyLocation": {
"country": "country 1",
"city": "city 1",
"strictCity": false
},
"pairingPhone": "pairingPhone 1",
"projectId": "projectId 1",
"historySync": "none"
}"#));
assert!(calls[0].header(sdk::IDEMPOTENCY_HEADER).is_some_and(|key| !key.is_empty()));
}
#[tokio::test]
async fn create_retries_with_one_key() {
let response = support::json(r#"{
"object": "account",
"id": "id 1",
"projectId": "projectId 1",
"name": "name 1",
"status": "initializing",
"reconnecting": true,
"phone": "phone 1",
"profileName": "profileName 1",
"proxyLocation": {
"country": "country 1",
"city": "city 1",
"strictCity": false
},
"qrCodeUrl": "qrCodeUrl 1",
"pairingCode": "pairingCode 1",
"pairingCodeExpiresAt": "2026-09-24T09:00:00.000Z",
"billable": true,
"disconnectReason": "disconnectReason 1",
"lastError": "lastError 1",
"rejectCalls": true,
"rejectCallsMessage": "rejectCallsMessage 1",
"pacing": {
"messagesPerMinute": 0,
"firstContactPerMinute": 0,
"typing": {
"enabled": true,
"minMs": 0,
"maxMs": 0,
"charsPerSecond": 5
},
"queueTimeoutMinutes": 1,
"custom": true
},
"historySync": "none",
"mediaAutoDownload": "none",
"imageQuality": "standard",
"metadata": {
"key": "value 1"
},
"linkedAt": "2026-09-24T09:00:00.000Z",
"lastConnectedAt": "2026-09-24T09:00:00.000Z",
"createdAt": "2026-09-24T09:00:00.000Z",
"updatedAt": "2026-09-24T09:00:00.000Z"
}"#);
let api = support::MockApi::start(vec![support::Reply::status(503), support::Reply::json(201, response.clone())]).await;
let params: types::AccountsCreateParams = support::from_json(r#"{
"name": "name 1",
"proxyLocation": {
"country": "country 1",
"city": "city 1",
"strictCity": false
},
"pairingPhone": "pairingPhone 1",
"projectId": "projectId 1",
"historySync": "none"
}"#);
let result = api.client().accounts().create(params).await.unwrap();
support::assert_json(&result, &response);
let calls = api.calls().await;
assert_eq!(calls.len(), 2);
let key = calls[0].header(sdk::IDEMPOTENCY_HEADER).unwrap();
assert!(!key.is_empty());
assert_eq!(calls[1].header(sdk::IDEMPOTENCY_HEADER), Some(key));
assert_eq!(calls[0].body, calls[1].body);
}
#[tokio::test]
async fn get() {
let response = support::json(r#"{
"object": "account",
"id": "id 1",
"projectId": "projectId 1",
"name": "name 1",
"status": "initializing",
"reconnecting": true,
"phone": "phone 1",
"profileName": "profileName 1",
"proxyLocation": {
"country": "country 1",
"city": "city 1",
"strictCity": false
},
"qrCodeUrl": "qrCodeUrl 1",
"pairingCode": "pairingCode 1",
"pairingCodeExpiresAt": "2026-09-24T09:00:00.000Z",
"billable": true,
"disconnectReason": "disconnectReason 1",
"lastError": "lastError 1",
"rejectCalls": true,
"rejectCallsMessage": "rejectCallsMessage 1",
"pacing": {
"messagesPerMinute": 0,
"firstContactPerMinute": 0,
"typing": {
"enabled": true,
"minMs": 0,
"maxMs": 0,
"charsPerSecond": 5
},
"queueTimeoutMinutes": 1,
"custom": true
},
"historySync": "none",
"mediaAutoDownload": "none",
"imageQuality": "standard",
"metadata": {
"key": "value 1"
},
"linkedAt": "2026-09-24T09:00:00.000Z",
"lastConnectedAt": "2026-09-24T09:00:00.000Z",
"createdAt": "2026-09-24T09:00:00.000Z",
"updatedAt": "2026-09-24T09:00:00.000Z"
}"#);
let api = support::MockApi::start(vec![support::Reply::json(200, response.clone())]).await;
let result = api.client().accounts().get("k57a8m2x9d3f0q1wjh6ypc4n2d7s0vbr").await.unwrap();
support::assert_json(&result, &response);
let calls = api.calls().await;
assert_eq!(calls.len(), 1);
assert_eq!(calls[0].method, "GET");
assert_eq!(calls[0].path, "/v1/accounts/k57a8m2x9d3f0q1wjh6ypc4n2d7s0vbr");
assert_eq!(calls[0].query, support::pairs(&[]));
assert!(calls[0].body.is_none());
assert!(calls[0].header(sdk::IDEMPOTENCY_HEADER).is_none());
}
#[tokio::test]
async fn update() {
let response = support::json(r#"{
"object": "account",
"id": "id 1",
"projectId": "projectId 1",
"name": "name 1",
"status": "initializing",
"reconnecting": true,
"phone": "phone 1",
"profileName": "profileName 1",
"proxyLocation": {
"country": "country 1",
"city": "city 1",
"strictCity": false
},
"qrCodeUrl": "qrCodeUrl 1",
"pairingCode": "pairingCode 1",
"pairingCodeExpiresAt": "2026-09-24T09:00:00.000Z",
"billable": true,
"disconnectReason": "disconnectReason 1",
"lastError": "lastError 1",
"rejectCalls": true,
"rejectCallsMessage": "rejectCallsMessage 1",
"pacing": {
"messagesPerMinute": 0,
"firstContactPerMinute": 0,
"typing": {
"enabled": true,
"minMs": 0,
"maxMs": 0,
"charsPerSecond": 5
},
"queueTimeoutMinutes": 1,
"custom": true
},
"historySync": "none",
"mediaAutoDownload": "none",
"imageQuality": "standard",
"metadata": {
"key": "value 1"
},
"linkedAt": "2026-09-24T09:00:00.000Z",
"lastConnectedAt": "2026-09-24T09:00:00.000Z",
"createdAt": "2026-09-24T09:00:00.000Z",
"updatedAt": "2026-09-24T09:00:00.000Z"
}"#);
let api = support::MockApi::start(vec![support::Reply::json(200, response.clone())]).await;
let params: types::AccountsUpdateParams = support::from_json(r#"{
"name": "name 1",
"rejectCalls": true,
"rejectCallsMessage": "rejectCallsMessage 1",
"pacing": {
"messagesPerMinute": 0,
"firstContactPerMinute": 0,
"typing": {
"enabled": true,
"minMs": 0,
"maxMs": 0,
"charsPerSecond": 5
},
"queueTimeoutMinutes": 1
},
"historySync": "none",
"mediaAutoDownload": "none",
"imageQuality": "standard",
"proxyLocation": {
"country": "country 1",
"city": "city 1",
"strictCity": false
}
}"#);
let result = api.client().accounts().update("k57a8m2x9d3f0q1wjh6ypc4n2d7s0vbr", params).await.unwrap();
support::assert_json(&result, &response);
let calls = api.calls().await;
assert_eq!(calls.len(), 1);
assert_eq!(calls[0].method, "PATCH");
assert_eq!(calls[0].path, "/v1/accounts/k57a8m2x9d3f0q1wjh6ypc4n2d7s0vbr");
assert_eq!(calls[0].query, support::pairs(&[]));
support::assert_json(&calls[0].body, &support::json(r#"{
"name": "name 1",
"rejectCalls": true,
"rejectCallsMessage": "rejectCallsMessage 1",
"pacing": {
"messagesPerMinute": 0,
"firstContactPerMinute": 0,
"typing": {
"enabled": true,
"minMs": 0,
"maxMs": 0,
"charsPerSecond": 5
},
"queueTimeoutMinutes": 1
},
"historySync": "none",
"mediaAutoDownload": "none",
"imageQuality": "standard",
"proxyLocation": {
"country": "country 1",
"city": "city 1",
"strictCity": false
}
}"#));
assert!(calls[0].header(sdk::IDEMPOTENCY_HEADER).is_none());
}
#[tokio::test]
async fn update_without_params() {
let response = support::json(r#"{
"object": "account",
"id": "id 1",
"projectId": "projectId 1",
"name": "name 1",
"status": "initializing",
"reconnecting": true,
"phone": "phone 1",
"profileName": "profileName 1",
"proxyLocation": {
"country": "country 1",
"city": "city 1",
"strictCity": false
},
"qrCodeUrl": "qrCodeUrl 1",
"pairingCode": "pairingCode 1",
"pairingCodeExpiresAt": "2026-09-24T09:00:00.000Z",
"billable": true,
"disconnectReason": "disconnectReason 1",
"lastError": "lastError 1",
"rejectCalls": true,
"rejectCallsMessage": "rejectCallsMessage 1",
"pacing": {
"messagesPerMinute": 0,
"firstContactPerMinute": 0,
"typing": {
"enabled": true,
"minMs": 0,
"maxMs": 0,
"charsPerSecond": 5
},
"queueTimeoutMinutes": 1,
"custom": true
},
"historySync": "none",
"mediaAutoDownload": "none",
"imageQuality": "standard",
"metadata": {
"key": "value 1"
},
"linkedAt": "2026-09-24T09:00:00.000Z",
"lastConnectedAt": "2026-09-24T09:00:00.000Z",
"createdAt": "2026-09-24T09:00:00.000Z",
"updatedAt": "2026-09-24T09:00:00.000Z"
}"#);
let api = support::MockApi::start(vec![support::Reply::json(200, response.clone())]).await;
let result = api.client().accounts().update("k57a8m2x9d3f0q1wjh6ypc4n2d7s0vbr", Default::default()).await.unwrap();
support::assert_json(&result, &response);
let calls = api.calls().await;
assert_eq!(calls.len(), 1);
assert_eq!(calls[0].method, "PATCH");
assert_eq!(calls[0].path, "/v1/accounts/k57a8m2x9d3f0q1wjh6ypc4n2d7s0vbr");
assert_eq!(calls[0].query, support::pairs(&[]));
support::assert_json(&calls[0].body, &support::json(r#"{}"#));
assert!(calls[0].header(sdk::IDEMPOTENCY_HEADER).is_none());
}
#[tokio::test]
async fn update_is_not_repeated() {
let api = support::MockApi::start(vec![
support::Reply::status(503),
support::Reply::status(503),
])
.await;
let params: types::AccountsUpdateParams = support::from_json(r#"{
"name": "name 1",
"rejectCalls": true,
"rejectCallsMessage": "rejectCallsMessage 1",
"pacing": {
"messagesPerMinute": 0,
"firstContactPerMinute": 0,
"typing": {
"enabled": true,
"minMs": 0,
"maxMs": 0,
"charsPerSecond": 5
},
"queueTimeoutMinutes": 1
},
"historySync": "none",
"mediaAutoDownload": "none",
"imageQuality": "standard",
"proxyLocation": {
"country": "country 1",
"city": "city 1",
"strictCity": false
}
}"#);
let error = api.client().accounts().update("k57a8m2x9d3f0q1wjh6ypc4n2d7s0vbr", params).await.unwrap_err();
assert_eq!(error.status(), Some(503));
assert_eq!(api.calls().await.len(), 1);
}
#[tokio::test]
async fn delete() {
let api = support::MockApi::start(vec![support::Reply::status(204)]).await;
api.client().accounts().delete("k57a8m2x9d3f0q1wjh6ypc4n2d7s0vbr").await.unwrap();
let calls = api.calls().await;
assert_eq!(calls.len(), 1);
assert_eq!(calls[0].method, "DELETE");
assert_eq!(calls[0].path, "/v1/accounts/k57a8m2x9d3f0q1wjh6ypc4n2d7s0vbr");
assert_eq!(calls[0].query, support::pairs(&[]));
assert!(calls[0].body.is_none());
assert!(calls[0].header(sdk::IDEMPOTENCY_HEADER).is_none());
}
#[tokio::test]
async fn reconnect() {
let response = support::json(r#"{
"object": "account",
"id": "id 1",
"projectId": "projectId 1",
"name": "name 1",
"status": "initializing",
"reconnecting": true,
"phone": "phone 1",
"profileName": "profileName 1",
"proxyLocation": {
"country": "country 1",
"city": "city 1",
"strictCity": false
},
"qrCodeUrl": "qrCodeUrl 1",
"pairingCode": "pairingCode 1",
"pairingCodeExpiresAt": "2026-09-24T09:00:00.000Z",
"billable": true,
"disconnectReason": "disconnectReason 1",
"lastError": "lastError 1",
"rejectCalls": true,
"rejectCallsMessage": "rejectCallsMessage 1",
"pacing": {
"messagesPerMinute": 0,
"firstContactPerMinute": 0,
"typing": {
"enabled": true,
"minMs": 0,
"maxMs": 0,
"charsPerSecond": 5
},
"queueTimeoutMinutes": 1,
"custom": true
},
"historySync": "none",
"mediaAutoDownload": "none",
"imageQuality": "standard",
"metadata": {
"key": "value 1"
},
"linkedAt": "2026-09-24T09:00:00.000Z",
"lastConnectedAt": "2026-09-24T09:00:00.000Z",
"createdAt": "2026-09-24T09:00:00.000Z",
"updatedAt": "2026-09-24T09:00:00.000Z"
}"#);
let api = support::MockApi::start(vec![support::Reply::json(202, response.clone())]).await;
let result = api.client().accounts().reconnect("k57a8m2x9d3f0q1wjh6ypc4n2d7s0vbr").await.unwrap();
support::assert_json(&result, &response);
let calls = api.calls().await;
assert_eq!(calls.len(), 1);
assert_eq!(calls[0].method, "POST");
assert_eq!(calls[0].path, "/v1/accounts/k57a8m2x9d3f0q1wjh6ypc4n2d7s0vbr/reconnect");
assert_eq!(calls[0].query, support::pairs(&[]));
assert!(calls[0].body.is_none());
assert!(calls[0].header(sdk::IDEMPOTENCY_HEADER).is_some_and(|key| !key.is_empty()));
}
#[tokio::test]
async fn reconnect_retries_with_one_key() {
let response = support::json(r#"{
"object": "account",
"id": "id 1",
"projectId": "projectId 1",
"name": "name 1",
"status": "initializing",
"reconnecting": true,
"phone": "phone 1",
"profileName": "profileName 1",
"proxyLocation": {
"country": "country 1",
"city": "city 1",
"strictCity": false
},
"qrCodeUrl": "qrCodeUrl 1",
"pairingCode": "pairingCode 1",
"pairingCodeExpiresAt": "2026-09-24T09:00:00.000Z",
"billable": true,
"disconnectReason": "disconnectReason 1",
"lastError": "lastError 1",
"rejectCalls": true,
"rejectCallsMessage": "rejectCallsMessage 1",
"pacing": {
"messagesPerMinute": 0,
"firstContactPerMinute": 0,
"typing": {
"enabled": true,
"minMs": 0,
"maxMs": 0,
"charsPerSecond": 5
},
"queueTimeoutMinutes": 1,
"custom": true
},
"historySync": "none",
"mediaAutoDownload": "none",
"imageQuality": "standard",
"metadata": {
"key": "value 1"
},
"linkedAt": "2026-09-24T09:00:00.000Z",
"lastConnectedAt": "2026-09-24T09:00:00.000Z",
"createdAt": "2026-09-24T09:00:00.000Z",
"updatedAt": "2026-09-24T09:00:00.000Z"
}"#);
let api = support::MockApi::start(vec![support::Reply::status(503), support::Reply::json(202, response.clone())]).await;
let result = api.client().accounts().reconnect("k57a8m2x9d3f0q1wjh6ypc4n2d7s0vbr").await.unwrap();
support::assert_json(&result, &response);
let calls = api.calls().await;
assert_eq!(calls.len(), 2);
let key = calls[0].header(sdk::IDEMPOTENCY_HEADER).unwrap();
assert!(!key.is_empty());
assert_eq!(calls[1].header(sdk::IDEMPOTENCY_HEADER), Some(key));
assert_eq!(calls[0].body, calls[1].body);
}
#[tokio::test]
async fn logout() {
let response = support::json(r#"{
"object": "account",
"id": "id 1",
"projectId": "projectId 1",
"name": "name 1",
"status": "initializing",
"reconnecting": true,
"phone": "phone 1",
"profileName": "profileName 1",
"proxyLocation": {
"country": "country 1",
"city": "city 1",
"strictCity": false
},
"qrCodeUrl": "qrCodeUrl 1",
"pairingCode": "pairingCode 1",
"pairingCodeExpiresAt": "2026-09-24T09:00:00.000Z",
"billable": true,
"disconnectReason": "disconnectReason 1",
"lastError": "lastError 1",
"rejectCalls": true,
"rejectCallsMessage": "rejectCallsMessage 1",
"pacing": {
"messagesPerMinute": 0,
"firstContactPerMinute": 0,
"typing": {
"enabled": true,
"minMs": 0,
"maxMs": 0,
"charsPerSecond": 5
},
"queueTimeoutMinutes": 1,
"custom": true
},
"historySync": "none",
"mediaAutoDownload": "none",
"imageQuality": "standard",
"metadata": {
"key": "value 1"
},
"linkedAt": "2026-09-24T09:00:00.000Z",
"lastConnectedAt": "2026-09-24T09:00:00.000Z",
"createdAt": "2026-09-24T09:00:00.000Z",
"updatedAt": "2026-09-24T09:00:00.000Z"
}"#);
let api = support::MockApi::start(vec![support::Reply::json(202, response.clone())]).await;
let result = api.client().accounts().logout("k57a8m2x9d3f0q1wjh6ypc4n2d7s0vbr").await.unwrap();
support::assert_json(&result, &response);
let calls = api.calls().await;
assert_eq!(calls.len(), 1);
assert_eq!(calls[0].method, "POST");
assert_eq!(calls[0].path, "/v1/accounts/k57a8m2x9d3f0q1wjh6ypc4n2d7s0vbr/logout");
assert_eq!(calls[0].query, support::pairs(&[]));
assert!(calls[0].body.is_none());
assert!(calls[0].header(sdk::IDEMPOTENCY_HEADER).is_some_and(|key| !key.is_empty()));
}
#[tokio::test]
async fn logout_retries_with_one_key() {
let response = support::json(r#"{
"object": "account",
"id": "id 1",
"projectId": "projectId 1",
"name": "name 1",
"status": "initializing",
"reconnecting": true,
"phone": "phone 1",
"profileName": "profileName 1",
"proxyLocation": {
"country": "country 1",
"city": "city 1",
"strictCity": false
},
"qrCodeUrl": "qrCodeUrl 1",
"pairingCode": "pairingCode 1",
"pairingCodeExpiresAt": "2026-09-24T09:00:00.000Z",
"billable": true,
"disconnectReason": "disconnectReason 1",
"lastError": "lastError 1",
"rejectCalls": true,
"rejectCallsMessage": "rejectCallsMessage 1",
"pacing": {
"messagesPerMinute": 0,
"firstContactPerMinute": 0,
"typing": {
"enabled": true,
"minMs": 0,
"maxMs": 0,
"charsPerSecond": 5
},
"queueTimeoutMinutes": 1,
"custom": true
},
"historySync": "none",
"mediaAutoDownload": "none",
"imageQuality": "standard",
"metadata": {
"key": "value 1"
},
"linkedAt": "2026-09-24T09:00:00.000Z",
"lastConnectedAt": "2026-09-24T09:00:00.000Z",
"createdAt": "2026-09-24T09:00:00.000Z",
"updatedAt": "2026-09-24T09:00:00.000Z"
}"#);
let api = support::MockApi::start(vec![support::Reply::status(503), support::Reply::json(202, response.clone())]).await;
let result = api.client().accounts().logout("k57a8m2x9d3f0q1wjh6ypc4n2d7s0vbr").await.unwrap();
support::assert_json(&result, &response);
let calls = api.calls().await;
assert_eq!(calls.len(), 2);
let key = calls[0].header(sdk::IDEMPOTENCY_HEADER).unwrap();
assert!(!key.is_empty());
assert_eq!(calls[1].header(sdk::IDEMPOTENCY_HEADER), Some(key));
assert_eq!(calls[0].body, calls[1].body);
}
#[tokio::test]
async fn create_pairing_code() {
let response = support::json(r#"{
"object": "pairing_code",
"accountId": "accountId 1",
"code": "code 1",
"expiresAt": "2026-09-24T09:00:00.000Z"
}"#);
let api = support::MockApi::start(vec![support::Reply::json(201, response.clone())]).await;
let params: types::AccountsCreatePairingCodeParams = support::from_json(r#"{"phone":"phone 1"}"#);
let result = api.client().accounts().create_pairing_code("k57a8m2x9d3f0q1wjh6ypc4n2d7s0vbr", params).await.unwrap();
support::assert_json(&result, &response);
let calls = api.calls().await;
assert_eq!(calls.len(), 1);
assert_eq!(calls[0].method, "POST");
assert_eq!(calls[0].path, "/v1/accounts/k57a8m2x9d3f0q1wjh6ypc4n2d7s0vbr/pairing-code");
assert_eq!(calls[0].query, support::pairs(&[]));
support::assert_json(&calls[0].body, &support::json(r#"{"phone":"phone 1"}"#));
assert!(calls[0].header(sdk::IDEMPOTENCY_HEADER).is_some_and(|key| !key.is_empty()));
}
#[tokio::test]
async fn create_pairing_code_retries_with_one_key() {
let response = support::json(r#"{
"object": "pairing_code",
"accountId": "accountId 1",
"code": "code 1",
"expiresAt": "2026-09-24T09:00:00.000Z"
}"#);
let api = support::MockApi::start(vec![support::Reply::status(503), support::Reply::json(201, response.clone())]).await;
let params: types::AccountsCreatePairingCodeParams = support::from_json(r#"{"phone":"phone 1"}"#);
let result = api.client().accounts().create_pairing_code("k57a8m2x9d3f0q1wjh6ypc4n2d7s0vbr", params).await.unwrap();
support::assert_json(&result, &response);
let calls = api.calls().await;
assert_eq!(calls.len(), 2);
let key = calls[0].header(sdk::IDEMPOTENCY_HEADER).unwrap();
assert!(!key.is_empty());
assert_eq!(calls[1].header(sdk::IDEMPOTENCY_HEADER), Some(key));
assert_eq!(calls[0].body, calls[1].body);
}
#[tokio::test]
async fn set_presence() {
let api = support::MockApi::start(vec![support::Reply::status(204)]).await;
let params: types::AccountsSetPresenceParams = support::from_json(r#"{"state":"online"}"#);
api.client().accounts().set_presence("k57a8m2x9d3f0q1wjh6ypc4n2d7s0vbr", params).await.unwrap();
let calls = api.calls().await;
assert_eq!(calls.len(), 1);
assert_eq!(calls[0].method, "POST");
assert_eq!(calls[0].path, "/v1/accounts/k57a8m2x9d3f0q1wjh6ypc4n2d7s0vbr/presence");
assert_eq!(calls[0].query, support::pairs(&[]));
support::assert_json(&calls[0].body, &support::json(r#"{"state":"online"}"#));
assert!(calls[0].header(sdk::IDEMPOTENCY_HEADER).is_some_and(|key| !key.is_empty()));
}
#[tokio::test]
async fn set_presence_retries_with_one_key() {
let api = support::MockApi::start(vec![support::Reply::status(503), support::Reply::status(204)]).await;
let params: types::AccountsSetPresenceParams = support::from_json(r#"{"state":"online"}"#);
api.client().accounts().set_presence("k57a8m2x9d3f0q1wjh6ypc4n2d7s0vbr", params).await.unwrap();
let calls = api.calls().await;
assert_eq!(calls.len(), 2);
let key = calls[0].header(sdk::IDEMPOTENCY_HEADER).unwrap();
assert!(!key.is_empty());
assert_eq!(calls[1].header(sdk::IDEMPOTENCY_HEADER), Some(key));
assert_eq!(calls[0].body, calls[1].body);
}
#[tokio::test]
async fn set_default_disappearing_timer() {
let api = support::MockApi::start(vec![support::Reply::status(204)]).await;
let params: types::AccountsSetDefaultDisappearingTimerParams = support::from_json(r#"{"durationSeconds":0}"#);
api.client().accounts().set_default_disappearing_timer("k57a8m2x9d3f0q1wjh6ypc4n2d7s0vbr", params).await.unwrap();
let calls = api.calls().await;
assert_eq!(calls.len(), 1);
assert_eq!(calls[0].method, "PUT");
assert_eq!(calls[0].path, "/v1/accounts/k57a8m2x9d3f0q1wjh6ypc4n2d7s0vbr/disappearing-timer");
assert_eq!(calls[0].query, support::pairs(&[]));
support::assert_json(&calls[0].body, &support::json(r#"{"durationSeconds":0}"#));
assert!(calls[0].header(sdk::IDEMPOTENCY_HEADER).is_none());
}
}
mod proxy_locations {
use super::*;
#[tokio::test]
async fn list_streams_every_page() {
let first = support::json(r#"{
"object": "list",
"items": [
{
"object": "proxy_location",
"country": "country 1",
"countryName": "countryName 1",
"city": "city 1",
"cityName": "cityName 1"
}
],
"nextCursor": "cursor_2"
}"#);
let last = support::json(r#"{
"object": "list",
"items": [
{
"object": "proxy_location",
"country": "country 1",
"countryName": "countryName 1",
"city": "city 1",
"cityName": "cityName 1"
}
],
"nextCursor": null
}"#);
let api = support::MockApi::start(vec![
support::Reply::json(200, first),
support::Reply::json(200, last),
])
.await;
let params: types::ProxyLocationsListParams = support::from_json(r#"{"country":"CL","q":"bogo","limit":50,"cursor":"cursor 1"}"#);
let items = api.client().proxy_locations().list(params).to_vec().await.unwrap();
support::assert_json(&items, &support::json(r#"[
{
"object": "proxy_location",
"country": "country 1",
"countryName": "countryName 1",
"city": "city 1",
"cityName": "cityName 1"
},
{
"object": "proxy_location",
"country": "country 1",
"countryName": "countryName 1",
"city": "city 1",
"cityName": "cityName 1"
}
]"#));
let calls = api.calls().await;
assert_eq!(calls.len(), 2);
assert_eq!(calls[0].method, "GET");
assert_eq!(calls[0].path, "/v1/proxy-locations");
assert_eq!(calls[0].query, support::pairs(&[("country", "CL"), ("q", "bogo"), ("limit", "50"), ("cursor", "cursor 1")]));
assert_eq!(calls[1].query, support::pairs(&[("country", "CL"), ("q", "bogo"), ("limit", "50"), ("cursor", "cursor_2")]));
}
#[tokio::test]
async fn list_fetches_one_page() {
let page = support::json(r#"{
"object": "list",
"items": [
{
"object": "proxy_location",
"country": "country 1",
"countryName": "countryName 1",
"city": "city 1",
"cityName": "cityName 1"
}
],
"nextCursor": null
}"#);
let api = support::MockApi::start(vec![support::Reply::json(200, page.clone())]).await;
let result = api.client().proxy_locations().list(Default::default()).page().await.unwrap();
support::assert_json(&result, &page);
let calls = api.calls().await;
assert_eq!(calls.len(), 1);
assert_eq!(calls[0].method, "GET");
assert_eq!(calls[0].path, "/v1/proxy-locations");
assert_eq!(calls[0].query, support::pairs(&[]));
}
}
mod messages {
use super::*;
#[tokio::test]
async fn send() {
let response = support::json(r#"{
"object": "message",
"id": "id 1",
"projectId": "projectId 1",
"accountId": "accountId 1",
"chatId": "chatId 1",
"chatType": "direct",
"direction": "inbound",
"source": "api",
"from": "from 1",
"to": "to 1",
"profileName": "profileName 1",
"username": "username 1",
"type": "text",
"text": "text 1",
"media": {
"url": "url 1",
"mimeType": "mimeType 1",
"filename": "filename 1",
"size": 1,
"width": 1,
"height": 1,
"durationSeconds": 1,
"gifPlayback": true,
"downloaded": true
},
"location": {
"latitude": 1.5,
"longitude": 1.5,
"name": "name 1",
"address": "address 1"
},
"contact": {
"name": "name 1",
"phone": "phone 1"
},
"contacts": [
{
"name": "name 1",
"phone": "phone 1"
}
],
"poll": {
"name": "name 1",
"options": [
{
"name": "name 1",
"voteCount": 1
}
],
"selectableCount": 1,
"voterCount": 1
},
"calendarEvent": {
"name": "name 1",
"description": "description 1",
"startsAt": "2026-09-24T09:00:00.000Z",
"endsAt": "2026-09-24T09:00:00.000Z",
"location": {
"name": "name 1",
"address": "address 1",
"latitude": 1.5,
"longitude": 1.5
},
"callType": "audio",
"joinUrl": "joinUrl 1",
"allowExtraGuests": true,
"cancelled": true
},
"mentions": [
"mentions 1"
],
"forwarded": true,
"forwardedManyTimes": true,
"viewOnce": true,
"starred": true,
"replyToMessageId": "replyToMessageId 1",
"replyToStoryId": "replyToStoryId 1",
"status": "queued",
"error": {
"code": "not_on_whatsapp",
"message": "message 1"
},
"metadata": {
"key": "value 1"
},
"sentAt": "2026-09-24T09:00:00.000Z",
"editedAt": "2026-09-24T09:00:00.000Z",
"deletedAt": "2026-09-24T09:00:00.000Z",
"createdAt": "2026-09-24T09:00:00.000Z",
"updatedAt": "2026-09-24T09:00:00.000Z"
}"#);
let api = support::MockApi::start(vec![support::Reply::json(202, response.clone())]).await;
let params: types::MessagesSendParams = support::from_json(r#"{
"accountId": "accountId 1",
"to": "to 1",
"type": "text",
"text": "text 1",
"mentions": [
"mentions 1"
],
"mentionAll": true,
"forwarded": true,
"disappearingSeconds": 0,
"linkPreview": {
"url": "https://example.com/url",
"title": "title 1",
"description": "description 1",
"thumbnailBase64": "thumbnailBase64 1"
},
"replyToMessageId": "replyToMessageId 1",
"replyToStoryId": "replyToStoryId 1",
"metadata": {
"key": "value 1"
}
}"#);
let result = api.client().messages().send(params).await.unwrap();
support::assert_json(&result, &response);
let calls = api.calls().await;
assert_eq!(calls.len(), 1);
assert_eq!(calls[0].method, "POST");
assert_eq!(calls[0].path, "/v1/messages");
assert_eq!(calls[0].query, support::pairs(&[]));
support::assert_json(&calls[0].body, &support::json(r#"{
"accountId": "accountId 1",
"to": "to 1",
"type": "text",
"text": "text 1",
"mentions": [
"mentions 1"
],
"mentionAll": true,
"forwarded": true,
"disappearingSeconds": 0,
"linkPreview": {
"url": "https://example.com/url",
"title": "title 1",
"description": "description 1",
"thumbnailBase64": "thumbnailBase64 1"
},
"replyToMessageId": "replyToMessageId 1",
"replyToStoryId": "replyToStoryId 1",
"metadata": {
"key": "value 1"
}
}"#));
assert!(calls[0].header(sdk::IDEMPOTENCY_HEADER).is_some_and(|key| !key.is_empty()));
}
#[tokio::test]
async fn send_retries_with_one_key() {
let response = support::json(r#"{
"object": "message",
"id": "id 1",
"projectId": "projectId 1",
"accountId": "accountId 1",
"chatId": "chatId 1",
"chatType": "direct",
"direction": "inbound",
"source": "api",
"from": "from 1",
"to": "to 1",
"profileName": "profileName 1",
"username": "username 1",
"type": "text",
"text": "text 1",
"media": {
"url": "url 1",
"mimeType": "mimeType 1",
"filename": "filename 1",
"size": 1,
"width": 1,
"height": 1,
"durationSeconds": 1,
"gifPlayback": true,
"downloaded": true
},
"location": {
"latitude": 1.5,
"longitude": 1.5,
"name": "name 1",
"address": "address 1"
},
"contact": {
"name": "name 1",
"phone": "phone 1"
},
"contacts": [
{
"name": "name 1",
"phone": "phone 1"
}
],
"poll": {
"name": "name 1",
"options": [
{
"name": "name 1",
"voteCount": 1
}
],
"selectableCount": 1,
"voterCount": 1
},
"calendarEvent": {
"name": "name 1",
"description": "description 1",
"startsAt": "2026-09-24T09:00:00.000Z",
"endsAt": "2026-09-24T09:00:00.000Z",
"location": {
"name": "name 1",
"address": "address 1",
"latitude": 1.5,
"longitude": 1.5
},
"callType": "audio",
"joinUrl": "joinUrl 1",
"allowExtraGuests": true,
"cancelled": true
},
"mentions": [
"mentions 1"
],
"forwarded": true,
"forwardedManyTimes": true,
"viewOnce": true,
"starred": true,
"replyToMessageId": "replyToMessageId 1",
"replyToStoryId": "replyToStoryId 1",
"status": "queued",
"error": {
"code": "not_on_whatsapp",
"message": "message 1"
},
"metadata": {
"key": "value 1"
},
"sentAt": "2026-09-24T09:00:00.000Z",
"editedAt": "2026-09-24T09:00:00.000Z",
"deletedAt": "2026-09-24T09:00:00.000Z",
"createdAt": "2026-09-24T09:00:00.000Z",
"updatedAt": "2026-09-24T09:00:00.000Z"
}"#);
let api = support::MockApi::start(vec![support::Reply::status(503), support::Reply::json(202, response.clone())]).await;
let params: types::MessagesSendParams = support::from_json(r#"{
"accountId": "accountId 1",
"to": "to 1",
"type": "text",
"text": "text 1",
"mentions": [
"mentions 1"
],
"mentionAll": true,
"forwarded": true,
"disappearingSeconds": 0,
"linkPreview": {
"url": "https://example.com/url",
"title": "title 1",
"description": "description 1",
"thumbnailBase64": "thumbnailBase64 1"
},
"replyToMessageId": "replyToMessageId 1",
"replyToStoryId": "replyToStoryId 1",
"metadata": {
"key": "value 1"
}
}"#);
let result = api.client().messages().send(params).await.unwrap();
support::assert_json(&result, &response);
let calls = api.calls().await;
assert_eq!(calls.len(), 2);
let key = calls[0].header(sdk::IDEMPOTENCY_HEADER).unwrap();
assert!(!key.is_empty());
assert_eq!(calls[1].header(sdk::IDEMPOTENCY_HEADER), Some(key));
assert_eq!(calls[0].body, calls[1].body);
}
#[tokio::test]
async fn list_streams_every_page() {
let first = support::json(r#"{
"object": "list",
"items": [
{
"object": "message",
"id": "id 1",
"projectId": "projectId 1",
"accountId": "accountId 1",
"chatId": "chatId 1",
"chatType": "direct",
"direction": "inbound",
"source": "api",
"from": "from 1",
"to": "to 1",
"profileName": "profileName 1",
"username": "username 1",
"type": "text",
"text": "text 1",
"media": {
"url": "url 1",
"mimeType": "mimeType 1",
"filename": "filename 1",
"size": 1,
"width": 1,
"height": 1,
"durationSeconds": 1,
"gifPlayback": true,
"downloaded": true
},
"location": {
"latitude": 1.5,
"longitude": 1.5,
"name": "name 1",
"address": "address 1"
},
"contact": {
"name": "name 1",
"phone": "phone 1"
},
"contacts": [
{
"name": "name 1",
"phone": "phone 1"
}
],
"poll": {
"name": "name 1",
"options": [
{
"name": "name 1",
"voteCount": 1
}
],
"selectableCount": 1,
"voterCount": 1
},
"calendarEvent": {
"name": "name 1",
"description": "description 1",
"startsAt": "2026-09-24T09:00:00.000Z",
"endsAt": "2026-09-24T09:00:00.000Z",
"location": {
"name": "name 1",
"address": "address 1",
"latitude": 1.5,
"longitude": 1.5
},
"callType": "audio",
"joinUrl": "joinUrl 1",
"allowExtraGuests": true,
"cancelled": true
},
"mentions": [
"mentions 1"
],
"forwarded": true,
"forwardedManyTimes": true,
"viewOnce": true,
"starred": true,
"replyToMessageId": "replyToMessageId 1",
"replyToStoryId": "replyToStoryId 1",
"status": "queued",
"error": {
"code": "not_on_whatsapp",
"message": "message 1"
},
"metadata": {
"key": "value 1"
},
"sentAt": "2026-09-24T09:00:00.000Z",
"editedAt": "2026-09-24T09:00:00.000Z",
"deletedAt": "2026-09-24T09:00:00.000Z",
"createdAt": "2026-09-24T09:00:00.000Z",
"updatedAt": "2026-09-24T09:00:00.000Z"
}
],
"nextCursor": "cursor_2"
}"#);
let last = support::json(r#"{
"object": "list",
"items": [
{
"object": "message",
"id": "id 1",
"projectId": "projectId 1",
"accountId": "accountId 1",
"chatId": "chatId 1",
"chatType": "direct",
"direction": "inbound",
"source": "api",
"from": "from 1",
"to": "to 1",
"profileName": "profileName 1",
"username": "username 1",
"type": "text",
"text": "text 1",
"media": {
"url": "url 1",
"mimeType": "mimeType 1",
"filename": "filename 1",
"size": 1,
"width": 1,
"height": 1,
"durationSeconds": 1,
"gifPlayback": true,
"downloaded": true
},
"location": {
"latitude": 1.5,
"longitude": 1.5,
"name": "name 1",
"address": "address 1"
},
"contact": {
"name": "name 1",
"phone": "phone 1"
},
"contacts": [
{
"name": "name 1",
"phone": "phone 1"
}
],
"poll": {
"name": "name 1",
"options": [
{
"name": "name 1",
"voteCount": 1
}
],
"selectableCount": 1,
"voterCount": 1
},
"calendarEvent": {
"name": "name 1",
"description": "description 1",
"startsAt": "2026-09-24T09:00:00.000Z",
"endsAt": "2026-09-24T09:00:00.000Z",
"location": {
"name": "name 1",
"address": "address 1",
"latitude": 1.5,
"longitude": 1.5
},
"callType": "audio",
"joinUrl": "joinUrl 1",
"allowExtraGuests": true,
"cancelled": true
},
"mentions": [
"mentions 1"
],
"forwarded": true,
"forwardedManyTimes": true,
"viewOnce": true,
"starred": true,
"replyToMessageId": "replyToMessageId 1",
"replyToStoryId": "replyToStoryId 1",
"status": "queued",
"error": {
"code": "not_on_whatsapp",
"message": "message 1"
},
"metadata": {
"key": "value 1"
},
"sentAt": "2026-09-24T09:00:00.000Z",
"editedAt": "2026-09-24T09:00:00.000Z",
"deletedAt": "2026-09-24T09:00:00.000Z",
"createdAt": "2026-09-24T09:00:00.000Z",
"updatedAt": "2026-09-24T09:00:00.000Z"
}
],
"nextCursor": null
}"#);
let api = support::MockApi::start(vec![
support::Reply::json(200, first),
support::Reply::json(200, last),
])
.await;
let params: types::MessagesListParams = support::from_json(r#"{
"accountId": "accountId 1",
"chatId": "chatId 1",
"direction": "inbound",
"limit": 50,
"cursor": "cursor 1",
"projectId": "ext:customer_8812"
}"#);
let items = api.client().messages().list(params).to_vec().await.unwrap();
support::assert_json(&items, &support::json(r#"[
{
"object": "message",
"id": "id 1",
"projectId": "projectId 1",
"accountId": "accountId 1",
"chatId": "chatId 1",
"chatType": "direct",
"direction": "inbound",
"source": "api",
"from": "from 1",
"to": "to 1",
"profileName": "profileName 1",
"username": "username 1",
"type": "text",
"text": "text 1",
"media": {
"url": "url 1",
"mimeType": "mimeType 1",
"filename": "filename 1",
"size": 1,
"width": 1,
"height": 1,
"durationSeconds": 1,
"gifPlayback": true,
"downloaded": true
},
"location": {
"latitude": 1.5,
"longitude": 1.5,
"name": "name 1",
"address": "address 1"
},
"contact": {
"name": "name 1",
"phone": "phone 1"
},
"contacts": [
{
"name": "name 1",
"phone": "phone 1"
}
],
"poll": {
"name": "name 1",
"options": [
{
"name": "name 1",
"voteCount": 1
}
],
"selectableCount": 1,
"voterCount": 1
},
"calendarEvent": {
"name": "name 1",
"description": "description 1",
"startsAt": "2026-09-24T09:00:00.000Z",
"endsAt": "2026-09-24T09:00:00.000Z",
"location": {
"name": "name 1",
"address": "address 1",
"latitude": 1.5,
"longitude": 1.5
},
"callType": "audio",
"joinUrl": "joinUrl 1",
"allowExtraGuests": true,
"cancelled": true
},
"mentions": [
"mentions 1"
],
"forwarded": true,
"forwardedManyTimes": true,
"viewOnce": true,
"starred": true,
"replyToMessageId": "replyToMessageId 1",
"replyToStoryId": "replyToStoryId 1",
"status": "queued",
"error": {
"code": "not_on_whatsapp",
"message": "message 1"
},
"metadata": {
"key": "value 1"
},
"sentAt": "2026-09-24T09:00:00.000Z",
"editedAt": "2026-09-24T09:00:00.000Z",
"deletedAt": "2026-09-24T09:00:00.000Z",
"createdAt": "2026-09-24T09:00:00.000Z",
"updatedAt": "2026-09-24T09:00:00.000Z"
},
{
"object": "message",
"id": "id 1",
"projectId": "projectId 1",
"accountId": "accountId 1",
"chatId": "chatId 1",
"chatType": "direct",
"direction": "inbound",
"source": "api",
"from": "from 1",
"to": "to 1",
"profileName": "profileName 1",
"username": "username 1",
"type": "text",
"text": "text 1",
"media": {
"url": "url 1",
"mimeType": "mimeType 1",
"filename": "filename 1",
"size": 1,
"width": 1,
"height": 1,
"durationSeconds": 1,
"gifPlayback": true,
"downloaded": true
},
"location": {
"latitude": 1.5,
"longitude": 1.5,
"name": "name 1",
"address": "address 1"
},
"contact": {
"name": "name 1",
"phone": "phone 1"
},
"contacts": [
{
"name": "name 1",
"phone": "phone 1"
}
],
"poll": {
"name": "name 1",
"options": [
{
"name": "name 1",
"voteCount": 1
}
],
"selectableCount": 1,
"voterCount": 1
},
"calendarEvent": {
"name": "name 1",
"description": "description 1",
"startsAt": "2026-09-24T09:00:00.000Z",
"endsAt": "2026-09-24T09:00:00.000Z",
"location": {
"name": "name 1",
"address": "address 1",
"latitude": 1.5,
"longitude": 1.5
},
"callType": "audio",
"joinUrl": "joinUrl 1",
"allowExtraGuests": true,
"cancelled": true
},
"mentions": [
"mentions 1"
],
"forwarded": true,
"forwardedManyTimes": true,
"viewOnce": true,
"starred": true,
"replyToMessageId": "replyToMessageId 1",
"replyToStoryId": "replyToStoryId 1",
"status": "queued",
"error": {
"code": "not_on_whatsapp",
"message": "message 1"
},
"metadata": {
"key": "value 1"
},
"sentAt": "2026-09-24T09:00:00.000Z",
"editedAt": "2026-09-24T09:00:00.000Z",
"deletedAt": "2026-09-24T09:00:00.000Z",
"createdAt": "2026-09-24T09:00:00.000Z",
"updatedAt": "2026-09-24T09:00:00.000Z"
}
]"#));
let calls = api.calls().await;
assert_eq!(calls.len(), 2);
assert_eq!(calls[0].method, "GET");
assert_eq!(calls[0].path, "/v1/messages");
assert_eq!(calls[0].query, support::pairs(&[("accountId", "accountId 1"), ("chatId", "chatId 1"), ("direction", "inbound"), ("limit", "50"), ("projectId", "ext:customer_8812"), ("cursor", "cursor 1")]));
assert_eq!(calls[1].query, support::pairs(&[("accountId", "accountId 1"), ("chatId", "chatId 1"), ("direction", "inbound"), ("limit", "50"), ("projectId", "ext:customer_8812"), ("cursor", "cursor_2")]));
}
#[tokio::test]
async fn list_fetches_one_page() {
let page = support::json(r#"{
"object": "list",
"items": [
{
"object": "message",
"id": "id 1",
"projectId": "projectId 1",
"accountId": "accountId 1",
"chatId": "chatId 1",
"chatType": "direct",
"direction": "inbound",
"source": "api",
"from": "from 1",
"to": "to 1",
"profileName": "profileName 1",
"username": "username 1",
"type": "text",
"text": "text 1",
"media": {
"url": "url 1",
"mimeType": "mimeType 1",
"filename": "filename 1",
"size": 1,
"width": 1,
"height": 1,
"durationSeconds": 1,
"gifPlayback": true,
"downloaded": true
},
"location": {
"latitude": 1.5,
"longitude": 1.5,
"name": "name 1",
"address": "address 1"
},
"contact": {
"name": "name 1",
"phone": "phone 1"
},
"contacts": [
{
"name": "name 1",
"phone": "phone 1"
}
],
"poll": {
"name": "name 1",
"options": [
{
"name": "name 1",
"voteCount": 1
}
],
"selectableCount": 1,
"voterCount": 1
},
"calendarEvent": {
"name": "name 1",
"description": "description 1",
"startsAt": "2026-09-24T09:00:00.000Z",
"endsAt": "2026-09-24T09:00:00.000Z",
"location": {
"name": "name 1",
"address": "address 1",
"latitude": 1.5,
"longitude": 1.5
},
"callType": "audio",
"joinUrl": "joinUrl 1",
"allowExtraGuests": true,
"cancelled": true
},
"mentions": [
"mentions 1"
],
"forwarded": true,
"forwardedManyTimes": true,
"viewOnce": true,
"starred": true,
"replyToMessageId": "replyToMessageId 1",
"replyToStoryId": "replyToStoryId 1",
"status": "queued",
"error": {
"code": "not_on_whatsapp",
"message": "message 1"
},
"metadata": {
"key": "value 1"
},
"sentAt": "2026-09-24T09:00:00.000Z",
"editedAt": "2026-09-24T09:00:00.000Z",
"deletedAt": "2026-09-24T09:00:00.000Z",
"createdAt": "2026-09-24T09:00:00.000Z",
"updatedAt": "2026-09-24T09:00:00.000Z"
}
],
"nextCursor": null
}"#);
let api = support::MockApi::start(vec![support::Reply::json(200, page.clone())]).await;
let result = api.client().messages().list(Default::default()).page().await.unwrap();
support::assert_json(&result, &page);
let calls = api.calls().await;
assert_eq!(calls.len(), 1);
assert_eq!(calls[0].method, "GET");
assert_eq!(calls[0].path, "/v1/messages");
assert_eq!(calls[0].query, support::pairs(&[]));
}
#[tokio::test]
async fn get() {
let response = support::json(r#"{
"object": "message",
"id": "id 1",
"projectId": "projectId 1",
"accountId": "accountId 1",
"chatId": "chatId 1",
"chatType": "direct",
"direction": "inbound",
"source": "api",
"from": "from 1",
"to": "to 1",
"profileName": "profileName 1",
"username": "username 1",
"type": "text",
"text": "text 1",
"media": {
"url": "url 1",
"mimeType": "mimeType 1",
"filename": "filename 1",
"size": 1,
"width": 1,
"height": 1,
"durationSeconds": 1,
"gifPlayback": true,
"downloaded": true
},
"location": {
"latitude": 1.5,
"longitude": 1.5,
"name": "name 1",
"address": "address 1"
},
"contact": {
"name": "name 1",
"phone": "phone 1"
},
"contacts": [
{
"name": "name 1",
"phone": "phone 1"
}
],
"poll": {
"name": "name 1",
"options": [
{
"name": "name 1",
"voteCount": 1
}
],
"selectableCount": 1,
"voterCount": 1
},
"calendarEvent": {
"name": "name 1",
"description": "description 1",
"startsAt": "2026-09-24T09:00:00.000Z",
"endsAt": "2026-09-24T09:00:00.000Z",
"location": {
"name": "name 1",
"address": "address 1",
"latitude": 1.5,
"longitude": 1.5
},
"callType": "audio",
"joinUrl": "joinUrl 1",
"allowExtraGuests": true,
"cancelled": true
},
"mentions": [
"mentions 1"
],
"forwarded": true,
"forwardedManyTimes": true,
"viewOnce": true,
"starred": true,
"replyToMessageId": "replyToMessageId 1",
"replyToStoryId": "replyToStoryId 1",
"status": "queued",
"error": {
"code": "not_on_whatsapp",
"message": "message 1"
},
"metadata": {
"key": "value 1"
},
"sentAt": "2026-09-24T09:00:00.000Z",
"editedAt": "2026-09-24T09:00:00.000Z",
"deletedAt": "2026-09-24T09:00:00.000Z",
"createdAt": "2026-09-24T09:00:00.000Z",
"updatedAt": "2026-09-24T09:00:00.000Z"
}"#);
let api = support::MockApi::start(vec![support::Reply::json(200, response.clone())]).await;
let result = api.client().messages().get("m17d0a9w2sqc7k3v8x1n5ybr6t4hjp2e").await.unwrap();
support::assert_json(&result, &response);
let calls = api.calls().await;
assert_eq!(calls.len(), 1);
assert_eq!(calls[0].method, "GET");
assert_eq!(calls[0].path, "/v1/messages/m17d0a9w2sqc7k3v8x1n5ybr6t4hjp2e");
assert_eq!(calls[0].query, support::pairs(&[]));
assert!(calls[0].body.is_none());
assert!(calls[0].header(sdk::IDEMPOTENCY_HEADER).is_none());
}
#[tokio::test]
async fn get_media() {
let response = support::json(r#"{
"object": "media",
"messageId": "messageId 1",
"url": "url 1",
"mimeType": "mimeType 1",
"filename": "filename 1",
"size": 1
}"#);
let api = support::MockApi::start(vec![support::Reply::json(200, response.clone())]).await;
let params: types::MessagesGetMediaParams = support::from_json(r#"{"redirect":true}"#);
let result = api.client().messages().get_media("m17d0a9w2sqc7k3v8x1n5ybr6t4hjp2e", params).await.unwrap();
support::assert_json(&result, &response);
let calls = api.calls().await;
assert_eq!(calls.len(), 1);
assert_eq!(calls[0].method, "GET");
assert_eq!(calls[0].path, "/v1/messages/m17d0a9w2sqc7k3v8x1n5ybr6t4hjp2e/media");
assert_eq!(calls[0].query, support::pairs(&[("redirect", "true")]));
assert!(calls[0].body.is_none());
assert!(calls[0].header(sdk::IDEMPOTENCY_HEADER).is_none());
}
#[tokio::test]
async fn get_media_without_params() {
let response = support::json(r#"{
"object": "media",
"messageId": "messageId 1",
"url": "url 1",
"mimeType": "mimeType 1",
"filename": "filename 1",
"size": 1
}"#);
let api = support::MockApi::start(vec![support::Reply::json(200, response.clone())]).await;
let result = api.client().messages().get_media("m17d0a9w2sqc7k3v8x1n5ybr6t4hjp2e", Default::default()).await.unwrap();
support::assert_json(&result, &response);
let calls = api.calls().await;
assert_eq!(calls.len(), 1);
assert_eq!(calls[0].method, "GET");
assert_eq!(calls[0].path, "/v1/messages/m17d0a9w2sqc7k3v8x1n5ybr6t4hjp2e/media");
assert_eq!(calls[0].query, support::pairs(&[]));
assert!(calls[0].body.is_none());
assert!(calls[0].header(sdk::IDEMPOTENCY_HEADER).is_none());
}
#[tokio::test]
async fn edit() {
let response = support::json(r#"{
"object": "message",
"id": "id 1",
"projectId": "projectId 1",
"accountId": "accountId 1",
"chatId": "chatId 1",
"chatType": "direct",
"direction": "inbound",
"source": "api",
"from": "from 1",
"to": "to 1",
"profileName": "profileName 1",
"username": "username 1",
"type": "text",
"text": "text 1",
"media": {
"url": "url 1",
"mimeType": "mimeType 1",
"filename": "filename 1",
"size": 1,
"width": 1,
"height": 1,
"durationSeconds": 1,
"gifPlayback": true,
"downloaded": true
},
"location": {
"latitude": 1.5,
"longitude": 1.5,
"name": "name 1",
"address": "address 1"
},
"contact": {
"name": "name 1",
"phone": "phone 1"
},
"contacts": [
{
"name": "name 1",
"phone": "phone 1"
}
],
"poll": {
"name": "name 1",
"options": [
{
"name": "name 1",
"voteCount": 1
}
],
"selectableCount": 1,
"voterCount": 1
},
"calendarEvent": {
"name": "name 1",
"description": "description 1",
"startsAt": "2026-09-24T09:00:00.000Z",
"endsAt": "2026-09-24T09:00:00.000Z",
"location": {
"name": "name 1",
"address": "address 1",
"latitude": 1.5,
"longitude": 1.5
},
"callType": "audio",
"joinUrl": "joinUrl 1",
"allowExtraGuests": true,
"cancelled": true
},
"mentions": [
"mentions 1"
],
"forwarded": true,
"forwardedManyTimes": true,
"viewOnce": true,
"starred": true,
"replyToMessageId": "replyToMessageId 1",
"replyToStoryId": "replyToStoryId 1",
"status": "queued",
"error": {
"code": "not_on_whatsapp",
"message": "message 1"
},
"metadata": {
"key": "value 1"
},
"sentAt": "2026-09-24T09:00:00.000Z",
"editedAt": "2026-09-24T09:00:00.000Z",
"deletedAt": "2026-09-24T09:00:00.000Z",
"createdAt": "2026-09-24T09:00:00.000Z",
"updatedAt": "2026-09-24T09:00:00.000Z"
}"#);
let api = support::MockApi::start(vec![support::Reply::json(200, response.clone())]).await;
let params: types::MessagesEditParams = support::from_json(r#"{"text":"text 1"}"#);
let result = api.client().messages().edit("m17d0a9w2sqc7k3v8x1n5ybr6t4hjp2e", params).await.unwrap();
support::assert_json(&result, &response);
let calls = api.calls().await;
assert_eq!(calls.len(), 1);
assert_eq!(calls[0].method, "PATCH");
assert_eq!(calls[0].path, "/v1/messages/m17d0a9w2sqc7k3v8x1n5ybr6t4hjp2e");
assert_eq!(calls[0].query, support::pairs(&[]));
support::assert_json(&calls[0].body, &support::json(r#"{"text":"text 1"}"#));
assert!(calls[0].header(sdk::IDEMPOTENCY_HEADER).is_none());
}
#[tokio::test]
async fn edit_is_not_repeated() {
let api = support::MockApi::start(vec![
support::Reply::status(503),
support::Reply::status(503),
])
.await;
let params: types::MessagesEditParams = support::from_json(r#"{"text":"text 1"}"#);
let error = api.client().messages().edit("m17d0a9w2sqc7k3v8x1n5ybr6t4hjp2e", params).await.unwrap_err();
assert_eq!(error.status(), Some(503));
assert_eq!(api.calls().await.len(), 1);
}
#[tokio::test]
async fn delete() {
let api = support::MockApi::start(vec![support::Reply::status(204)]).await;
let params: types::MessagesDeleteParams = support::from_json(r#"{"forEveryone":true}"#);
api.client().messages().delete("m17d0a9w2sqc7k3v8x1n5ybr6t4hjp2e", params).await.unwrap();
let calls = api.calls().await;
assert_eq!(calls.len(), 1);
assert_eq!(calls[0].method, "DELETE");
assert_eq!(calls[0].path, "/v1/messages/m17d0a9w2sqc7k3v8x1n5ybr6t4hjp2e");
assert_eq!(calls[0].query, support::pairs(&[("forEveryone", "true")]));
assert!(calls[0].body.is_none());
assert!(calls[0].header(sdk::IDEMPOTENCY_HEADER).is_none());
}
#[tokio::test]
async fn delete_without_params() {
let api = support::MockApi::start(vec![support::Reply::status(204)]).await;
api.client().messages().delete("m17d0a9w2sqc7k3v8x1n5ybr6t4hjp2e", Default::default()).await.unwrap();
let calls = api.calls().await;
assert_eq!(calls.len(), 1);
assert_eq!(calls[0].method, "DELETE");
assert_eq!(calls[0].path, "/v1/messages/m17d0a9w2sqc7k3v8x1n5ybr6t4hjp2e");
assert_eq!(calls[0].query, support::pairs(&[]));
assert!(calls[0].body.is_none());
assert!(calls[0].header(sdk::IDEMPOTENCY_HEADER).is_none());
}
#[tokio::test]
async fn react() {
let api = support::MockApi::start(vec![support::Reply::status(204)]).await;
let params: types::MessagesReactParams = support::from_json(r#"{"emoji":"emoji 1"}"#);
api.client().messages().react("m17d0a9w2sqc7k3v8x1n5ybr6t4hjp2e", params).await.unwrap();
let calls = api.calls().await;
assert_eq!(calls.len(), 1);
assert_eq!(calls[0].method, "POST");
assert_eq!(calls[0].path, "/v1/messages/m17d0a9w2sqc7k3v8x1n5ybr6t4hjp2e/react");
assert_eq!(calls[0].query, support::pairs(&[]));
support::assert_json(&calls[0].body, &support::json(r#"{"emoji":"emoji 1"}"#));
assert!(calls[0].header(sdk::IDEMPOTENCY_HEADER).is_some_and(|key| !key.is_empty()));
}
#[tokio::test]
async fn react_retries_with_one_key() {
let api = support::MockApi::start(vec![support::Reply::status(503), support::Reply::status(204)]).await;
let params: types::MessagesReactParams = support::from_json(r#"{"emoji":"emoji 1"}"#);
api.client().messages().react("m17d0a9w2sqc7k3v8x1n5ybr6t4hjp2e", params).await.unwrap();
let calls = api.calls().await;
assert_eq!(calls.len(), 2);
let key = calls[0].header(sdk::IDEMPOTENCY_HEADER).unwrap();
assert!(!key.is_empty());
assert_eq!(calls[1].header(sdk::IDEMPOTENCY_HEADER), Some(key));
assert_eq!(calls[0].body, calls[1].body);
}
#[tokio::test]
async fn vote() {
let response = support::json(r#"{
"object": "message",
"id": "id 1",
"projectId": "projectId 1",
"accountId": "accountId 1",
"chatId": "chatId 1",
"chatType": "direct",
"direction": "inbound",
"source": "api",
"from": "from 1",
"to": "to 1",
"profileName": "profileName 1",
"username": "username 1",
"type": "text",
"text": "text 1",
"media": {
"url": "url 1",
"mimeType": "mimeType 1",
"filename": "filename 1",
"size": 1,
"width": 1,
"height": 1,
"durationSeconds": 1,
"gifPlayback": true,
"downloaded": true
},
"location": {
"latitude": 1.5,
"longitude": 1.5,
"name": "name 1",
"address": "address 1"
},
"contact": {
"name": "name 1",
"phone": "phone 1"
},
"contacts": [
{
"name": "name 1",
"phone": "phone 1"
}
],
"poll": {
"name": "name 1",
"options": [
{
"name": "name 1",
"voteCount": 1
}
],
"selectableCount": 1,
"voterCount": 1
},
"calendarEvent": {
"name": "name 1",
"description": "description 1",
"startsAt": "2026-09-24T09:00:00.000Z",
"endsAt": "2026-09-24T09:00:00.000Z",
"location": {
"name": "name 1",
"address": "address 1",
"latitude": 1.5,
"longitude": 1.5
},
"callType": "audio",
"joinUrl": "joinUrl 1",
"allowExtraGuests": true,
"cancelled": true
},
"mentions": [
"mentions 1"
],
"forwarded": true,
"forwardedManyTimes": true,
"viewOnce": true,
"starred": true,
"replyToMessageId": "replyToMessageId 1",
"replyToStoryId": "replyToStoryId 1",
"status": "queued",
"error": {
"code": "not_on_whatsapp",
"message": "message 1"
},
"metadata": {
"key": "value 1"
},
"sentAt": "2026-09-24T09:00:00.000Z",
"editedAt": "2026-09-24T09:00:00.000Z",
"deletedAt": "2026-09-24T09:00:00.000Z",
"createdAt": "2026-09-24T09:00:00.000Z",
"updatedAt": "2026-09-24T09:00:00.000Z"
}"#);
let api = support::MockApi::start(vec![support::Reply::json(200, response.clone())]).await;
let params: types::MessagesVoteParams = support::from_json(r#"{"options":["options 1"]}"#);
let result = api.client().messages().vote("m17d0a9w2sqc7k3v8x1n5ybr6t4hjp2e", params).await.unwrap();
support::assert_json(&result, &response);
let calls = api.calls().await;
assert_eq!(calls.len(), 1);
assert_eq!(calls[0].method, "POST");
assert_eq!(calls[0].path, "/v1/messages/m17d0a9w2sqc7k3v8x1n5ybr6t4hjp2e/vote");
assert_eq!(calls[0].query, support::pairs(&[]));
support::assert_json(&calls[0].body, &support::json(r#"{"options":["options 1"]}"#));
assert!(calls[0].header(sdk::IDEMPOTENCY_HEADER).is_some_and(|key| !key.is_empty()));
}
#[tokio::test]
async fn vote_retries_with_one_key() {
let response = support::json(r#"{
"object": "message",
"id": "id 1",
"projectId": "projectId 1",
"accountId": "accountId 1",
"chatId": "chatId 1",
"chatType": "direct",
"direction": "inbound",
"source": "api",
"from": "from 1",
"to": "to 1",
"profileName": "profileName 1",
"username": "username 1",
"type": "text",
"text": "text 1",
"media": {
"url": "url 1",
"mimeType": "mimeType 1",
"filename": "filename 1",
"size": 1,
"width": 1,
"height": 1,
"durationSeconds": 1,
"gifPlayback": true,
"downloaded": true
},
"location": {
"latitude": 1.5,
"longitude": 1.5,
"name": "name 1",
"address": "address 1"
},
"contact": {
"name": "name 1",
"phone": "phone 1"
},
"contacts": [
{
"name": "name 1",
"phone": "phone 1"
}
],
"poll": {
"name": "name 1",
"options": [
{
"name": "name 1",
"voteCount": 1
}
],
"selectableCount": 1,
"voterCount": 1
},
"calendarEvent": {
"name": "name 1",
"description": "description 1",
"startsAt": "2026-09-24T09:00:00.000Z",
"endsAt": "2026-09-24T09:00:00.000Z",
"location": {
"name": "name 1",
"address": "address 1",
"latitude": 1.5,
"longitude": 1.5
},
"callType": "audio",
"joinUrl": "joinUrl 1",
"allowExtraGuests": true,
"cancelled": true
},
"mentions": [
"mentions 1"
],
"forwarded": true,
"forwardedManyTimes": true,
"viewOnce": true,
"starred": true,
"replyToMessageId": "replyToMessageId 1",
"replyToStoryId": "replyToStoryId 1",
"status": "queued",
"error": {
"code": "not_on_whatsapp",
"message": "message 1"
},
"metadata": {
"key": "value 1"
},
"sentAt": "2026-09-24T09:00:00.000Z",
"editedAt": "2026-09-24T09:00:00.000Z",
"deletedAt": "2026-09-24T09:00:00.000Z",
"createdAt": "2026-09-24T09:00:00.000Z",
"updatedAt": "2026-09-24T09:00:00.000Z"
}"#);
let api = support::MockApi::start(vec![support::Reply::status(503), support::Reply::json(200, response.clone())]).await;
let params: types::MessagesVoteParams = support::from_json(r#"{"options":["options 1"]}"#);
let result = api.client().messages().vote("m17d0a9w2sqc7k3v8x1n5ybr6t4hjp2e", params).await.unwrap();
support::assert_json(&result, &response);
let calls = api.calls().await;
assert_eq!(calls.len(), 2);
let key = calls[0].header(sdk::IDEMPOTENCY_HEADER).unwrap();
assert!(!key.is_empty());
assert_eq!(calls[1].header(sdk::IDEMPOTENCY_HEADER), Some(key));
assert_eq!(calls[0].body, calls[1].body);
}
#[tokio::test]
async fn forward() {
let response = support::json(r#"{
"object": "list",
"items": [
{
"object": "message",
"id": "id 1",
"projectId": "projectId 1",
"accountId": "accountId 1",
"chatId": "chatId 1",
"chatType": "direct",
"direction": "inbound",
"source": "api",
"from": "from 1",
"to": "to 1",
"profileName": "profileName 1",
"username": "username 1",
"type": "text",
"text": "text 1",
"media": {
"url": "url 1",
"mimeType": "mimeType 1",
"filename": "filename 1",
"size": 1,
"width": 1,
"height": 1,
"durationSeconds": 1,
"gifPlayback": true,
"downloaded": true
},
"location": {
"latitude": 1.5,
"longitude": 1.5,
"name": "name 1",
"address": "address 1"
},
"contact": {
"name": "name 1",
"phone": "phone 1"
},
"contacts": [
{
"name": "name 1",
"phone": "phone 1"
}
],
"poll": {
"name": "name 1",
"options": [
{
"name": "name 1",
"voteCount": 1
}
],
"selectableCount": 1,
"voterCount": 1
},
"calendarEvent": {
"name": "name 1",
"description": "description 1",
"startsAt": "2026-09-24T09:00:00.000Z",
"endsAt": "2026-09-24T09:00:00.000Z",
"location": {
"name": "name 1",
"address": "address 1",
"latitude": 1.5,
"longitude": 1.5
},
"callType": "audio",
"joinUrl": "joinUrl 1",
"allowExtraGuests": true,
"cancelled": true
},
"mentions": [
"mentions 1"
],
"forwarded": true,
"forwardedManyTimes": true,
"viewOnce": true,
"starred": true,
"replyToMessageId": "replyToMessageId 1",
"replyToStoryId": "replyToStoryId 1",
"status": "queued",
"error": {
"code": "not_on_whatsapp",
"message": "message 1"
},
"metadata": {
"key": "value 1"
},
"sentAt": "2026-09-24T09:00:00.000Z",
"editedAt": "2026-09-24T09:00:00.000Z",
"deletedAt": "2026-09-24T09:00:00.000Z",
"createdAt": "2026-09-24T09:00:00.000Z",
"updatedAt": "2026-09-24T09:00:00.000Z"
}
],
"nextCursor": "nextCursor 1"
}"#);
let api = support::MockApi::start(vec![support::Reply::json(202, response.clone())]).await;
let params: types::MessagesForwardParams = support::from_json(r#"{"to":["to 1"]}"#);
let result = api.client().messages().forward("m17d0a9w2sqc7k3v8x1n5ybr6t4hjp2e", params).await.unwrap();
support::assert_json(&result, &response);
let calls = api.calls().await;
assert_eq!(calls.len(), 1);
assert_eq!(calls[0].method, "POST");
assert_eq!(calls[0].path, "/v1/messages/m17d0a9w2sqc7k3v8x1n5ybr6t4hjp2e/forward");
assert_eq!(calls[0].query, support::pairs(&[]));
support::assert_json(&calls[0].body, &support::json(r#"{"to":["to 1"]}"#));
assert!(calls[0].header(sdk::IDEMPOTENCY_HEADER).is_some_and(|key| !key.is_empty()));
}
#[tokio::test]
async fn forward_retries_with_one_key() {
let response = support::json(r#"{
"object": "list",
"items": [
{
"object": "message",
"id": "id 1",
"projectId": "projectId 1",
"accountId": "accountId 1",
"chatId": "chatId 1",
"chatType": "direct",
"direction": "inbound",
"source": "api",
"from": "from 1",
"to": "to 1",
"profileName": "profileName 1",
"username": "username 1",
"type": "text",
"text": "text 1",
"media": {
"url": "url 1",
"mimeType": "mimeType 1",
"filename": "filename 1",
"size": 1,
"width": 1,
"height": 1,
"durationSeconds": 1,
"gifPlayback": true,
"downloaded": true
},
"location": {
"latitude": 1.5,
"longitude": 1.5,
"name": "name 1",
"address": "address 1"
},
"contact": {
"name": "name 1",
"phone": "phone 1"
},
"contacts": [
{
"name": "name 1",
"phone": "phone 1"
}
],
"poll": {
"name": "name 1",
"options": [
{
"name": "name 1",
"voteCount": 1
}
],
"selectableCount": 1,
"voterCount": 1
},
"calendarEvent": {
"name": "name 1",
"description": "description 1",
"startsAt": "2026-09-24T09:00:00.000Z",
"endsAt": "2026-09-24T09:00:00.000Z",
"location": {
"name": "name 1",
"address": "address 1",
"latitude": 1.5,
"longitude": 1.5
},
"callType": "audio",
"joinUrl": "joinUrl 1",
"allowExtraGuests": true,
"cancelled": true
},
"mentions": [
"mentions 1"
],
"forwarded": true,
"forwardedManyTimes": true,
"viewOnce": true,
"starred": true,
"replyToMessageId": "replyToMessageId 1",
"replyToStoryId": "replyToStoryId 1",
"status": "queued",
"error": {
"code": "not_on_whatsapp",
"message": "message 1"
},
"metadata": {
"key": "value 1"
},
"sentAt": "2026-09-24T09:00:00.000Z",
"editedAt": "2026-09-24T09:00:00.000Z",
"deletedAt": "2026-09-24T09:00:00.000Z",
"createdAt": "2026-09-24T09:00:00.000Z",
"updatedAt": "2026-09-24T09:00:00.000Z"
}
],
"nextCursor": "nextCursor 1"
}"#);
let api = support::MockApi::start(vec![support::Reply::status(503), support::Reply::json(202, response.clone())]).await;
let params: types::MessagesForwardParams = support::from_json(r#"{"to":["to 1"]}"#);
let result = api.client().messages().forward("m17d0a9w2sqc7k3v8x1n5ybr6t4hjp2e", params).await.unwrap();
support::assert_json(&result, &response);
let calls = api.calls().await;
assert_eq!(calls.len(), 2);
let key = calls[0].header(sdk::IDEMPOTENCY_HEADER).unwrap();
assert!(!key.is_empty());
assert_eq!(calls[1].header(sdk::IDEMPOTENCY_HEADER), Some(key));
assert_eq!(calls[0].body, calls[1].body);
}
#[tokio::test]
async fn star() {
let response = support::json(r#"{
"object": "message",
"id": "id 1",
"projectId": "projectId 1",
"accountId": "accountId 1",
"chatId": "chatId 1",
"chatType": "direct",
"direction": "inbound",
"source": "api",
"from": "from 1",
"to": "to 1",
"profileName": "profileName 1",
"username": "username 1",
"type": "text",
"text": "text 1",
"media": {
"url": "url 1",
"mimeType": "mimeType 1",
"filename": "filename 1",
"size": 1,
"width": 1,
"height": 1,
"durationSeconds": 1,
"gifPlayback": true,
"downloaded": true
},
"location": {
"latitude": 1.5,
"longitude": 1.5,
"name": "name 1",
"address": "address 1"
},
"contact": {
"name": "name 1",
"phone": "phone 1"
},
"contacts": [
{
"name": "name 1",
"phone": "phone 1"
}
],
"poll": {
"name": "name 1",
"options": [
{
"name": "name 1",
"voteCount": 1
}
],
"selectableCount": 1,
"voterCount": 1
},
"calendarEvent": {
"name": "name 1",
"description": "description 1",
"startsAt": "2026-09-24T09:00:00.000Z",
"endsAt": "2026-09-24T09:00:00.000Z",
"location": {
"name": "name 1",
"address": "address 1",
"latitude": 1.5,
"longitude": 1.5
},
"callType": "audio",
"joinUrl": "joinUrl 1",
"allowExtraGuests": true,
"cancelled": true
},
"mentions": [
"mentions 1"
],
"forwarded": true,
"forwardedManyTimes": true,
"viewOnce": true,
"starred": true,
"replyToMessageId": "replyToMessageId 1",
"replyToStoryId": "replyToStoryId 1",
"status": "queued",
"error": {
"code": "not_on_whatsapp",
"message": "message 1"
},
"metadata": {
"key": "value 1"
},
"sentAt": "2026-09-24T09:00:00.000Z",
"editedAt": "2026-09-24T09:00:00.000Z",
"deletedAt": "2026-09-24T09:00:00.000Z",
"createdAt": "2026-09-24T09:00:00.000Z",
"updatedAt": "2026-09-24T09:00:00.000Z"
}"#);
let api = support::MockApi::start(vec![support::Reply::json(200, response.clone())]).await;
let result = api.client().messages().star("m17d0a9w2sqc7k3v8x1n5ybr6t4hjp2e").await.unwrap();
support::assert_json(&result, &response);
let calls = api.calls().await;
assert_eq!(calls.len(), 1);
assert_eq!(calls[0].method, "POST");
assert_eq!(calls[0].path, "/v1/messages/m17d0a9w2sqc7k3v8x1n5ybr6t4hjp2e/star");
assert_eq!(calls[0].query, support::pairs(&[]));
assert!(calls[0].body.is_none());
assert!(calls[0].header(sdk::IDEMPOTENCY_HEADER).is_some_and(|key| !key.is_empty()));
}
#[tokio::test]
async fn star_retries_with_one_key() {
let response = support::json(r#"{
"object": "message",
"id": "id 1",
"projectId": "projectId 1",
"accountId": "accountId 1",
"chatId": "chatId 1",
"chatType": "direct",
"direction": "inbound",
"source": "api",
"from": "from 1",
"to": "to 1",
"profileName": "profileName 1",
"username": "username 1",
"type": "text",
"text": "text 1",
"media": {
"url": "url 1",
"mimeType": "mimeType 1",
"filename": "filename 1",
"size": 1,
"width": 1,
"height": 1,
"durationSeconds": 1,
"gifPlayback": true,
"downloaded": true
},
"location": {
"latitude": 1.5,
"longitude": 1.5,
"name": "name 1",
"address": "address 1"
},
"contact": {
"name": "name 1",
"phone": "phone 1"
},
"contacts": [
{
"name": "name 1",
"phone": "phone 1"
}
],
"poll": {
"name": "name 1",
"options": [
{
"name": "name 1",
"voteCount": 1
}
],
"selectableCount": 1,
"voterCount": 1
},
"calendarEvent": {
"name": "name 1",
"description": "description 1",
"startsAt": "2026-09-24T09:00:00.000Z",
"endsAt": "2026-09-24T09:00:00.000Z",
"location": {
"name": "name 1",
"address": "address 1",
"latitude": 1.5,
"longitude": 1.5
},
"callType": "audio",
"joinUrl": "joinUrl 1",
"allowExtraGuests": true,
"cancelled": true
},
"mentions": [
"mentions 1"
],
"forwarded": true,
"forwardedManyTimes": true,
"viewOnce": true,
"starred": true,
"replyToMessageId": "replyToMessageId 1",
"replyToStoryId": "replyToStoryId 1",
"status": "queued",
"error": {
"code": "not_on_whatsapp",
"message": "message 1"
},
"metadata": {
"key": "value 1"
},
"sentAt": "2026-09-24T09:00:00.000Z",
"editedAt": "2026-09-24T09:00:00.000Z",
"deletedAt": "2026-09-24T09:00:00.000Z",
"createdAt": "2026-09-24T09:00:00.000Z",
"updatedAt": "2026-09-24T09:00:00.000Z"
}"#);
let api = support::MockApi::start(vec![support::Reply::status(503), support::Reply::json(200, response.clone())]).await;
let result = api.client().messages().star("m17d0a9w2sqc7k3v8x1n5ybr6t4hjp2e").await.unwrap();
support::assert_json(&result, &response);
let calls = api.calls().await;
assert_eq!(calls.len(), 2);
let key = calls[0].header(sdk::IDEMPOTENCY_HEADER).unwrap();
assert!(!key.is_empty());
assert_eq!(calls[1].header(sdk::IDEMPOTENCY_HEADER), Some(key));
assert_eq!(calls[0].body, calls[1].body);
}
#[tokio::test]
async fn unstar() {
let response = support::json(r#"{
"object": "message",
"id": "id 1",
"projectId": "projectId 1",
"accountId": "accountId 1",
"chatId": "chatId 1",
"chatType": "direct",
"direction": "inbound",
"source": "api",
"from": "from 1",
"to": "to 1",
"profileName": "profileName 1",
"username": "username 1",
"type": "text",
"text": "text 1",
"media": {
"url": "url 1",
"mimeType": "mimeType 1",
"filename": "filename 1",
"size": 1,
"width": 1,
"height": 1,
"durationSeconds": 1,
"gifPlayback": true,
"downloaded": true
},
"location": {
"latitude": 1.5,
"longitude": 1.5,
"name": "name 1",
"address": "address 1"
},
"contact": {
"name": "name 1",
"phone": "phone 1"
},
"contacts": [
{
"name": "name 1",
"phone": "phone 1"
}
],
"poll": {
"name": "name 1",
"options": [
{
"name": "name 1",
"voteCount": 1
}
],
"selectableCount": 1,
"voterCount": 1
},
"calendarEvent": {
"name": "name 1",
"description": "description 1",
"startsAt": "2026-09-24T09:00:00.000Z",
"endsAt": "2026-09-24T09:00:00.000Z",
"location": {
"name": "name 1",
"address": "address 1",
"latitude": 1.5,
"longitude": 1.5
},
"callType": "audio",
"joinUrl": "joinUrl 1",
"allowExtraGuests": true,
"cancelled": true
},
"mentions": [
"mentions 1"
],
"forwarded": true,
"forwardedManyTimes": true,
"viewOnce": true,
"starred": true,
"replyToMessageId": "replyToMessageId 1",
"replyToStoryId": "replyToStoryId 1",
"status": "queued",
"error": {
"code": "not_on_whatsapp",
"message": "message 1"
},
"metadata": {
"key": "value 1"
},
"sentAt": "2026-09-24T09:00:00.000Z",
"editedAt": "2026-09-24T09:00:00.000Z",
"deletedAt": "2026-09-24T09:00:00.000Z",
"createdAt": "2026-09-24T09:00:00.000Z",
"updatedAt": "2026-09-24T09:00:00.000Z"
}"#);
let api = support::MockApi::start(vec![support::Reply::json(200, response.clone())]).await;
let result = api.client().messages().unstar("m17d0a9w2sqc7k3v8x1n5ybr6t4hjp2e").await.unwrap();
support::assert_json(&result, &response);
let calls = api.calls().await;
assert_eq!(calls.len(), 1);
assert_eq!(calls[0].method, "POST");
assert_eq!(calls[0].path, "/v1/messages/m17d0a9w2sqc7k3v8x1n5ybr6t4hjp2e/unstar");
assert_eq!(calls[0].query, support::pairs(&[]));
assert!(calls[0].body.is_none());
assert!(calls[0].header(sdk::IDEMPOTENCY_HEADER).is_some_and(|key| !key.is_empty()));
}
#[tokio::test]
async fn unstar_retries_with_one_key() {
let response = support::json(r#"{
"object": "message",
"id": "id 1",
"projectId": "projectId 1",
"accountId": "accountId 1",
"chatId": "chatId 1",
"chatType": "direct",
"direction": "inbound",
"source": "api",
"from": "from 1",
"to": "to 1",
"profileName": "profileName 1",
"username": "username 1",
"type": "text",
"text": "text 1",
"media": {
"url": "url 1",
"mimeType": "mimeType 1",
"filename": "filename 1",
"size": 1,
"width": 1,
"height": 1,
"durationSeconds": 1,
"gifPlayback": true,
"downloaded": true
},
"location": {
"latitude": 1.5,
"longitude": 1.5,
"name": "name 1",
"address": "address 1"
},
"contact": {
"name": "name 1",
"phone": "phone 1"
},
"contacts": [
{
"name": "name 1",
"phone": "phone 1"
}
],
"poll": {
"name": "name 1",
"options": [
{
"name": "name 1",
"voteCount": 1
}
],
"selectableCount": 1,
"voterCount": 1
},
"calendarEvent": {
"name": "name 1",
"description": "description 1",
"startsAt": "2026-09-24T09:00:00.000Z",
"endsAt": "2026-09-24T09:00:00.000Z",
"location": {
"name": "name 1",
"address": "address 1",
"latitude": 1.5,
"longitude": 1.5
},
"callType": "audio",
"joinUrl": "joinUrl 1",
"allowExtraGuests": true,
"cancelled": true
},
"mentions": [
"mentions 1"
],
"forwarded": true,
"forwardedManyTimes": true,
"viewOnce": true,
"starred": true,
"replyToMessageId": "replyToMessageId 1",
"replyToStoryId": "replyToStoryId 1",
"status": "queued",
"error": {
"code": "not_on_whatsapp",
"message": "message 1"
},
"metadata": {
"key": "value 1"
},
"sentAt": "2026-09-24T09:00:00.000Z",
"editedAt": "2026-09-24T09:00:00.000Z",
"deletedAt": "2026-09-24T09:00:00.000Z",
"createdAt": "2026-09-24T09:00:00.000Z",
"updatedAt": "2026-09-24T09:00:00.000Z"
}"#);
let api = support::MockApi::start(vec![support::Reply::status(503), support::Reply::json(200, response.clone())]).await;
let result = api.client().messages().unstar("m17d0a9w2sqc7k3v8x1n5ybr6t4hjp2e").await.unwrap();
support::assert_json(&result, &response);
let calls = api.calls().await;
assert_eq!(calls.len(), 2);
let key = calls[0].header(sdk::IDEMPOTENCY_HEADER).unwrap();
assert!(!key.is_empty());
assert_eq!(calls[1].header(sdk::IDEMPOTENCY_HEADER), Some(key));
assert_eq!(calls[0].body, calls[1].body);
}
#[tokio::test]
async fn add_label() {
let api = support::MockApi::start(vec![support::Reply::status(204)]).await;
let params: types::MessagesAddLabelParams = support::from_json(r#"{"labelId":"labelId 1"}"#);
api.client().messages().add_label("m17d0a9w2sqc7k3v8x1n5ybr6t4hjp2e", params).await.unwrap();
let calls = api.calls().await;
assert_eq!(calls.len(), 1);
assert_eq!(calls[0].method, "POST");
assert_eq!(calls[0].path, "/v1/messages/m17d0a9w2sqc7k3v8x1n5ybr6t4hjp2e/labels");
assert_eq!(calls[0].query, support::pairs(&[]));
support::assert_json(&calls[0].body, &support::json(r#"{"labelId":"labelId 1"}"#));
assert!(calls[0].header(sdk::IDEMPOTENCY_HEADER).is_some_and(|key| !key.is_empty()));
}
#[tokio::test]
async fn add_label_retries_with_one_key() {
let api = support::MockApi::start(vec![support::Reply::status(503), support::Reply::status(204)]).await;
let params: types::MessagesAddLabelParams = support::from_json(r#"{"labelId":"labelId 1"}"#);
api.client().messages().add_label("m17d0a9w2sqc7k3v8x1n5ybr6t4hjp2e", params).await.unwrap();
let calls = api.calls().await;
assert_eq!(calls.len(), 2);
let key = calls[0].header(sdk::IDEMPOTENCY_HEADER).unwrap();
assert!(!key.is_empty());
assert_eq!(calls[1].header(sdk::IDEMPOTENCY_HEADER), Some(key));
assert_eq!(calls[0].body, calls[1].body);
}
#[tokio::test]
async fn remove_label() {
let api = support::MockApi::start(vec![support::Reply::status(204)]).await;
api.client().messages().remove_label("m17d0a9w2sqc7k3v8x1n5ybr6t4hjp2e", "5").await.unwrap();
let calls = api.calls().await;
assert_eq!(calls.len(), 1);
assert_eq!(calls[0].method, "DELETE");
assert_eq!(calls[0].path, "/v1/messages/m17d0a9w2sqc7k3v8x1n5ybr6t4hjp2e/labels/5");
assert_eq!(calls[0].query, support::pairs(&[]));
assert!(calls[0].body.is_none());
assert!(calls[0].header(sdk::IDEMPOTENCY_HEADER).is_none());
}
}
mod stories {
use super::*;
#[tokio::test]
async fn create() {
let response = support::json(r#"{
"object": "message",
"id": "id 1",
"projectId": "projectId 1",
"accountId": "accountId 1",
"chatId": "chatId 1",
"chatType": "direct",
"direction": "inbound",
"source": "api",
"from": "from 1",
"to": "to 1",
"profileName": "profileName 1",
"username": "username 1",
"type": "text",
"text": "text 1",
"media": {
"url": "url 1",
"mimeType": "mimeType 1",
"filename": "filename 1",
"size": 1,
"width": 1,
"height": 1,
"durationSeconds": 1,
"gifPlayback": true,
"downloaded": true
},
"location": {
"latitude": 1.5,
"longitude": 1.5,
"name": "name 1",
"address": "address 1"
},
"contact": {
"name": "name 1",
"phone": "phone 1"
},
"contacts": [
{
"name": "name 1",
"phone": "phone 1"
}
],
"poll": {
"name": "name 1",
"options": [
{
"name": "name 1",
"voteCount": 1
}
],
"selectableCount": 1,
"voterCount": 1
},
"calendarEvent": {
"name": "name 1",
"description": "description 1",
"startsAt": "2026-09-24T09:00:00.000Z",
"endsAt": "2026-09-24T09:00:00.000Z",
"location": {
"name": "name 1",
"address": "address 1",
"latitude": 1.5,
"longitude": 1.5
},
"callType": "audio",
"joinUrl": "joinUrl 1",
"allowExtraGuests": true,
"cancelled": true
},
"mentions": [
"mentions 1"
],
"forwarded": true,
"forwardedManyTimes": true,
"viewOnce": true,
"starred": true,
"replyToMessageId": "replyToMessageId 1",
"replyToStoryId": "replyToStoryId 1",
"status": "queued",
"error": {
"code": "not_on_whatsapp",
"message": "message 1"
},
"metadata": {
"key": "value 1"
},
"sentAt": "2026-09-24T09:00:00.000Z",
"editedAt": "2026-09-24T09:00:00.000Z",
"deletedAt": "2026-09-24T09:00:00.000Z",
"createdAt": "2026-09-24T09:00:00.000Z",
"updatedAt": "2026-09-24T09:00:00.000Z"
}"#);
let api = support::MockApi::start(vec![support::Reply::json(202, response.clone())]).await;
let params: types::StoriesCreateParams = support::from_json(r#"{"type":"text","text":"text 1","backgroundColor":"backgroundColor 1","font":0}"#);
let result = api.client().stories().create("k57a8m2x9d3f0q1wjh6ypc4n2d7s0vbr", params).await.unwrap();
support::assert_json(&result, &response);
let calls = api.calls().await;
assert_eq!(calls.len(), 1);
assert_eq!(calls[0].method, "POST");
assert_eq!(calls[0].path, "/v1/accounts/k57a8m2x9d3f0q1wjh6ypc4n2d7s0vbr/stories");
assert_eq!(calls[0].query, support::pairs(&[]));
support::assert_json(&calls[0].body, &support::json(r#"{"type":"text","text":"text 1","backgroundColor":"backgroundColor 1","font":0}"#));
assert!(calls[0].header(sdk::IDEMPOTENCY_HEADER).is_some_and(|key| !key.is_empty()));
}
#[tokio::test]
async fn create_retries_with_one_key() {
let response = support::json(r#"{
"object": "message",
"id": "id 1",
"projectId": "projectId 1",
"accountId": "accountId 1",
"chatId": "chatId 1",
"chatType": "direct",
"direction": "inbound",
"source": "api",
"from": "from 1",
"to": "to 1",
"profileName": "profileName 1",
"username": "username 1",
"type": "text",
"text": "text 1",
"media": {
"url": "url 1",
"mimeType": "mimeType 1",
"filename": "filename 1",
"size": 1,
"width": 1,
"height": 1,
"durationSeconds": 1,
"gifPlayback": true,
"downloaded": true
},
"location": {
"latitude": 1.5,
"longitude": 1.5,
"name": "name 1",
"address": "address 1"
},
"contact": {
"name": "name 1",
"phone": "phone 1"
},
"contacts": [
{
"name": "name 1",
"phone": "phone 1"
}
],
"poll": {
"name": "name 1",
"options": [
{
"name": "name 1",
"voteCount": 1
}
],
"selectableCount": 1,
"voterCount": 1
},
"calendarEvent": {
"name": "name 1",
"description": "description 1",
"startsAt": "2026-09-24T09:00:00.000Z",
"endsAt": "2026-09-24T09:00:00.000Z",
"location": {
"name": "name 1",
"address": "address 1",
"latitude": 1.5,
"longitude": 1.5
},
"callType": "audio",
"joinUrl": "joinUrl 1",
"allowExtraGuests": true,
"cancelled": true
},
"mentions": [
"mentions 1"
],
"forwarded": true,
"forwardedManyTimes": true,
"viewOnce": true,
"starred": true,
"replyToMessageId": "replyToMessageId 1",
"replyToStoryId": "replyToStoryId 1",
"status": "queued",
"error": {
"code": "not_on_whatsapp",
"message": "message 1"
},
"metadata": {
"key": "value 1"
},
"sentAt": "2026-09-24T09:00:00.000Z",
"editedAt": "2026-09-24T09:00:00.000Z",
"deletedAt": "2026-09-24T09:00:00.000Z",
"createdAt": "2026-09-24T09:00:00.000Z",
"updatedAt": "2026-09-24T09:00:00.000Z"
}"#);
let api = support::MockApi::start(vec![support::Reply::status(503), support::Reply::json(202, response.clone())]).await;
let params: types::StoriesCreateParams = support::from_json(r#"{"type":"text","text":"text 1","backgroundColor":"backgroundColor 1","font":0}"#);
let result = api.client().stories().create("k57a8m2x9d3f0q1wjh6ypc4n2d7s0vbr", params).await.unwrap();
support::assert_json(&result, &response);
let calls = api.calls().await;
assert_eq!(calls.len(), 2);
let key = calls[0].header(sdk::IDEMPOTENCY_HEADER).unwrap();
assert!(!key.is_empty());
assert_eq!(calls[1].header(sdk::IDEMPOTENCY_HEADER), Some(key));
assert_eq!(calls[0].body, calls[1].body);
}
#[tokio::test]
async fn list_streams_every_page() {
let first = support::json(r#"{
"object": "list",
"items": [
{
"object": "story_group",
"accountId": "accountId 1",
"contactId": "contactId 1",
"profileName": "profileName 1",
"username": "username 1",
"muted": true,
"storyCount": 1,
"unviewedCount": 1,
"lastPostedAt": "2026-09-24T09:00:00.000Z",
"stories": [
{
"object": "story",
"id": "id 1",
"projectId": "projectId 1",
"accountId": "accountId 1",
"contactId": "contactId 1",
"own": true,
"profileName": "profileName 1",
"username": "username 1",
"type": "text",
"text": "text 1",
"backgroundColor": "backgroundColor 1",
"font": 1,
"media": {
"url": "url 1",
"mimeType": "mimeType 1",
"filename": "filename 1",
"size": 1,
"width": 1,
"height": 1,
"durationSeconds": 1,
"gifPlayback": true,
"downloaded": true
},
"status": "queued",
"viewedAt": "2026-09-24T09:00:00.000Z",
"authorNotified": true,
"reaction": "reaction 1",
"viewCount": 1,
"postedAt": "2026-09-24T09:00:00.000Z",
"expiresAt": "2026-09-24T09:00:00.000Z",
"deletedAt": "2026-09-24T09:00:00.000Z",
"createdAt": "2026-09-24T09:00:00.000Z"
}
]
}
],
"nextCursor": "cursor_2"
}"#);
let last = support::json(r#"{
"object": "list",
"items": [
{
"object": "story_group",
"accountId": "accountId 1",
"contactId": "contactId 1",
"profileName": "profileName 1",
"username": "username 1",
"muted": true,
"storyCount": 1,
"unviewedCount": 1,
"lastPostedAt": "2026-09-24T09:00:00.000Z",
"stories": [
{
"object": "story",
"id": "id 1",
"projectId": "projectId 1",
"accountId": "accountId 1",
"contactId": "contactId 1",
"own": true,
"profileName": "profileName 1",
"username": "username 1",
"type": "text",
"text": "text 1",
"backgroundColor": "backgroundColor 1",
"font": 1,
"media": {
"url": "url 1",
"mimeType": "mimeType 1",
"filename": "filename 1",
"size": 1,
"width": 1,
"height": 1,
"durationSeconds": 1,
"gifPlayback": true,
"downloaded": true
},
"status": "queued",
"viewedAt": "2026-09-24T09:00:00.000Z",
"authorNotified": true,
"reaction": "reaction 1",
"viewCount": 1,
"postedAt": "2026-09-24T09:00:00.000Z",
"expiresAt": "2026-09-24T09:00:00.000Z",
"deletedAt": "2026-09-24T09:00:00.000Z",
"createdAt": "2026-09-24T09:00:00.000Z"
}
]
}
],
"nextCursor": null
}"#);
let api = support::MockApi::start(vec![
support::Reply::json(200, first),
support::Reply::json(200, last),
])
.await;
let params: types::StoriesListParams = support::from_json(r#"{"contactId":"contactId 1","unviewed":true,"limit":50,"cursor":"cursor 1"}"#);
let items = api.client().stories().list("k57a8m2x9d3f0q1wjh6ypc4n2d7s0vbr", params).to_vec().await.unwrap();
support::assert_json(&items, &support::json(r#"[
{
"object": "story_group",
"accountId": "accountId 1",
"contactId": "contactId 1",
"profileName": "profileName 1",
"username": "username 1",
"muted": true,
"storyCount": 1,
"unviewedCount": 1,
"lastPostedAt": "2026-09-24T09:00:00.000Z",
"stories": [
{
"object": "story",
"id": "id 1",
"projectId": "projectId 1",
"accountId": "accountId 1",
"contactId": "contactId 1",
"own": true,
"profileName": "profileName 1",
"username": "username 1",
"type": "text",
"text": "text 1",
"backgroundColor": "backgroundColor 1",
"font": 1,
"media": {
"url": "url 1",
"mimeType": "mimeType 1",
"filename": "filename 1",
"size": 1,
"width": 1,
"height": 1,
"durationSeconds": 1,
"gifPlayback": true,
"downloaded": true
},
"status": "queued",
"viewedAt": "2026-09-24T09:00:00.000Z",
"authorNotified": true,
"reaction": "reaction 1",
"viewCount": 1,
"postedAt": "2026-09-24T09:00:00.000Z",
"expiresAt": "2026-09-24T09:00:00.000Z",
"deletedAt": "2026-09-24T09:00:00.000Z",
"createdAt": "2026-09-24T09:00:00.000Z"
}
]
},
{
"object": "story_group",
"accountId": "accountId 1",
"contactId": "contactId 1",
"profileName": "profileName 1",
"username": "username 1",
"muted": true,
"storyCount": 1,
"unviewedCount": 1,
"lastPostedAt": "2026-09-24T09:00:00.000Z",
"stories": [
{
"object": "story",
"id": "id 1",
"projectId": "projectId 1",
"accountId": "accountId 1",
"contactId": "contactId 1",
"own": true,
"profileName": "profileName 1",
"username": "username 1",
"type": "text",
"text": "text 1",
"backgroundColor": "backgroundColor 1",
"font": 1,
"media": {
"url": "url 1",
"mimeType": "mimeType 1",
"filename": "filename 1",
"size": 1,
"width": 1,
"height": 1,
"durationSeconds": 1,
"gifPlayback": true,
"downloaded": true
},
"status": "queued",
"viewedAt": "2026-09-24T09:00:00.000Z",
"authorNotified": true,
"reaction": "reaction 1",
"viewCount": 1,
"postedAt": "2026-09-24T09:00:00.000Z",
"expiresAt": "2026-09-24T09:00:00.000Z",
"deletedAt": "2026-09-24T09:00:00.000Z",
"createdAt": "2026-09-24T09:00:00.000Z"
}
]
}
]"#));
let calls = api.calls().await;
assert_eq!(calls.len(), 2);
assert_eq!(calls[0].method, "GET");
assert_eq!(calls[0].path, "/v1/accounts/k57a8m2x9d3f0q1wjh6ypc4n2d7s0vbr/stories");
assert_eq!(calls[0].query, support::pairs(&[("contactId", "contactId 1"), ("unviewed", "true"), ("limit", "50"), ("cursor", "cursor 1")]));
assert_eq!(calls[1].query, support::pairs(&[("contactId", "contactId 1"), ("unviewed", "true"), ("limit", "50"), ("cursor", "cursor_2")]));
}
#[tokio::test]
async fn list_fetches_one_page() {
let page = support::json(r#"{
"object": "list",
"items": [
{
"object": "story_group",
"accountId": "accountId 1",
"contactId": "contactId 1",
"profileName": "profileName 1",
"username": "username 1",
"muted": true,
"storyCount": 1,
"unviewedCount": 1,
"lastPostedAt": "2026-09-24T09:00:00.000Z",
"stories": [
{
"object": "story",
"id": "id 1",
"projectId": "projectId 1",
"accountId": "accountId 1",
"contactId": "contactId 1",
"own": true,
"profileName": "profileName 1",
"username": "username 1",
"type": "text",
"text": "text 1",
"backgroundColor": "backgroundColor 1",
"font": 1,
"media": {
"url": "url 1",
"mimeType": "mimeType 1",
"filename": "filename 1",
"size": 1,
"width": 1,
"height": 1,
"durationSeconds": 1,
"gifPlayback": true,
"downloaded": true
},
"status": "queued",
"viewedAt": "2026-09-24T09:00:00.000Z",
"authorNotified": true,
"reaction": "reaction 1",
"viewCount": 1,
"postedAt": "2026-09-24T09:00:00.000Z",
"expiresAt": "2026-09-24T09:00:00.000Z",
"deletedAt": "2026-09-24T09:00:00.000Z",
"createdAt": "2026-09-24T09:00:00.000Z"
}
]
}
],
"nextCursor": null
}"#);
let api = support::MockApi::start(vec![support::Reply::json(200, page.clone())]).await;
let result = api.client().stories().list("k57a8m2x9d3f0q1wjh6ypc4n2d7s0vbr", Default::default()).page().await.unwrap();
support::assert_json(&result, &page);
let calls = api.calls().await;
assert_eq!(calls.len(), 1);
assert_eq!(calls[0].method, "GET");
assert_eq!(calls[0].path, "/v1/accounts/k57a8m2x9d3f0q1wjh6ypc4n2d7s0vbr/stories");
assert_eq!(calls[0].query, support::pairs(&[]));
}
#[tokio::test]
async fn list_own_streams_every_page() {
let first = support::json(r#"{
"object": "list",
"items": [
{
"object": "story",
"id": "id 1",
"projectId": "projectId 1",
"accountId": "accountId 1",
"contactId": "contactId 1",
"own": true,
"profileName": "profileName 1",
"username": "username 1",
"type": "text",
"text": "text 1",
"backgroundColor": "backgroundColor 1",
"font": 1,
"media": {
"url": "url 1",
"mimeType": "mimeType 1",
"filename": "filename 1",
"size": 1,
"width": 1,
"height": 1,
"durationSeconds": 1,
"gifPlayback": true,
"downloaded": true
},
"status": "queued",
"viewedAt": "2026-09-24T09:00:00.000Z",
"authorNotified": true,
"reaction": "reaction 1",
"viewCount": 1,
"postedAt": "2026-09-24T09:00:00.000Z",
"expiresAt": "2026-09-24T09:00:00.000Z",
"deletedAt": "2026-09-24T09:00:00.000Z",
"createdAt": "2026-09-24T09:00:00.000Z"
}
],
"nextCursor": "cursor_2"
}"#);
let last = support::json(r#"{
"object": "list",
"items": [
{
"object": "story",
"id": "id 1",
"projectId": "projectId 1",
"accountId": "accountId 1",
"contactId": "contactId 1",
"own": true,
"profileName": "profileName 1",
"username": "username 1",
"type": "text",
"text": "text 1",
"backgroundColor": "backgroundColor 1",
"font": 1,
"media": {
"url": "url 1",
"mimeType": "mimeType 1",
"filename": "filename 1",
"size": 1,
"width": 1,
"height": 1,
"durationSeconds": 1,
"gifPlayback": true,
"downloaded": true
},
"status": "queued",
"viewedAt": "2026-09-24T09:00:00.000Z",
"authorNotified": true,
"reaction": "reaction 1",
"viewCount": 1,
"postedAt": "2026-09-24T09:00:00.000Z",
"expiresAt": "2026-09-24T09:00:00.000Z",
"deletedAt": "2026-09-24T09:00:00.000Z",
"createdAt": "2026-09-24T09:00:00.000Z"
}
],
"nextCursor": null
}"#);
let api = support::MockApi::start(vec![
support::Reply::json(200, first),
support::Reply::json(200, last),
])
.await;
let params: types::StoriesListOwnParams = support::from_json(r#"{"limit":50,"cursor":"cursor 1"}"#);
let items = api.client().stories().list_own("k57a8m2x9d3f0q1wjh6ypc4n2d7s0vbr", params).to_vec().await.unwrap();
support::assert_json(&items, &support::json(r#"[
{
"object": "story",
"id": "id 1",
"projectId": "projectId 1",
"accountId": "accountId 1",
"contactId": "contactId 1",
"own": true,
"profileName": "profileName 1",
"username": "username 1",
"type": "text",
"text": "text 1",
"backgroundColor": "backgroundColor 1",
"font": 1,
"media": {
"url": "url 1",
"mimeType": "mimeType 1",
"filename": "filename 1",
"size": 1,
"width": 1,
"height": 1,
"durationSeconds": 1,
"gifPlayback": true,
"downloaded": true
},
"status": "queued",
"viewedAt": "2026-09-24T09:00:00.000Z",
"authorNotified": true,
"reaction": "reaction 1",
"viewCount": 1,
"postedAt": "2026-09-24T09:00:00.000Z",
"expiresAt": "2026-09-24T09:00:00.000Z",
"deletedAt": "2026-09-24T09:00:00.000Z",
"createdAt": "2026-09-24T09:00:00.000Z"
},
{
"object": "story",
"id": "id 1",
"projectId": "projectId 1",
"accountId": "accountId 1",
"contactId": "contactId 1",
"own": true,
"profileName": "profileName 1",
"username": "username 1",
"type": "text",
"text": "text 1",
"backgroundColor": "backgroundColor 1",
"font": 1,
"media": {
"url": "url 1",
"mimeType": "mimeType 1",
"filename": "filename 1",
"size": 1,
"width": 1,
"height": 1,
"durationSeconds": 1,
"gifPlayback": true,
"downloaded": true
},
"status": "queued",
"viewedAt": "2026-09-24T09:00:00.000Z",
"authorNotified": true,
"reaction": "reaction 1",
"viewCount": 1,
"postedAt": "2026-09-24T09:00:00.000Z",
"expiresAt": "2026-09-24T09:00:00.000Z",
"deletedAt": "2026-09-24T09:00:00.000Z",
"createdAt": "2026-09-24T09:00:00.000Z"
}
]"#));
let calls = api.calls().await;
assert_eq!(calls.len(), 2);
assert_eq!(calls[0].method, "GET");
assert_eq!(calls[0].path, "/v1/accounts/k57a8m2x9d3f0q1wjh6ypc4n2d7s0vbr/stories/own");
assert_eq!(calls[0].query, support::pairs(&[("limit", "50"), ("cursor", "cursor 1")]));
assert_eq!(calls[1].query, support::pairs(&[("limit", "50"), ("cursor", "cursor_2")]));
}
#[tokio::test]
async fn list_own_fetches_one_page() {
let page = support::json(r#"{
"object": "list",
"items": [
{
"object": "story",
"id": "id 1",
"projectId": "projectId 1",
"accountId": "accountId 1",
"contactId": "contactId 1",
"own": true,
"profileName": "profileName 1",
"username": "username 1",
"type": "text",
"text": "text 1",
"backgroundColor": "backgroundColor 1",
"font": 1,
"media": {
"url": "url 1",
"mimeType": "mimeType 1",
"filename": "filename 1",
"size": 1,
"width": 1,
"height": 1,
"durationSeconds": 1,
"gifPlayback": true,
"downloaded": true
},
"status": "queued",
"viewedAt": "2026-09-24T09:00:00.000Z",
"authorNotified": true,
"reaction": "reaction 1",
"viewCount": 1,
"postedAt": "2026-09-24T09:00:00.000Z",
"expiresAt": "2026-09-24T09:00:00.000Z",
"deletedAt": "2026-09-24T09:00:00.000Z",
"createdAt": "2026-09-24T09:00:00.000Z"
}
],
"nextCursor": null
}"#);
let api = support::MockApi::start(vec![support::Reply::json(200, page.clone())]).await;
let result = api.client().stories().list_own("k57a8m2x9d3f0q1wjh6ypc4n2d7s0vbr", Default::default()).page().await.unwrap();
support::assert_json(&result, &page);
let calls = api.calls().await;
assert_eq!(calls.len(), 1);
assert_eq!(calls[0].method, "GET");
assert_eq!(calls[0].path, "/v1/accounts/k57a8m2x9d3f0q1wjh6ypc4n2d7s0vbr/stories/own");
assert_eq!(calls[0].query, support::pairs(&[]));
}
#[tokio::test]
async fn get() {
let response = support::json(r#"{
"object": "story",
"id": "id 1",
"projectId": "projectId 1",
"accountId": "accountId 1",
"contactId": "contactId 1",
"own": true,
"profileName": "profileName 1",
"username": "username 1",
"type": "text",
"text": "text 1",
"backgroundColor": "backgroundColor 1",
"font": 1,
"media": {
"url": "url 1",
"mimeType": "mimeType 1",
"filename": "filename 1",
"size": 1,
"width": 1,
"height": 1,
"durationSeconds": 1,
"gifPlayback": true,
"downloaded": true
},
"status": "queued",
"viewedAt": "2026-09-24T09:00:00.000Z",
"authorNotified": true,
"reaction": "reaction 1",
"viewCount": 1,
"postedAt": "2026-09-24T09:00:00.000Z",
"expiresAt": "2026-09-24T09:00:00.000Z",
"deletedAt": "2026-09-24T09:00:00.000Z",
"createdAt": "2026-09-24T09:00:00.000Z"
}"#);
let api = support::MockApi::start(vec![support::Reply::json(200, response.clone())]).await;
let result = api.client().stories().get("k57a8m2x9d3f0q1wjh6ypc4n2d7s0vbr", "s97fd2k4w8qc1n5x7v3b9yt6r0hjm2ea").await.unwrap();
support::assert_json(&result, &response);
let calls = api.calls().await;
assert_eq!(calls.len(), 1);
assert_eq!(calls[0].method, "GET");
assert_eq!(calls[0].path, "/v1/accounts/k57a8m2x9d3f0q1wjh6ypc4n2d7s0vbr/stories/s97fd2k4w8qc1n5x7v3b9yt6r0hjm2ea");
assert_eq!(calls[0].query, support::pairs(&[]));
assert!(calls[0].body.is_none());
assert!(calls[0].header(sdk::IDEMPOTENCY_HEADER).is_none());
}
#[tokio::test]
async fn get_media() {
let response = support::json(r#"{
"object": "media",
"storyId": "storyId 1",
"url": "url 1",
"mimeType": "mimeType 1",
"filename": "filename 1",
"size": 1
}"#);
let api = support::MockApi::start(vec![support::Reply::json(200, response.clone())]).await;
let params: types::StoriesGetMediaParams = support::from_json(r#"{"redirect":true}"#);
let result = api.client().stories().get_media("k57a8m2x9d3f0q1wjh6ypc4n2d7s0vbr", "s97fd2k4w8qc1n5x7v3b9yt6r0hjm2ea", params).await.unwrap();
support::assert_json(&result, &response);
let calls = api.calls().await;
assert_eq!(calls.len(), 1);
assert_eq!(calls[0].method, "GET");
assert_eq!(calls[0].path, "/v1/accounts/k57a8m2x9d3f0q1wjh6ypc4n2d7s0vbr/stories/s97fd2k4w8qc1n5x7v3b9yt6r0hjm2ea/media");
assert_eq!(calls[0].query, support::pairs(&[("redirect", "true")]));
assert!(calls[0].body.is_none());
assert!(calls[0].header(sdk::IDEMPOTENCY_HEADER).is_none());
}
#[tokio::test]
async fn get_media_without_params() {
let response = support::json(r#"{
"object": "media",
"storyId": "storyId 1",
"url": "url 1",
"mimeType": "mimeType 1",
"filename": "filename 1",
"size": 1
}"#);
let api = support::MockApi::start(vec![support::Reply::json(200, response.clone())]).await;
let result = api.client().stories().get_media("k57a8m2x9d3f0q1wjh6ypc4n2d7s0vbr", "s97fd2k4w8qc1n5x7v3b9yt6r0hjm2ea", Default::default()).await.unwrap();
support::assert_json(&result, &response);
let calls = api.calls().await;
assert_eq!(calls.len(), 1);
assert_eq!(calls[0].method, "GET");
assert_eq!(calls[0].path, "/v1/accounts/k57a8m2x9d3f0q1wjh6ypc4n2d7s0vbr/stories/s97fd2k4w8qc1n5x7v3b9yt6r0hjm2ea/media");
assert_eq!(calls[0].query, support::pairs(&[]));
assert!(calls[0].body.is_none());
assert!(calls[0].header(sdk::IDEMPOTENCY_HEADER).is_none());
}
#[tokio::test]
async fn list_viewers_streams_every_page() {
let first = support::json(r#"{
"object": "list",
"items": [
{
"object": "story_viewer",
"accountId": "accountId 1",
"storyId": "storyId 1",
"contactId": "contactId 1",
"viewedAt": "2026-09-24T09:00:00.000Z",
"reaction": "reaction 1",
"reactedAt": "2026-09-24T09:00:00.000Z"
}
],
"nextCursor": "cursor_2"
}"#);
let last = support::json(r#"{
"object": "list",
"items": [
{
"object": "story_viewer",
"accountId": "accountId 1",
"storyId": "storyId 1",
"contactId": "contactId 1",
"viewedAt": "2026-09-24T09:00:00.000Z",
"reaction": "reaction 1",
"reactedAt": "2026-09-24T09:00:00.000Z"
}
],
"nextCursor": null
}"#);
let api = support::MockApi::start(vec![
support::Reply::json(200, first),
support::Reply::json(200, last),
])
.await;
let params: types::StoriesListViewersParams = support::from_json(r#"{"limit":50,"cursor":"cursor 1"}"#);
let items = api.client().stories().list_viewers("k57a8m2x9d3f0q1wjh6ypc4n2d7s0vbr", "s97fd2k4w8qc1n5x7v3b9yt6r0hjm2ea", params).to_vec().await.unwrap();
support::assert_json(&items, &support::json(r#"[
{
"object": "story_viewer",
"accountId": "accountId 1",
"storyId": "storyId 1",
"contactId": "contactId 1",
"viewedAt": "2026-09-24T09:00:00.000Z",
"reaction": "reaction 1",
"reactedAt": "2026-09-24T09:00:00.000Z"
},
{
"object": "story_viewer",
"accountId": "accountId 1",
"storyId": "storyId 1",
"contactId": "contactId 1",
"viewedAt": "2026-09-24T09:00:00.000Z",
"reaction": "reaction 1",
"reactedAt": "2026-09-24T09:00:00.000Z"
}
]"#));
let calls = api.calls().await;
assert_eq!(calls.len(), 2);
assert_eq!(calls[0].method, "GET");
assert_eq!(calls[0].path, "/v1/accounts/k57a8m2x9d3f0q1wjh6ypc4n2d7s0vbr/stories/s97fd2k4w8qc1n5x7v3b9yt6r0hjm2ea/viewers");
assert_eq!(calls[0].query, support::pairs(&[("limit", "50"), ("cursor", "cursor 1")]));
assert_eq!(calls[1].query, support::pairs(&[("limit", "50"), ("cursor", "cursor_2")]));
}
#[tokio::test]
async fn list_viewers_fetches_one_page() {
let page = support::json(r#"{
"object": "list",
"items": [
{
"object": "story_viewer",
"accountId": "accountId 1",
"storyId": "storyId 1",
"contactId": "contactId 1",
"viewedAt": "2026-09-24T09:00:00.000Z",
"reaction": "reaction 1",
"reactedAt": "2026-09-24T09:00:00.000Z"
}
],
"nextCursor": null
}"#);
let api = support::MockApi::start(vec![support::Reply::json(200, page.clone())]).await;
let result = api.client().stories().list_viewers("k57a8m2x9d3f0q1wjh6ypc4n2d7s0vbr", "s97fd2k4w8qc1n5x7v3b9yt6r0hjm2ea", Default::default()).page().await.unwrap();
support::assert_json(&result, &page);
let calls = api.calls().await;
assert_eq!(calls.len(), 1);
assert_eq!(calls[0].method, "GET");
assert_eq!(calls[0].path, "/v1/accounts/k57a8m2x9d3f0q1wjh6ypc4n2d7s0vbr/stories/s97fd2k4w8qc1n5x7v3b9yt6r0hjm2ea/viewers");
assert_eq!(calls[0].query, support::pairs(&[]));
}
#[tokio::test]
async fn view() {
let response = support::json(r#"{
"object": "story",
"id": "id 1",
"projectId": "projectId 1",
"accountId": "accountId 1",
"contactId": "contactId 1",
"own": true,
"profileName": "profileName 1",
"username": "username 1",
"type": "text",
"text": "text 1",
"backgroundColor": "backgroundColor 1",
"font": 1,
"media": {
"url": "url 1",
"mimeType": "mimeType 1",
"filename": "filename 1",
"size": 1,
"width": 1,
"height": 1,
"durationSeconds": 1,
"gifPlayback": true,
"downloaded": true
},
"status": "queued",
"viewedAt": "2026-09-24T09:00:00.000Z",
"authorNotified": true,
"reaction": "reaction 1",
"viewCount": 1,
"postedAt": "2026-09-24T09:00:00.000Z",
"expiresAt": "2026-09-24T09:00:00.000Z",
"deletedAt": "2026-09-24T09:00:00.000Z",
"createdAt": "2026-09-24T09:00:00.000Z"
}"#);
let api = support::MockApi::start(vec![support::Reply::json(200, response.clone())]).await;
let result = api.client().stories().view("k57a8m2x9d3f0q1wjh6ypc4n2d7s0vbr", "s97fd2k4w8qc1n5x7v3b9yt6r0hjm2ea").await.unwrap();
support::assert_json(&result, &response);
let calls = api.calls().await;
assert_eq!(calls.len(), 1);
assert_eq!(calls[0].method, "POST");
assert_eq!(calls[0].path, "/v1/accounts/k57a8m2x9d3f0q1wjh6ypc4n2d7s0vbr/stories/s97fd2k4w8qc1n5x7v3b9yt6r0hjm2ea/view");
assert_eq!(calls[0].query, support::pairs(&[]));
assert!(calls[0].body.is_none());
assert!(calls[0].header(sdk::IDEMPOTENCY_HEADER).is_some_and(|key| !key.is_empty()));
}
#[tokio::test]
async fn view_retries_with_one_key() {
let response = support::json(r#"{
"object": "story",
"id": "id 1",
"projectId": "projectId 1",
"accountId": "accountId 1",
"contactId": "contactId 1",
"own": true,
"profileName": "profileName 1",
"username": "username 1",
"type": "text",
"text": "text 1",
"backgroundColor": "backgroundColor 1",
"font": 1,
"media": {
"url": "url 1",
"mimeType": "mimeType 1",
"filename": "filename 1",
"size": 1,
"width": 1,
"height": 1,
"durationSeconds": 1,
"gifPlayback": true,
"downloaded": true
},
"status": "queued",
"viewedAt": "2026-09-24T09:00:00.000Z",
"authorNotified": true,
"reaction": "reaction 1",
"viewCount": 1,
"postedAt": "2026-09-24T09:00:00.000Z",
"expiresAt": "2026-09-24T09:00:00.000Z",
"deletedAt": "2026-09-24T09:00:00.000Z",
"createdAt": "2026-09-24T09:00:00.000Z"
}"#);
let api = support::MockApi::start(vec![support::Reply::status(503), support::Reply::json(200, response.clone())]).await;
let result = api.client().stories().view("k57a8m2x9d3f0q1wjh6ypc4n2d7s0vbr", "s97fd2k4w8qc1n5x7v3b9yt6r0hjm2ea").await.unwrap();
support::assert_json(&result, &response);
let calls = api.calls().await;
assert_eq!(calls.len(), 2);
let key = calls[0].header(sdk::IDEMPOTENCY_HEADER).unwrap();
assert!(!key.is_empty());
assert_eq!(calls[1].header(sdk::IDEMPOTENCY_HEADER), Some(key));
assert_eq!(calls[0].body, calls[1].body);
}
#[tokio::test]
async fn react() {
let api = support::MockApi::start(vec![support::Reply::status(204)]).await;
let params: types::StoriesReactParams = support::from_json(r#"{"emoji":"emoji 1"}"#);
api.client().stories().react("k57a8m2x9d3f0q1wjh6ypc4n2d7s0vbr", "s97fd2k4w8qc1n5x7v3b9yt6r0hjm2ea", params).await.unwrap();
let calls = api.calls().await;
assert_eq!(calls.len(), 1);
assert_eq!(calls[0].method, "POST");
assert_eq!(calls[0].path, "/v1/accounts/k57a8m2x9d3f0q1wjh6ypc4n2d7s0vbr/stories/s97fd2k4w8qc1n5x7v3b9yt6r0hjm2ea/react");
assert_eq!(calls[0].query, support::pairs(&[]));
support::assert_json(&calls[0].body, &support::json(r#"{"emoji":"emoji 1"}"#));
assert!(calls[0].header(sdk::IDEMPOTENCY_HEADER).is_some_and(|key| !key.is_empty()));
}
#[tokio::test]
async fn react_retries_with_one_key() {
let api = support::MockApi::start(vec![support::Reply::status(503), support::Reply::status(204)]).await;
let params: types::StoriesReactParams = support::from_json(r#"{"emoji":"emoji 1"}"#);
api.client().stories().react("k57a8m2x9d3f0q1wjh6ypc4n2d7s0vbr", "s97fd2k4w8qc1n5x7v3b9yt6r0hjm2ea", params).await.unwrap();
let calls = api.calls().await;
assert_eq!(calls.len(), 2);
let key = calls[0].header(sdk::IDEMPOTENCY_HEADER).unwrap();
assert!(!key.is_empty());
assert_eq!(calls[1].header(sdk::IDEMPOTENCY_HEADER), Some(key));
assert_eq!(calls[0].body, calls[1].body);
}
#[tokio::test]
async fn delete() {
let api = support::MockApi::start(vec![support::Reply::status(204)]).await;
api.client().stories().delete("k57a8m2x9d3f0q1wjh6ypc4n2d7s0vbr", "s97fd2k4w8qc1n5x7v3b9yt6r0hjm2ea").await.unwrap();
let calls = api.calls().await;
assert_eq!(calls.len(), 1);
assert_eq!(calls[0].method, "DELETE");
assert_eq!(calls[0].path, "/v1/accounts/k57a8m2x9d3f0q1wjh6ypc4n2d7s0vbr/stories/s97fd2k4w8qc1n5x7v3b9yt6r0hjm2ea");
assert_eq!(calls[0].query, support::pairs(&[]));
assert!(calls[0].body.is_none());
assert!(calls[0].header(sdk::IDEMPOTENCY_HEADER).is_none());
}
}
mod uploads {
use super::*;
#[tokio::test]
async fn create() {
let response = support::json(r#"{
"object": "upload",
"id": "id 1",
"projectId": "projectId 1",
"status": "pending",
"mimeType": "mimeType 1",
"filename": "filename 1",
"size": 1,
"uploadUrl": "uploadUrl 1",
"expiresAt": "2026-09-24T09:00:00.000Z",
"createdAt": "2026-09-24T09:00:00.000Z"
}"#);
let api = support::MockApi::start(vec![support::Reply::json(201, response.clone())]).await;
let params: types::UploadsCreateParams = support::from_json(r#"{"mimeType":"mimeType 1","size":1,"filename":"filename 1"}"#);
let result = api.client().uploads().create(params).await.unwrap();
support::assert_json(&result, &response);
let calls = api.calls().await;
assert_eq!(calls.len(), 1);
assert_eq!(calls[0].method, "POST");
assert_eq!(calls[0].path, "/v1/uploads");
assert_eq!(calls[0].query, support::pairs(&[]));
support::assert_json(&calls[0].body, &support::json(r#"{"mimeType":"mimeType 1","size":1,"filename":"filename 1"}"#));
assert!(calls[0].header(sdk::IDEMPOTENCY_HEADER).is_some_and(|key| !key.is_empty()));
}
#[tokio::test]
async fn create_retries_with_one_key() {
let response = support::json(r#"{
"object": "upload",
"id": "id 1",
"projectId": "projectId 1",
"status": "pending",
"mimeType": "mimeType 1",
"filename": "filename 1",
"size": 1,
"uploadUrl": "uploadUrl 1",
"expiresAt": "2026-09-24T09:00:00.000Z",
"createdAt": "2026-09-24T09:00:00.000Z"
}"#);
let api = support::MockApi::start(vec![support::Reply::status(503), support::Reply::json(201, response.clone())]).await;
let params: types::UploadsCreateParams = support::from_json(r#"{"mimeType":"mimeType 1","size":1,"filename":"filename 1"}"#);
let result = api.client().uploads().create(params).await.unwrap();
support::assert_json(&result, &response);
let calls = api.calls().await;
assert_eq!(calls.len(), 2);
let key = calls[0].header(sdk::IDEMPOTENCY_HEADER).unwrap();
assert!(!key.is_empty());
assert_eq!(calls[1].header(sdk::IDEMPOTENCY_HEADER), Some(key));
assert_eq!(calls[0].body, calls[1].body);
}
#[tokio::test]
async fn get() {
let response = support::json(r#"{
"object": "upload",
"id": "id 1",
"projectId": "projectId 1",
"status": "pending",
"mimeType": "mimeType 1",
"filename": "filename 1",
"size": 1,
"uploadUrl": "uploadUrl 1",
"expiresAt": "2026-09-24T09:00:00.000Z",
"createdAt": "2026-09-24T09:00:00.000Z"
}"#);
let api = support::MockApi::start(vec![support::Reply::json(200, response.clone())]).await;
let result = api.client().uploads().get("u57c1k9w2sqd7k3v8x1n5ybr6t4hjp2e").await.unwrap();
support::assert_json(&result, &response);
let calls = api.calls().await;
assert_eq!(calls.len(), 1);
assert_eq!(calls[0].method, "GET");
assert_eq!(calls[0].path, "/v1/uploads/u57c1k9w2sqd7k3v8x1n5ybr6t4hjp2e");
assert_eq!(calls[0].query, support::pairs(&[]));
assert!(calls[0].body.is_none());
assert!(calls[0].header(sdk::IDEMPOTENCY_HEADER).is_none());
}
#[tokio::test]
async fn complete() {
let response = support::json(r#"{
"object": "upload",
"id": "id 1",
"projectId": "projectId 1",
"status": "pending",
"mimeType": "mimeType 1",
"filename": "filename 1",
"size": 1,
"uploadUrl": "uploadUrl 1",
"expiresAt": "2026-09-24T09:00:00.000Z",
"createdAt": "2026-09-24T09:00:00.000Z"
}"#);
let api = support::MockApi::start(vec![support::Reply::json(200, response.clone())]).await;
let params: types::UploadsCompleteParams = support::from_json(r#"{"storageId":"storageId 1"}"#);
let result = api.client().uploads().complete("u57c1k9w2sqd7k3v8x1n5ybr6t4hjp2e", params).await.unwrap();
support::assert_json(&result, &response);
let calls = api.calls().await;
assert_eq!(calls.len(), 1);
assert_eq!(calls[0].method, "POST");
assert_eq!(calls[0].path, "/v1/uploads/u57c1k9w2sqd7k3v8x1n5ybr6t4hjp2e/complete");
assert_eq!(calls[0].query, support::pairs(&[]));
support::assert_json(&calls[0].body, &support::json(r#"{"storageId":"storageId 1"}"#));
assert!(calls[0].header(sdk::IDEMPOTENCY_HEADER).is_some_and(|key| !key.is_empty()));
}
#[tokio::test]
async fn complete_retries_with_one_key() {
let response = support::json(r#"{
"object": "upload",
"id": "id 1",
"projectId": "projectId 1",
"status": "pending",
"mimeType": "mimeType 1",
"filename": "filename 1",
"size": 1,
"uploadUrl": "uploadUrl 1",
"expiresAt": "2026-09-24T09:00:00.000Z",
"createdAt": "2026-09-24T09:00:00.000Z"
}"#);
let api = support::MockApi::start(vec![support::Reply::status(503), support::Reply::json(200, response.clone())]).await;
let params: types::UploadsCompleteParams = support::from_json(r#"{"storageId":"storageId 1"}"#);
let result = api.client().uploads().complete("u57c1k9w2sqd7k3v8x1n5ybr6t4hjp2e", params).await.unwrap();
support::assert_json(&result, &response);
let calls = api.calls().await;
assert_eq!(calls.len(), 2);
let key = calls[0].header(sdk::IDEMPOTENCY_HEADER).unwrap();
assert!(!key.is_empty());
assert_eq!(calls[1].header(sdk::IDEMPOTENCY_HEADER), Some(key));
assert_eq!(calls[0].body, calls[1].body);
}
}
mod chats {
use super::*;
#[tokio::test]
async fn list_streams_every_page() {
let first = support::json(r#"{
"object": "list",
"items": [
{
"object": "chat",
"id": "id 1",
"projectId": "projectId 1",
"accountId": "accountId 1",
"type": "direct",
"name": "name 1",
"savedName": "savedName 1",
"profileName": "profileName 1",
"username": "username 1",
"pictureId": "pictureId 1",
"lastMessage": {
"object": "message",
"id": "id 1",
"projectId": "projectId 1",
"accountId": "accountId 1",
"chatId": "chatId 1",
"chatType": "direct",
"direction": "inbound",
"source": "api",
"from": "from 1",
"to": "to 1",
"profileName": "profileName 1",
"username": "username 1",
"type": "text",
"text": "text 1",
"media": {
"url": "url 1",
"mimeType": "mimeType 1",
"filename": "filename 1",
"size": 1,
"width": 1,
"height": 1,
"durationSeconds": 1,
"gifPlayback": true,
"downloaded": true
},
"location": {
"latitude": 1.5,
"longitude": 1.5,
"name": "name 1",
"address": "address 1"
},
"contact": {
"name": "name 1",
"phone": "phone 1"
},
"contacts": [
{
"name": "name 1",
"phone": "phone 1"
}
],
"poll": {
"name": "name 1",
"options": [
{
"name": "name 1",
"voteCount": 1
}
],
"selectableCount": 1,
"voterCount": 1
},
"calendarEvent": {
"name": "name 1",
"description": "description 1",
"startsAt": "2026-09-24T09:00:00.000Z",
"endsAt": "2026-09-24T09:00:00.000Z",
"location": {
"name": "name 1",
"address": "address 1",
"latitude": 1.5,
"longitude": 1.5
},
"callType": "audio",
"joinUrl": "joinUrl 1",
"allowExtraGuests": true,
"cancelled": true
},
"mentions": [
"mentions 1"
],
"forwarded": true,
"forwardedManyTimes": true,
"viewOnce": true,
"starred": true,
"replyToMessageId": "replyToMessageId 1",
"replyToStoryId": "replyToStoryId 1",
"status": "queued",
"error": {
"code": "not_on_whatsapp",
"message": "message 1"
},
"metadata": {
"key": "value 1"
},
"sentAt": "2026-09-24T09:00:00.000Z",
"editedAt": "2026-09-24T09:00:00.000Z",
"deletedAt": "2026-09-24T09:00:00.000Z",
"createdAt": "2026-09-24T09:00:00.000Z",
"updatedAt": "2026-09-24T09:00:00.000Z"
},
"lastMessageAt": "2026-09-24T09:00:00.000Z",
"unread": true,
"unreadCount": 0,
"pinned": true,
"pinnedAt": "2026-09-24T09:00:00.000Z",
"archived": true,
"muted": true,
"muteExpiresAt": "2026-09-24T09:00:00.000Z"
}
],
"nextCursor": "cursor_2"
}"#);
let last = support::json(r#"{
"object": "list",
"items": [
{
"object": "chat",
"id": "id 1",
"projectId": "projectId 1",
"accountId": "accountId 1",
"type": "direct",
"name": "name 1",
"savedName": "savedName 1",
"profileName": "profileName 1",
"username": "username 1",
"pictureId": "pictureId 1",
"lastMessage": {
"object": "message",
"id": "id 1",
"projectId": "projectId 1",
"accountId": "accountId 1",
"chatId": "chatId 1",
"chatType": "direct",
"direction": "inbound",
"source": "api",
"from": "from 1",
"to": "to 1",
"profileName": "profileName 1",
"username": "username 1",
"type": "text",
"text": "text 1",
"media": {
"url": "url 1",
"mimeType": "mimeType 1",
"filename": "filename 1",
"size": 1,
"width": 1,
"height": 1,
"durationSeconds": 1,
"gifPlayback": true,
"downloaded": true
},
"location": {
"latitude": 1.5,
"longitude": 1.5,
"name": "name 1",
"address": "address 1"
},
"contact": {
"name": "name 1",
"phone": "phone 1"
},
"contacts": [
{
"name": "name 1",
"phone": "phone 1"
}
],
"poll": {
"name": "name 1",
"options": [
{
"name": "name 1",
"voteCount": 1
}
],
"selectableCount": 1,
"voterCount": 1
},
"calendarEvent": {
"name": "name 1",
"description": "description 1",
"startsAt": "2026-09-24T09:00:00.000Z",
"endsAt": "2026-09-24T09:00:00.000Z",
"location": {
"name": "name 1",
"address": "address 1",
"latitude": 1.5,
"longitude": 1.5
},
"callType": "audio",
"joinUrl": "joinUrl 1",
"allowExtraGuests": true,
"cancelled": true
},
"mentions": [
"mentions 1"
],
"forwarded": true,
"forwardedManyTimes": true,
"viewOnce": true,
"starred": true,
"replyToMessageId": "replyToMessageId 1",
"replyToStoryId": "replyToStoryId 1",
"status": "queued",
"error": {
"code": "not_on_whatsapp",
"message": "message 1"
},
"metadata": {
"key": "value 1"
},
"sentAt": "2026-09-24T09:00:00.000Z",
"editedAt": "2026-09-24T09:00:00.000Z",
"deletedAt": "2026-09-24T09:00:00.000Z",
"createdAt": "2026-09-24T09:00:00.000Z",
"updatedAt": "2026-09-24T09:00:00.000Z"
},
"lastMessageAt": "2026-09-24T09:00:00.000Z",
"unread": true,
"unreadCount": 0,
"pinned": true,
"pinnedAt": "2026-09-24T09:00:00.000Z",
"archived": true,
"muted": true,
"muteExpiresAt": "2026-09-24T09:00:00.000Z"
}
],
"nextCursor": null
}"#);
let api = support::MockApi::start(vec![
support::Reply::json(200, first),
support::Reply::json(200, last),
])
.await;
let params: types::ChatsListParams = support::from_json(r#"{
"archived": true,
"unread": true,
"type": "direct",
"q": "q 1",
"limit": 50,
"cursor": "cursor 1"
}"#);
let items = api.client().chats().list("k57a8m2x9d3f0q1wjh6ypc4n2d7s0vbr", params).to_vec().await.unwrap();
support::assert_json(&items, &support::json(r#"[
{
"object": "chat",
"id": "id 1",
"projectId": "projectId 1",
"accountId": "accountId 1",
"type": "direct",
"name": "name 1",
"savedName": "savedName 1",
"profileName": "profileName 1",
"username": "username 1",
"pictureId": "pictureId 1",
"lastMessage": {
"object": "message",
"id": "id 1",
"projectId": "projectId 1",
"accountId": "accountId 1",
"chatId": "chatId 1",
"chatType": "direct",
"direction": "inbound",
"source": "api",
"from": "from 1",
"to": "to 1",
"profileName": "profileName 1",
"username": "username 1",
"type": "text",
"text": "text 1",
"media": {
"url": "url 1",
"mimeType": "mimeType 1",
"filename": "filename 1",
"size": 1,
"width": 1,
"height": 1,
"durationSeconds": 1,
"gifPlayback": true,
"downloaded": true
},
"location": {
"latitude": 1.5,
"longitude": 1.5,
"name": "name 1",
"address": "address 1"
},
"contact": {
"name": "name 1",
"phone": "phone 1"
},
"contacts": [
{
"name": "name 1",
"phone": "phone 1"
}
],
"poll": {
"name": "name 1",
"options": [
{
"name": "name 1",
"voteCount": 1
}
],
"selectableCount": 1,
"voterCount": 1
},
"calendarEvent": {
"name": "name 1",
"description": "description 1",
"startsAt": "2026-09-24T09:00:00.000Z",
"endsAt": "2026-09-24T09:00:00.000Z",
"location": {
"name": "name 1",
"address": "address 1",
"latitude": 1.5,
"longitude": 1.5
},
"callType": "audio",
"joinUrl": "joinUrl 1",
"allowExtraGuests": true,
"cancelled": true
},
"mentions": [
"mentions 1"
],
"forwarded": true,
"forwardedManyTimes": true,
"viewOnce": true,
"starred": true,
"replyToMessageId": "replyToMessageId 1",
"replyToStoryId": "replyToStoryId 1",
"status": "queued",
"error": {
"code": "not_on_whatsapp",
"message": "message 1"
},
"metadata": {
"key": "value 1"
},
"sentAt": "2026-09-24T09:00:00.000Z",
"editedAt": "2026-09-24T09:00:00.000Z",
"deletedAt": "2026-09-24T09:00:00.000Z",
"createdAt": "2026-09-24T09:00:00.000Z",
"updatedAt": "2026-09-24T09:00:00.000Z"
},
"lastMessageAt": "2026-09-24T09:00:00.000Z",
"unread": true,
"unreadCount": 0,
"pinned": true,
"pinnedAt": "2026-09-24T09:00:00.000Z",
"archived": true,
"muted": true,
"muteExpiresAt": "2026-09-24T09:00:00.000Z"
},
{
"object": "chat",
"id": "id 1",
"projectId": "projectId 1",
"accountId": "accountId 1",
"type": "direct",
"name": "name 1",
"savedName": "savedName 1",
"profileName": "profileName 1",
"username": "username 1",
"pictureId": "pictureId 1",
"lastMessage": {
"object": "message",
"id": "id 1",
"projectId": "projectId 1",
"accountId": "accountId 1",
"chatId": "chatId 1",
"chatType": "direct",
"direction": "inbound",
"source": "api",
"from": "from 1",
"to": "to 1",
"profileName": "profileName 1",
"username": "username 1",
"type": "text",
"text": "text 1",
"media": {
"url": "url 1",
"mimeType": "mimeType 1",
"filename": "filename 1",
"size": 1,
"width": 1,
"height": 1,
"durationSeconds": 1,
"gifPlayback": true,
"downloaded": true
},
"location": {
"latitude": 1.5,
"longitude": 1.5,
"name": "name 1",
"address": "address 1"
},
"contact": {
"name": "name 1",
"phone": "phone 1"
},
"contacts": [
{
"name": "name 1",
"phone": "phone 1"
}
],
"poll": {
"name": "name 1",
"options": [
{
"name": "name 1",
"voteCount": 1
}
],
"selectableCount": 1,
"voterCount": 1
},
"calendarEvent": {
"name": "name 1",
"description": "description 1",
"startsAt": "2026-09-24T09:00:00.000Z",
"endsAt": "2026-09-24T09:00:00.000Z",
"location": {
"name": "name 1",
"address": "address 1",
"latitude": 1.5,
"longitude": 1.5
},
"callType": "audio",
"joinUrl": "joinUrl 1",
"allowExtraGuests": true,
"cancelled": true
},
"mentions": [
"mentions 1"
],
"forwarded": true,
"forwardedManyTimes": true,
"viewOnce": true,
"starred": true,
"replyToMessageId": "replyToMessageId 1",
"replyToStoryId": "replyToStoryId 1",
"status": "queued",
"error": {
"code": "not_on_whatsapp",
"message": "message 1"
},
"metadata": {
"key": "value 1"
},
"sentAt": "2026-09-24T09:00:00.000Z",
"editedAt": "2026-09-24T09:00:00.000Z",
"deletedAt": "2026-09-24T09:00:00.000Z",
"createdAt": "2026-09-24T09:00:00.000Z",
"updatedAt": "2026-09-24T09:00:00.000Z"
},
"lastMessageAt": "2026-09-24T09:00:00.000Z",
"unread": true,
"unreadCount": 0,
"pinned": true,
"pinnedAt": "2026-09-24T09:00:00.000Z",
"archived": true,
"muted": true,
"muteExpiresAt": "2026-09-24T09:00:00.000Z"
}
]"#));
let calls = api.calls().await;
assert_eq!(calls.len(), 2);
assert_eq!(calls[0].method, "GET");
assert_eq!(calls[0].path, "/v1/accounts/k57a8m2x9d3f0q1wjh6ypc4n2d7s0vbr/chats");
assert_eq!(calls[0].query, support::pairs(&[("archived", "true"), ("unread", "true"), ("type", "direct"), ("q", "q 1"), ("limit", "50"), ("cursor", "cursor 1")]));
assert_eq!(calls[1].query, support::pairs(&[("archived", "true"), ("unread", "true"), ("type", "direct"), ("q", "q 1"), ("limit", "50"), ("cursor", "cursor_2")]));
}
#[tokio::test]
async fn list_fetches_one_page() {
let page = support::json(r#"{
"object": "list",
"items": [
{
"object": "chat",
"id": "id 1",
"projectId": "projectId 1",
"accountId": "accountId 1",
"type": "direct",
"name": "name 1",
"savedName": "savedName 1",
"profileName": "profileName 1",
"username": "username 1",
"pictureId": "pictureId 1",
"lastMessage": {
"object": "message",
"id": "id 1",
"projectId": "projectId 1",
"accountId": "accountId 1",
"chatId": "chatId 1",
"chatType": "direct",
"direction": "inbound",
"source": "api",
"from": "from 1",
"to": "to 1",
"profileName": "profileName 1",
"username": "username 1",
"type": "text",
"text": "text 1",
"media": {
"url": "url 1",
"mimeType": "mimeType 1",
"filename": "filename 1",
"size": 1,
"width": 1,
"height": 1,
"durationSeconds": 1,
"gifPlayback": true,
"downloaded": true
},
"location": {
"latitude": 1.5,
"longitude": 1.5,
"name": "name 1",
"address": "address 1"
},
"contact": {
"name": "name 1",
"phone": "phone 1"
},
"contacts": [
{
"name": "name 1",
"phone": "phone 1"
}
],
"poll": {
"name": "name 1",
"options": [
{
"name": "name 1",
"voteCount": 1
}
],
"selectableCount": 1,
"voterCount": 1
},
"calendarEvent": {
"name": "name 1",
"description": "description 1",
"startsAt": "2026-09-24T09:00:00.000Z",
"endsAt": "2026-09-24T09:00:00.000Z",
"location": {
"name": "name 1",
"address": "address 1",
"latitude": 1.5,
"longitude": 1.5
},
"callType": "audio",
"joinUrl": "joinUrl 1",
"allowExtraGuests": true,
"cancelled": true
},
"mentions": [
"mentions 1"
],
"forwarded": true,
"forwardedManyTimes": true,
"viewOnce": true,
"starred": true,
"replyToMessageId": "replyToMessageId 1",
"replyToStoryId": "replyToStoryId 1",
"status": "queued",
"error": {
"code": "not_on_whatsapp",
"message": "message 1"
},
"metadata": {
"key": "value 1"
},
"sentAt": "2026-09-24T09:00:00.000Z",
"editedAt": "2026-09-24T09:00:00.000Z",
"deletedAt": "2026-09-24T09:00:00.000Z",
"createdAt": "2026-09-24T09:00:00.000Z",
"updatedAt": "2026-09-24T09:00:00.000Z"
},
"lastMessageAt": "2026-09-24T09:00:00.000Z",
"unread": true,
"unreadCount": 0,
"pinned": true,
"pinnedAt": "2026-09-24T09:00:00.000Z",
"archived": true,
"muted": true,
"muteExpiresAt": "2026-09-24T09:00:00.000Z"
}
],
"nextCursor": null
}"#);
let api = support::MockApi::start(vec![support::Reply::json(200, page.clone())]).await;
let result = api.client().chats().list("k57a8m2x9d3f0q1wjh6ypc4n2d7s0vbr", Default::default()).page().await.unwrap();
support::assert_json(&result, &page);
let calls = api.calls().await;
assert_eq!(calls.len(), 1);
assert_eq!(calls[0].method, "GET");
assert_eq!(calls[0].path, "/v1/accounts/k57a8m2x9d3f0q1wjh6ypc4n2d7s0vbr/chats");
assert_eq!(calls[0].query, support::pairs(&[]));
}
#[tokio::test]
async fn get() {
let response = support::json(r#"{
"object": "chat",
"id": "id 1",
"projectId": "projectId 1",
"accountId": "accountId 1",
"type": "direct",
"name": "name 1",
"savedName": "savedName 1",
"profileName": "profileName 1",
"username": "username 1",
"pictureId": "pictureId 1",
"lastMessage": {
"object": "message",
"id": "id 1",
"projectId": "projectId 1",
"accountId": "accountId 1",
"chatId": "chatId 1",
"chatType": "direct",
"direction": "inbound",
"source": "api",
"from": "from 1",
"to": "to 1",
"profileName": "profileName 1",
"username": "username 1",
"type": "text",
"text": "text 1",
"media": {
"url": "url 1",
"mimeType": "mimeType 1",
"filename": "filename 1",
"size": 1,
"width": 1,
"height": 1,
"durationSeconds": 1,
"gifPlayback": true,
"downloaded": true
},
"location": {
"latitude": 1.5,
"longitude": 1.5,
"name": "name 1",
"address": "address 1"
},
"contact": {
"name": "name 1",
"phone": "phone 1"
},
"contacts": [
{
"name": "name 1",
"phone": "phone 1"
}
],
"poll": {
"name": "name 1",
"options": [
{
"name": "name 1",
"voteCount": 1
}
],
"selectableCount": 1,
"voterCount": 1
},
"calendarEvent": {
"name": "name 1",
"description": "description 1",
"startsAt": "2026-09-24T09:00:00.000Z",
"endsAt": "2026-09-24T09:00:00.000Z",
"location": {
"name": "name 1",
"address": "address 1",
"latitude": 1.5,
"longitude": 1.5
},
"callType": "audio",
"joinUrl": "joinUrl 1",
"allowExtraGuests": true,
"cancelled": true
},
"mentions": [
"mentions 1"
],
"forwarded": true,
"forwardedManyTimes": true,
"viewOnce": true,
"starred": true,
"replyToMessageId": "replyToMessageId 1",
"replyToStoryId": "replyToStoryId 1",
"status": "queued",
"error": {
"code": "not_on_whatsapp",
"message": "message 1"
},
"metadata": {
"key": "value 1"
},
"sentAt": "2026-09-24T09:00:00.000Z",
"editedAt": "2026-09-24T09:00:00.000Z",
"deletedAt": "2026-09-24T09:00:00.000Z",
"createdAt": "2026-09-24T09:00:00.000Z",
"updatedAt": "2026-09-24T09:00:00.000Z"
},
"lastMessageAt": "2026-09-24T09:00:00.000Z",
"unread": true,
"unreadCount": 0,
"pinned": true,
"pinnedAt": "2026-09-24T09:00:00.000Z",
"archived": true,
"muted": true,
"muteExpiresAt": "2026-09-24T09:00:00.000Z"
}"#);
let api = support::MockApi::start(vec![support::Reply::json(200, response.clone())]).await;
let result = api.client().chats().get("k57a8m2x9d3f0q1wjh6ypc4n2d7s0vbr", "+584241112233").await.unwrap();
support::assert_json(&result, &response);
let calls = api.calls().await;
assert_eq!(calls.len(), 1);
assert_eq!(calls[0].method, "GET");
assert_eq!(calls[0].path, "/v1/accounts/k57a8m2x9d3f0q1wjh6ypc4n2d7s0vbr/chats/%2B584241112233");
assert_eq!(calls[0].query, support::pairs(&[]));
assert!(calls[0].body.is_none());
assert!(calls[0].header(sdk::IDEMPOTENCY_HEADER).is_none());
}
#[tokio::test]
async fn send_presence() {
let api = support::MockApi::start(vec![support::Reply::status(204)]).await;
let params: types::ChatsSendPresenceParams = support::from_json(r#"{"state":"typing"}"#);
api.client().chats().send_presence("k57a8m2x9d3f0q1wjh6ypc4n2d7s0vbr", "+584241112233", params).await.unwrap();
let calls = api.calls().await;
assert_eq!(calls.len(), 1);
assert_eq!(calls[0].method, "POST");
assert_eq!(calls[0].path, "/v1/accounts/k57a8m2x9d3f0q1wjh6ypc4n2d7s0vbr/chats/%2B584241112233/presence");
assert_eq!(calls[0].query, support::pairs(&[]));
support::assert_json(&calls[0].body, &support::json(r#"{"state":"typing"}"#));
assert!(calls[0].header(sdk::IDEMPOTENCY_HEADER).is_some_and(|key| !key.is_empty()));
}
#[tokio::test]
async fn send_presence_retries_with_one_key() {
let api = support::MockApi::start(vec![support::Reply::status(503), support::Reply::status(204)]).await;
let params: types::ChatsSendPresenceParams = support::from_json(r#"{"state":"typing"}"#);
api.client().chats().send_presence("k57a8m2x9d3f0q1wjh6ypc4n2d7s0vbr", "+584241112233", params).await.unwrap();
let calls = api.calls().await;
assert_eq!(calls.len(), 2);
let key = calls[0].header(sdk::IDEMPOTENCY_HEADER).unwrap();
assert!(!key.is_empty());
assert_eq!(calls[1].header(sdk::IDEMPOTENCY_HEADER), Some(key));
assert_eq!(calls[0].body, calls[1].body);
}
#[tokio::test]
async fn send_read_receipts() {
let response = support::json(r#"{"object":"chat_read","accountId":"accountId 1","chatId":"chatId 1","messageCount":1}"#);
let api = support::MockApi::start(vec![support::Reply::json(200, response.clone())]).await;
let params: types::ChatsSendReadReceiptsParams = support::from_json(r#"{"messageIds":["messageIds 1"]}"#);
let result = api.client().chats().send_read_receipts("k57a8m2x9d3f0q1wjh6ypc4n2d7s0vbr", "+584241112233", params).await.unwrap();
support::assert_json(&result, &response);
let calls = api.calls().await;
assert_eq!(calls.len(), 1);
assert_eq!(calls[0].method, "POST");
assert_eq!(calls[0].path, "/v1/accounts/k57a8m2x9d3f0q1wjh6ypc4n2d7s0vbr/chats/%2B584241112233/read");
assert_eq!(calls[0].query, support::pairs(&[]));
support::assert_json(&calls[0].body, &support::json(r#"{"messageIds":["messageIds 1"]}"#));
assert!(calls[0].header(sdk::IDEMPOTENCY_HEADER).is_some_and(|key| !key.is_empty()));
}
#[tokio::test]
async fn send_read_receipts_without_params() {
let response = support::json(r#"{"object":"chat_read","accountId":"accountId 1","chatId":"chatId 1","messageCount":1}"#);
let api = support::MockApi::start(vec![support::Reply::json(200, response.clone())]).await;
let result = api.client().chats().send_read_receipts("k57a8m2x9d3f0q1wjh6ypc4n2d7s0vbr", "+584241112233", Default::default()).await.unwrap();
support::assert_json(&result, &response);
let calls = api.calls().await;
assert_eq!(calls.len(), 1);
assert_eq!(calls[0].method, "POST");
assert_eq!(calls[0].path, "/v1/accounts/k57a8m2x9d3f0q1wjh6ypc4n2d7s0vbr/chats/%2B584241112233/read");
assert_eq!(calls[0].query, support::pairs(&[]));
support::assert_json(&calls[0].body, &support::json(r#"{}"#));
assert!(calls[0].header(sdk::IDEMPOTENCY_HEADER).is_some_and(|key| !key.is_empty()));
}
#[tokio::test]
async fn send_read_receipts_retries_with_one_key() {
let response = support::json(r#"{"object":"chat_read","accountId":"accountId 1","chatId":"chatId 1","messageCount":1}"#);
let api = support::MockApi::start(vec![support::Reply::status(503), support::Reply::json(200, response.clone())]).await;
let params: types::ChatsSendReadReceiptsParams = support::from_json(r#"{"messageIds":["messageIds 1"]}"#);
let result = api.client().chats().send_read_receipts("k57a8m2x9d3f0q1wjh6ypc4n2d7s0vbr", "+584241112233", params).await.unwrap();
support::assert_json(&result, &response);
let calls = api.calls().await;
assert_eq!(calls.len(), 2);
let key = calls[0].header(sdk::IDEMPOTENCY_HEADER).unwrap();
assert!(!key.is_empty());
assert_eq!(calls[1].header(sdk::IDEMPOTENCY_HEADER), Some(key));
assert_eq!(calls[0].body, calls[1].body);
}
#[tokio::test]
async fn mark_read() {
let api = support::MockApi::start(vec![support::Reply::status(204)]).await;
api.client().chats().mark_read("k57a8m2x9d3f0q1wjh6ypc4n2d7s0vbr", "+584241112233").await.unwrap();
let calls = api.calls().await;
assert_eq!(calls.len(), 1);
assert_eq!(calls[0].method, "POST");
assert_eq!(calls[0].path, "/v1/accounts/k57a8m2x9d3f0q1wjh6ypc4n2d7s0vbr/chats/%2B584241112233/mark-read");
assert_eq!(calls[0].query, support::pairs(&[]));
assert!(calls[0].body.is_none());
assert!(calls[0].header(sdk::IDEMPOTENCY_HEADER).is_some_and(|key| !key.is_empty()));
}
#[tokio::test]
async fn mark_read_retries_with_one_key() {
let api = support::MockApi::start(vec![support::Reply::status(503), support::Reply::status(204)]).await;
api.client().chats().mark_read("k57a8m2x9d3f0q1wjh6ypc4n2d7s0vbr", "+584241112233").await.unwrap();
let calls = api.calls().await;
assert_eq!(calls.len(), 2);
let key = calls[0].header(sdk::IDEMPOTENCY_HEADER).unwrap();
assert!(!key.is_empty());
assert_eq!(calls[1].header(sdk::IDEMPOTENCY_HEADER), Some(key));
assert_eq!(calls[0].body, calls[1].body);
}
#[tokio::test]
async fn mark_unread() {
let api = support::MockApi::start(vec![support::Reply::status(204)]).await;
api.client().chats().mark_unread("k57a8m2x9d3f0q1wjh6ypc4n2d7s0vbr", "+584241112233").await.unwrap();
let calls = api.calls().await;
assert_eq!(calls.len(), 1);
assert_eq!(calls[0].method, "POST");
assert_eq!(calls[0].path, "/v1/accounts/k57a8m2x9d3f0q1wjh6ypc4n2d7s0vbr/chats/%2B584241112233/mark-unread");
assert_eq!(calls[0].query, support::pairs(&[]));
assert!(calls[0].body.is_none());
assert!(calls[0].header(sdk::IDEMPOTENCY_HEADER).is_some_and(|key| !key.is_empty()));
}
#[tokio::test]
async fn mark_unread_retries_with_one_key() {
let api = support::MockApi::start(vec![support::Reply::status(503), support::Reply::status(204)]).await;
api.client().chats().mark_unread("k57a8m2x9d3f0q1wjh6ypc4n2d7s0vbr", "+584241112233").await.unwrap();
let calls = api.calls().await;
assert_eq!(calls.len(), 2);
let key = calls[0].header(sdk::IDEMPOTENCY_HEADER).unwrap();
assert!(!key.is_empty());
assert_eq!(calls[1].header(sdk::IDEMPOTENCY_HEADER), Some(key));
assert_eq!(calls[0].body, calls[1].body);
}
#[tokio::test]
async fn archive() {
let api = support::MockApi::start(vec![support::Reply::status(204)]).await;
api.client().chats().archive("k57a8m2x9d3f0q1wjh6ypc4n2d7s0vbr", "+584241112233").await.unwrap();
let calls = api.calls().await;
assert_eq!(calls.len(), 1);
assert_eq!(calls[0].method, "POST");
assert_eq!(calls[0].path, "/v1/accounts/k57a8m2x9d3f0q1wjh6ypc4n2d7s0vbr/chats/%2B584241112233/archive");
assert_eq!(calls[0].query, support::pairs(&[]));
assert!(calls[0].body.is_none());
assert!(calls[0].header(sdk::IDEMPOTENCY_HEADER).is_some_and(|key| !key.is_empty()));
}
#[tokio::test]
async fn archive_retries_with_one_key() {
let api = support::MockApi::start(vec![support::Reply::status(503), support::Reply::status(204)]).await;
api.client().chats().archive("k57a8m2x9d3f0q1wjh6ypc4n2d7s0vbr", "+584241112233").await.unwrap();
let calls = api.calls().await;
assert_eq!(calls.len(), 2);
let key = calls[0].header(sdk::IDEMPOTENCY_HEADER).unwrap();
assert!(!key.is_empty());
assert_eq!(calls[1].header(sdk::IDEMPOTENCY_HEADER), Some(key));
assert_eq!(calls[0].body, calls[1].body);
}
#[tokio::test]
async fn unarchive() {
let api = support::MockApi::start(vec![support::Reply::status(204)]).await;
api.client().chats().unarchive("k57a8m2x9d3f0q1wjh6ypc4n2d7s0vbr", "+584241112233").await.unwrap();
let calls = api.calls().await;
assert_eq!(calls.len(), 1);
assert_eq!(calls[0].method, "POST");
assert_eq!(calls[0].path, "/v1/accounts/k57a8m2x9d3f0q1wjh6ypc4n2d7s0vbr/chats/%2B584241112233/unarchive");
assert_eq!(calls[0].query, support::pairs(&[]));
assert!(calls[0].body.is_none());
assert!(calls[0].header(sdk::IDEMPOTENCY_HEADER).is_some_and(|key| !key.is_empty()));
}
#[tokio::test]
async fn unarchive_retries_with_one_key() {
let api = support::MockApi::start(vec![support::Reply::status(503), support::Reply::status(204)]).await;
api.client().chats().unarchive("k57a8m2x9d3f0q1wjh6ypc4n2d7s0vbr", "+584241112233").await.unwrap();
let calls = api.calls().await;
assert_eq!(calls.len(), 2);
let key = calls[0].header(sdk::IDEMPOTENCY_HEADER).unwrap();
assert!(!key.is_empty());
assert_eq!(calls[1].header(sdk::IDEMPOTENCY_HEADER), Some(key));
assert_eq!(calls[0].body, calls[1].body);
}
#[tokio::test]
async fn pin() {
let api = support::MockApi::start(vec![support::Reply::status(204)]).await;
api.client().chats().pin("k57a8m2x9d3f0q1wjh6ypc4n2d7s0vbr", "+584241112233").await.unwrap();
let calls = api.calls().await;
assert_eq!(calls.len(), 1);
assert_eq!(calls[0].method, "POST");
assert_eq!(calls[0].path, "/v1/accounts/k57a8m2x9d3f0q1wjh6ypc4n2d7s0vbr/chats/%2B584241112233/pin");
assert_eq!(calls[0].query, support::pairs(&[]));
assert!(calls[0].body.is_none());
assert!(calls[0].header(sdk::IDEMPOTENCY_HEADER).is_some_and(|key| !key.is_empty()));
}
#[tokio::test]
async fn pin_retries_with_one_key() {
let api = support::MockApi::start(vec![support::Reply::status(503), support::Reply::status(204)]).await;
api.client().chats().pin("k57a8m2x9d3f0q1wjh6ypc4n2d7s0vbr", "+584241112233").await.unwrap();
let calls = api.calls().await;
assert_eq!(calls.len(), 2);
let key = calls[0].header(sdk::IDEMPOTENCY_HEADER).unwrap();
assert!(!key.is_empty());
assert_eq!(calls[1].header(sdk::IDEMPOTENCY_HEADER), Some(key));
assert_eq!(calls[0].body, calls[1].body);
}
#[tokio::test]
async fn unpin() {
let api = support::MockApi::start(vec![support::Reply::status(204)]).await;
api.client().chats().unpin("k57a8m2x9d3f0q1wjh6ypc4n2d7s0vbr", "+584241112233").await.unwrap();
let calls = api.calls().await;
assert_eq!(calls.len(), 1);
assert_eq!(calls[0].method, "POST");
assert_eq!(calls[0].path, "/v1/accounts/k57a8m2x9d3f0q1wjh6ypc4n2d7s0vbr/chats/%2B584241112233/unpin");
assert_eq!(calls[0].query, support::pairs(&[]));
assert!(calls[0].body.is_none());
assert!(calls[0].header(sdk::IDEMPOTENCY_HEADER).is_some_and(|key| !key.is_empty()));
}
#[tokio::test]
async fn unpin_retries_with_one_key() {
let api = support::MockApi::start(vec![support::Reply::status(503), support::Reply::status(204)]).await;
api.client().chats().unpin("k57a8m2x9d3f0q1wjh6ypc4n2d7s0vbr", "+584241112233").await.unwrap();
let calls = api.calls().await;
assert_eq!(calls.len(), 2);
let key = calls[0].header(sdk::IDEMPOTENCY_HEADER).unwrap();
assert!(!key.is_empty());
assert_eq!(calls[1].header(sdk::IDEMPOTENCY_HEADER), Some(key));
assert_eq!(calls[0].body, calls[1].body);
}
#[tokio::test]
async fn mute() {
let api = support::MockApi::start(vec![support::Reply::status(204)]).await;
let params: types::ChatsMuteParams = support::from_json(r#"{"durationSeconds":0}"#);
api.client().chats().mute("k57a8m2x9d3f0q1wjh6ypc4n2d7s0vbr", "+584241112233", params).await.unwrap();
let calls = api.calls().await;
assert_eq!(calls.len(), 1);
assert_eq!(calls[0].method, "POST");
assert_eq!(calls[0].path, "/v1/accounts/k57a8m2x9d3f0q1wjh6ypc4n2d7s0vbr/chats/%2B584241112233/mute");
assert_eq!(calls[0].query, support::pairs(&[]));
support::assert_json(&calls[0].body, &support::json(r#"{"durationSeconds":0}"#));
assert!(calls[0].header(sdk::IDEMPOTENCY_HEADER).is_some_and(|key| !key.is_empty()));
}
#[tokio::test]
async fn mute_without_params() {
let api = support::MockApi::start(vec![support::Reply::status(204)]).await;
api.client().chats().mute("k57a8m2x9d3f0q1wjh6ypc4n2d7s0vbr", "+584241112233", Default::default()).await.unwrap();
let calls = api.calls().await;
assert_eq!(calls.len(), 1);
assert_eq!(calls[0].method, "POST");
assert_eq!(calls[0].path, "/v1/accounts/k57a8m2x9d3f0q1wjh6ypc4n2d7s0vbr/chats/%2B584241112233/mute");
assert_eq!(calls[0].query, support::pairs(&[]));
support::assert_json(&calls[0].body, &support::json(r#"{}"#));
assert!(calls[0].header(sdk::IDEMPOTENCY_HEADER).is_some_and(|key| !key.is_empty()));
}
#[tokio::test]
async fn mute_retries_with_one_key() {
let api = support::MockApi::start(vec![support::Reply::status(503), support::Reply::status(204)]).await;
let params: types::ChatsMuteParams = support::from_json(r#"{"durationSeconds":0}"#);
api.client().chats().mute("k57a8m2x9d3f0q1wjh6ypc4n2d7s0vbr", "+584241112233", params).await.unwrap();
let calls = api.calls().await;
assert_eq!(calls.len(), 2);
let key = calls[0].header(sdk::IDEMPOTENCY_HEADER).unwrap();
assert!(!key.is_empty());
assert_eq!(calls[1].header(sdk::IDEMPOTENCY_HEADER), Some(key));
assert_eq!(calls[0].body, calls[1].body);
}
#[tokio::test]
async fn unmute() {
let api = support::MockApi::start(vec![support::Reply::status(204)]).await;
api.client().chats().unmute("k57a8m2x9d3f0q1wjh6ypc4n2d7s0vbr", "+584241112233").await.unwrap();
let calls = api.calls().await;
assert_eq!(calls.len(), 1);
assert_eq!(calls[0].method, "POST");
assert_eq!(calls[0].path, "/v1/accounts/k57a8m2x9d3f0q1wjh6ypc4n2d7s0vbr/chats/%2B584241112233/unmute");
assert_eq!(calls[0].query, support::pairs(&[]));
assert!(calls[0].body.is_none());
assert!(calls[0].header(sdk::IDEMPOTENCY_HEADER).is_some_and(|key| !key.is_empty()));
}
#[tokio::test]
async fn unmute_retries_with_one_key() {
let api = support::MockApi::start(vec![support::Reply::status(503), support::Reply::status(204)]).await;
api.client().chats().unmute("k57a8m2x9d3f0q1wjh6ypc4n2d7s0vbr", "+584241112233").await.unwrap();
let calls = api.calls().await;
assert_eq!(calls.len(), 2);
let key = calls[0].header(sdk::IDEMPOTENCY_HEADER).unwrap();
assert!(!key.is_empty());
assert_eq!(calls[1].header(sdk::IDEMPOTENCY_HEADER), Some(key));
assert_eq!(calls[0].body, calls[1].body);
}
#[tokio::test]
async fn delete() {
let api = support::MockApi::start(vec![support::Reply::status(204)]).await;
let params: types::ChatsDeleteParams = support::from_json(r#"{"deleteMedia":false}"#);
api.client().chats().delete("k57a8m2x9d3f0q1wjh6ypc4n2d7s0vbr", "+584241112233", params).await.unwrap();
let calls = api.calls().await;
assert_eq!(calls.len(), 1);
assert_eq!(calls[0].method, "DELETE");
assert_eq!(calls[0].path, "/v1/accounts/k57a8m2x9d3f0q1wjh6ypc4n2d7s0vbr/chats/%2B584241112233");
assert_eq!(calls[0].query, support::pairs(&[("deleteMedia", "false")]));
assert!(calls[0].body.is_none());
assert!(calls[0].header(sdk::IDEMPOTENCY_HEADER).is_none());
}
#[tokio::test]
async fn delete_without_params() {
let api = support::MockApi::start(vec![support::Reply::status(204)]).await;
api.client().chats().delete("k57a8m2x9d3f0q1wjh6ypc4n2d7s0vbr", "+584241112233", Default::default()).await.unwrap();
let calls = api.calls().await;
assert_eq!(calls.len(), 1);
assert_eq!(calls[0].method, "DELETE");
assert_eq!(calls[0].path, "/v1/accounts/k57a8m2x9d3f0q1wjh6ypc4n2d7s0vbr/chats/%2B584241112233");
assert_eq!(calls[0].query, support::pairs(&[]));
assert!(calls[0].body.is_none());
assert!(calls[0].header(sdk::IDEMPOTENCY_HEADER).is_none());
}
#[tokio::test]
async fn set_disappearing_timer() {
let api = support::MockApi::start(vec![support::Reply::status(204)]).await;
let params: types::ChatsSetDisappearingTimerParams = support::from_json(r#"{"durationSeconds":0}"#);
api.client().chats().set_disappearing_timer("k57a8m2x9d3f0q1wjh6ypc4n2d7s0vbr", "+584241112233", params).await.unwrap();
let calls = api.calls().await;
assert_eq!(calls.len(), 1);
assert_eq!(calls[0].method, "PUT");
assert_eq!(calls[0].path, "/v1/accounts/k57a8m2x9d3f0q1wjh6ypc4n2d7s0vbr/chats/%2B584241112233/disappearing-timer");
assert_eq!(calls[0].query, support::pairs(&[]));
support::assert_json(&calls[0].body, &support::json(r#"{"durationSeconds":0}"#));
assert!(calls[0].header(sdk::IDEMPOTENCY_HEADER).is_none());
}
#[tokio::test]
async fn add_label() {
let api = support::MockApi::start(vec![support::Reply::status(204)]).await;
let params: types::ChatsAddLabelParams = support::from_json(r#"{"labelId":"labelId 1"}"#);
api.client().chats().add_label("k57a8m2x9d3f0q1wjh6ypc4n2d7s0vbr", "+584241112233", params).await.unwrap();
let calls = api.calls().await;
assert_eq!(calls.len(), 1);
assert_eq!(calls[0].method, "POST");
assert_eq!(calls[0].path, "/v1/accounts/k57a8m2x9d3f0q1wjh6ypc4n2d7s0vbr/chats/%2B584241112233/labels");
assert_eq!(calls[0].query, support::pairs(&[]));
support::assert_json(&calls[0].body, &support::json(r#"{"labelId":"labelId 1"}"#));
assert!(calls[0].header(sdk::IDEMPOTENCY_HEADER).is_some_and(|key| !key.is_empty()));
}
#[tokio::test]
async fn add_label_retries_with_one_key() {
let api = support::MockApi::start(vec![support::Reply::status(503), support::Reply::status(204)]).await;
let params: types::ChatsAddLabelParams = support::from_json(r#"{"labelId":"labelId 1"}"#);
api.client().chats().add_label("k57a8m2x9d3f0q1wjh6ypc4n2d7s0vbr", "+584241112233", params).await.unwrap();
let calls = api.calls().await;
assert_eq!(calls.len(), 2);
let key = calls[0].header(sdk::IDEMPOTENCY_HEADER).unwrap();
assert!(!key.is_empty());
assert_eq!(calls[1].header(sdk::IDEMPOTENCY_HEADER), Some(key));
assert_eq!(calls[0].body, calls[1].body);
}
#[tokio::test]
async fn remove_label() {
let api = support::MockApi::start(vec![support::Reply::status(204)]).await;
api.client().chats().remove_label("k57a8m2x9d3f0q1wjh6ypc4n2d7s0vbr", "+584241112233", "5").await.unwrap();
let calls = api.calls().await;
assert_eq!(calls.len(), 1);
assert_eq!(calls[0].method, "DELETE");
assert_eq!(calls[0].path, "/v1/accounts/k57a8m2x9d3f0q1wjh6ypc4n2d7s0vbr/chats/%2B584241112233/labels/5");
assert_eq!(calls[0].query, support::pairs(&[]));
assert!(calls[0].body.is_none());
assert!(calls[0].header(sdk::IDEMPOTENCY_HEADER).is_none());
}
}
mod labels {
use super::*;
#[tokio::test]
async fn upsert() {
let response = support::json(r#"{"object":"label","id":"id 1","accountId":"accountId 1","name":"name 1","color":0}"#);
let api = support::MockApi::start(vec![support::Reply::json(200, response.clone())]).await;
let params: types::LabelsUpsertParams = support::from_json(r#"{"name":"name 1","color":0}"#);
let result = api.client().labels().upsert("k57a8m2x9d3f0q1wjh6ypc4n2d7s0vbr", "5", params).await.unwrap();
support::assert_json(&result, &response);
let calls = api.calls().await;
assert_eq!(calls.len(), 1);
assert_eq!(calls[0].method, "PUT");
assert_eq!(calls[0].path, "/v1/accounts/k57a8m2x9d3f0q1wjh6ypc4n2d7s0vbr/labels/5");
assert_eq!(calls[0].query, support::pairs(&[]));
support::assert_json(&calls[0].body, &support::json(r#"{"name":"name 1","color":0}"#));
assert!(calls[0].header(sdk::IDEMPOTENCY_HEADER).is_none());
}
#[tokio::test]
async fn delete() {
let api = support::MockApi::start(vec![support::Reply::status(204)]).await;
api.client().labels().delete("k57a8m2x9d3f0q1wjh6ypc4n2d7s0vbr", "5").await.unwrap();
let calls = api.calls().await;
assert_eq!(calls.len(), 1);
assert_eq!(calls[0].method, "DELETE");
assert_eq!(calls[0].path, "/v1/accounts/k57a8m2x9d3f0q1wjh6ypc4n2d7s0vbr/labels/5");
assert_eq!(calls[0].query, support::pairs(&[]));
assert!(calls[0].body.is_none());
assert!(calls[0].header(sdk::IDEMPOTENCY_HEADER).is_none());
}
}
mod contacts {
use super::*;
#[tokio::test]
async fn list_streams_every_page() {
let first = support::json(r#"{
"object": "list",
"items": [
{
"object": "contact",
"id": "id 1",
"accountId": "accountId 1",
"phone": "phone 1",
"lid": "lid 1",
"savedName": "savedName 1",
"profileName": "profileName 1",
"username": "username 1",
"about": "about 1",
"pictureId": "pictureId 1",
"businessName": "businessName 1",
"deviceCount": 1
}
],
"nextCursor": "cursor_2"
}"#);
let last = support::json(r#"{
"object": "list",
"items": [
{
"object": "contact",
"id": "id 1",
"accountId": "accountId 1",
"phone": "phone 1",
"lid": "lid 1",
"savedName": "savedName 1",
"profileName": "profileName 1",
"username": "username 1",
"about": "about 1",
"pictureId": "pictureId 1",
"businessName": "businessName 1",
"deviceCount": 1
}
],
"nextCursor": null
}"#);
let api = support::MockApi::start(vec![
support::Reply::json(200, first),
support::Reply::json(200, last),
])
.await;
let params: types::ContactsListParams = support::from_json(r#"{"q":"q 1","limit":50,"cursor":"cursor 1"}"#);
let items = api.client().contacts().list("k57a8m2x9d3f0q1wjh6ypc4n2d7s0vbr", params).to_vec().await.unwrap();
support::assert_json(&items, &support::json(r#"[
{
"object": "contact",
"id": "id 1",
"accountId": "accountId 1",
"phone": "phone 1",
"lid": "lid 1",
"savedName": "savedName 1",
"profileName": "profileName 1",
"username": "username 1",
"about": "about 1",
"pictureId": "pictureId 1",
"businessName": "businessName 1",
"deviceCount": 1
},
{
"object": "contact",
"id": "id 1",
"accountId": "accountId 1",
"phone": "phone 1",
"lid": "lid 1",
"savedName": "savedName 1",
"profileName": "profileName 1",
"username": "username 1",
"about": "about 1",
"pictureId": "pictureId 1",
"businessName": "businessName 1",
"deviceCount": 1
}
]"#));
let calls = api.calls().await;
assert_eq!(calls.len(), 2);
assert_eq!(calls[0].method, "GET");
assert_eq!(calls[0].path, "/v1/accounts/k57a8m2x9d3f0q1wjh6ypc4n2d7s0vbr/contacts");
assert_eq!(calls[0].query, support::pairs(&[("q", "q 1"), ("limit", "50"), ("cursor", "cursor 1")]));
assert_eq!(calls[1].query, support::pairs(&[("q", "q 1"), ("limit", "50"), ("cursor", "cursor_2")]));
}
#[tokio::test]
async fn list_fetches_one_page() {
let page = support::json(r#"{
"object": "list",
"items": [
{
"object": "contact",
"id": "id 1",
"accountId": "accountId 1",
"phone": "phone 1",
"lid": "lid 1",
"savedName": "savedName 1",
"profileName": "profileName 1",
"username": "username 1",
"about": "about 1",
"pictureId": "pictureId 1",
"businessName": "businessName 1",
"deviceCount": 1
}
],
"nextCursor": null
}"#);
let api = support::MockApi::start(vec![support::Reply::json(200, page.clone())]).await;
let result = api.client().contacts().list("k57a8m2x9d3f0q1wjh6ypc4n2d7s0vbr", Default::default()).page().await.unwrap();
support::assert_json(&result, &page);
let calls = api.calls().await;
assert_eq!(calls.len(), 1);
assert_eq!(calls[0].method, "GET");
assert_eq!(calls[0].path, "/v1/accounts/k57a8m2x9d3f0q1wjh6ypc4n2d7s0vbr/contacts");
assert_eq!(calls[0].query, support::pairs(&[]));
}
#[tokio::test]
async fn get() {
let response = support::json(r#"{
"object": "contact",
"id": "id 1",
"accountId": "accountId 1",
"phone": "phone 1",
"lid": "lid 1",
"savedName": "savedName 1",
"profileName": "profileName 1",
"username": "username 1",
"about": "about 1",
"pictureId": "pictureId 1",
"businessName": "businessName 1",
"deviceCount": 1
}"#);
let api = support::MockApi::start(vec![support::Reply::json(200, response.clone())]).await;
let result = api.client().contacts().get("k57a8m2x9d3f0q1wjh6ypc4n2d7s0vbr", "+584241112233").await.unwrap();
support::assert_json(&result, &response);
let calls = api.calls().await;
assert_eq!(calls.len(), 1);
assert_eq!(calls[0].method, "GET");
assert_eq!(calls[0].path, "/v1/accounts/k57a8m2x9d3f0q1wjh6ypc4n2d7s0vbr/contacts/%2B584241112233");
assert_eq!(calls[0].query, support::pairs(&[]));
assert!(calls[0].body.is_none());
assert!(calls[0].header(sdk::IDEMPOTENCY_HEADER).is_none());
}
#[tokio::test]
async fn check() {
let response = support::json(r#"{
"object": "list",
"items": [
{
"object": "contact_check",
"phone": "phone 1",
"onWhatsApp": true,
"contactId": "contactId 1",
"businessName": "businessName 1",
"username": "username 1"
}
],
"nextCursor": "nextCursor 1"
}"#);
let api = support::MockApi::start(vec![support::Reply::json(200, response.clone())]).await;
let params: types::ContactsCheckParams = support::from_json(r#"{"phones":["phones 1"]}"#);
let result = api.client().contacts().check("k57a8m2x9d3f0q1wjh6ypc4n2d7s0vbr", params).await.unwrap();
support::assert_json(&result, &response);
let calls = api.calls().await;
assert_eq!(calls.len(), 1);
assert_eq!(calls[0].method, "POST");
assert_eq!(calls[0].path, "/v1/accounts/k57a8m2x9d3f0q1wjh6ypc4n2d7s0vbr/contacts/check");
assert_eq!(calls[0].query, support::pairs(&[]));
support::assert_json(&calls[0].body, &support::json(r#"{"phones":["phones 1"]}"#));
assert!(calls[0].header(sdk::IDEMPOTENCY_HEADER).is_some_and(|key| !key.is_empty()));
}
#[tokio::test]
async fn check_retries_with_one_key() {
let response = support::json(r#"{
"object": "list",
"items": [
{
"object": "contact_check",
"phone": "phone 1",
"onWhatsApp": true,
"contactId": "contactId 1",
"businessName": "businessName 1",
"username": "username 1"
}
],
"nextCursor": "nextCursor 1"
}"#);
let api = support::MockApi::start(vec![support::Reply::status(503), support::Reply::json(200, response.clone())]).await;
let params: types::ContactsCheckParams = support::from_json(r#"{"phones":["phones 1"]}"#);
let result = api.client().contacts().check("k57a8m2x9d3f0q1wjh6ypc4n2d7s0vbr", params).await.unwrap();
support::assert_json(&result, &response);
let calls = api.calls().await;
assert_eq!(calls.len(), 2);
let key = calls[0].header(sdk::IDEMPOTENCY_HEADER).unwrap();
assert!(!key.is_empty());
assert_eq!(calls[1].header(sdk::IDEMPOTENCY_HEADER), Some(key));
assert_eq!(calls[0].body, calls[1].body);
}
#[tokio::test]
async fn lookup() {
let response = support::json(r#"{
"object": "list",
"items": [
{
"object": "contact",
"id": "id 1",
"accountId": "accountId 1",
"phone": "phone 1",
"lid": "lid 1",
"savedName": "savedName 1",
"profileName": "profileName 1",
"username": "username 1",
"about": "about 1",
"pictureId": "pictureId 1",
"businessName": "businessName 1",
"deviceCount": 1
}
],
"nextCursor": "nextCursor 1"
}"#);
let api = support::MockApi::start(vec![support::Reply::json(200, response.clone())]).await;
let params: types::ContactsLookupParams = support::from_json(r#"{"contactIds":["contactIds 1"]}"#);
let result = api.client().contacts().lookup("k57a8m2x9d3f0q1wjh6ypc4n2d7s0vbr", params).await.unwrap();
support::assert_json(&result, &response);
let calls = api.calls().await;
assert_eq!(calls.len(), 1);
assert_eq!(calls[0].method, "POST");
assert_eq!(calls[0].path, "/v1/accounts/k57a8m2x9d3f0q1wjh6ypc4n2d7s0vbr/contacts/lookup");
assert_eq!(calls[0].query, support::pairs(&[]));
support::assert_json(&calls[0].body, &support::json(r#"{"contactIds":["contactIds 1"]}"#));
assert!(calls[0].header(sdk::IDEMPOTENCY_HEADER).is_some_and(|key| !key.is_empty()));
}
#[tokio::test]
async fn lookup_retries_with_one_key() {
let response = support::json(r#"{
"object": "list",
"items": [
{
"object": "contact",
"id": "id 1",
"accountId": "accountId 1",
"phone": "phone 1",
"lid": "lid 1",
"savedName": "savedName 1",
"profileName": "profileName 1",
"username": "username 1",
"about": "about 1",
"pictureId": "pictureId 1",
"businessName": "businessName 1",
"deviceCount": 1
}
],
"nextCursor": "nextCursor 1"
}"#);
let api = support::MockApi::start(vec![support::Reply::status(503), support::Reply::json(200, response.clone())]).await;
let params: types::ContactsLookupParams = support::from_json(r#"{"contactIds":["contactIds 1"]}"#);
let result = api.client().contacts().lookup("k57a8m2x9d3f0q1wjh6ypc4n2d7s0vbr", params).await.unwrap();
support::assert_json(&result, &response);
let calls = api.calls().await;
assert_eq!(calls.len(), 2);
let key = calls[0].header(sdk::IDEMPOTENCY_HEADER).unwrap();
assert!(!key.is_empty());
assert_eq!(calls[1].header(sdk::IDEMPOTENCY_HEADER), Some(key));
assert_eq!(calls[0].body, calls[1].body);
}
#[tokio::test]
async fn get_picture() {
let response = support::json(r#"{"object":"picture","id":"id 1","url":"url 1","preview":true}"#);
let api = support::MockApi::start(vec![support::Reply::json(200, response.clone())]).await;
let params: types::ContactsGetPictureParams = support::from_json(r#"{"preview":false}"#);
let result = api.client().contacts().get_picture("k57a8m2x9d3f0q1wjh6ypc4n2d7s0vbr", "+584241112233", params).await.unwrap();
support::assert_json(&result, &response);
let calls = api.calls().await;
assert_eq!(calls.len(), 1);
assert_eq!(calls[0].method, "GET");
assert_eq!(calls[0].path, "/v1/accounts/k57a8m2x9d3f0q1wjh6ypc4n2d7s0vbr/contacts/%2B584241112233/picture");
assert_eq!(calls[0].query, support::pairs(&[("preview", "false")]));
assert!(calls[0].body.is_none());
assert!(calls[0].header(sdk::IDEMPOTENCY_HEADER).is_none());
}
#[tokio::test]
async fn get_picture_without_params() {
let response = support::json(r#"{"object":"picture","id":"id 1","url":"url 1","preview":true}"#);
let api = support::MockApi::start(vec![support::Reply::json(200, response.clone())]).await;
let result = api.client().contacts().get_picture("k57a8m2x9d3f0q1wjh6ypc4n2d7s0vbr", "+584241112233", Default::default()).await.unwrap();
support::assert_json(&result, &response);
let calls = api.calls().await;
assert_eq!(calls.len(), 1);
assert_eq!(calls[0].method, "GET");
assert_eq!(calls[0].path, "/v1/accounts/k57a8m2x9d3f0q1wjh6ypc4n2d7s0vbr/contacts/%2B584241112233/picture");
assert_eq!(calls[0].query, support::pairs(&[]));
assert!(calls[0].body.is_none());
assert!(calls[0].header(sdk::IDEMPOTENCY_HEADER).is_none());
}
#[tokio::test]
async fn get_business_profile() {
let response = support::json(r#"{
"object": "business_profile",
"contactId": "contactId 1",
"address": "address 1",
"email": "email 1",
"categories": [
{
"id": "id 1",
"name": "name 1"
}
],
"profileOptions": {
"key": "value 1"
},
"timeZone": "timeZone 1",
"businessHours": [
{
"dayOfWeek": "dayOfWeek 1",
"mode": "mode 1",
"openTime": "openTime 1",
"closeTime": "closeTime 1"
}
]
}"#);
let api = support::MockApi::start(vec![support::Reply::json(200, response.clone())]).await;
let result = api.client().contacts().get_business_profile("k57a8m2x9d3f0q1wjh6ypc4n2d7s0vbr", "+584241112233").await.unwrap();
support::assert_json(&result, &response);
let calls = api.calls().await;
assert_eq!(calls.len(), 1);
assert_eq!(calls[0].method, "GET");
assert_eq!(calls[0].path, "/v1/accounts/k57a8m2x9d3f0q1wjh6ypc4n2d7s0vbr/contacts/%2B584241112233/business-profile");
assert_eq!(calls[0].query, support::pairs(&[]));
assert!(calls[0].body.is_none());
assert!(calls[0].header(sdk::IDEMPOTENCY_HEADER).is_none());
}
#[tokio::test]
async fn subscribe_presence() {
let api = support::MockApi::start(vec![support::Reply::status(204)]).await;
api.client().contacts().subscribe_presence("k57a8m2x9d3f0q1wjh6ypc4n2d7s0vbr", "+584241112233").await.unwrap();
let calls = api.calls().await;
assert_eq!(calls.len(), 1);
assert_eq!(calls[0].method, "POST");
assert_eq!(calls[0].path, "/v1/accounts/k57a8m2x9d3f0q1wjh6ypc4n2d7s0vbr/contacts/%2B584241112233/subscribe-presence");
assert_eq!(calls[0].query, support::pairs(&[]));
assert!(calls[0].body.is_none());
assert!(calls[0].header(sdk::IDEMPOTENCY_HEADER).is_some_and(|key| !key.is_empty()));
}
#[tokio::test]
async fn subscribe_presence_retries_with_one_key() {
let api = support::MockApi::start(vec![support::Reply::status(503), support::Reply::status(204)]).await;
api.client().contacts().subscribe_presence("k57a8m2x9d3f0q1wjh6ypc4n2d7s0vbr", "+584241112233").await.unwrap();
let calls = api.calls().await;
assert_eq!(calls.len(), 2);
let key = calls[0].header(sdk::IDEMPOTENCY_HEADER).unwrap();
assert!(!key.is_empty());
assert_eq!(calls[1].header(sdk::IDEMPOTENCY_HEADER), Some(key));
assert_eq!(calls[0].body, calls[1].body);
}
#[tokio::test]
async fn block() {
let api = support::MockApi::start(vec![support::Reply::status(204)]).await;
api.client().contacts().block("k57a8m2x9d3f0q1wjh6ypc4n2d7s0vbr", "+584241112233").await.unwrap();
let calls = api.calls().await;
assert_eq!(calls.len(), 1);
assert_eq!(calls[0].method, "POST");
assert_eq!(calls[0].path, "/v1/accounts/k57a8m2x9d3f0q1wjh6ypc4n2d7s0vbr/contacts/%2B584241112233/block");
assert_eq!(calls[0].query, support::pairs(&[]));
assert!(calls[0].body.is_none());
assert!(calls[0].header(sdk::IDEMPOTENCY_HEADER).is_some_and(|key| !key.is_empty()));
}
#[tokio::test]
async fn block_retries_with_one_key() {
let api = support::MockApi::start(vec![support::Reply::status(503), support::Reply::status(204)]).await;
api.client().contacts().block("k57a8m2x9d3f0q1wjh6ypc4n2d7s0vbr", "+584241112233").await.unwrap();
let calls = api.calls().await;
assert_eq!(calls.len(), 2);
let key = calls[0].header(sdk::IDEMPOTENCY_HEADER).unwrap();
assert!(!key.is_empty());
assert_eq!(calls[1].header(sdk::IDEMPOTENCY_HEADER), Some(key));
assert_eq!(calls[0].body, calls[1].body);
}
#[tokio::test]
async fn unblock() {
let api = support::MockApi::start(vec![support::Reply::status(204)]).await;
api.client().contacts().unblock("k57a8m2x9d3f0q1wjh6ypc4n2d7s0vbr", "+584241112233").await.unwrap();
let calls = api.calls().await;
assert_eq!(calls.len(), 1);
assert_eq!(calls[0].method, "POST");
assert_eq!(calls[0].path, "/v1/accounts/k57a8m2x9d3f0q1wjh6ypc4n2d7s0vbr/contacts/%2B584241112233/unblock");
assert_eq!(calls[0].query, support::pairs(&[]));
assert!(calls[0].body.is_none());
assert!(calls[0].header(sdk::IDEMPOTENCY_HEADER).is_some_and(|key| !key.is_empty()));
}
#[tokio::test]
async fn unblock_retries_with_one_key() {
let api = support::MockApi::start(vec![support::Reply::status(503), support::Reply::status(204)]).await;
api.client().contacts().unblock("k57a8m2x9d3f0q1wjh6ypc4n2d7s0vbr", "+584241112233").await.unwrap();
let calls = api.calls().await;
assert_eq!(calls.len(), 2);
let key = calls[0].header(sdk::IDEMPOTENCY_HEADER).unwrap();
assert!(!key.is_empty());
assert_eq!(calls[1].header(sdk::IDEMPOTENCY_HEADER), Some(key));
assert_eq!(calls[0].body, calls[1].body);
}
#[tokio::test]
async fn list_blocked_streams_every_page() {
let first = support::json(r#"{
"object": "list",
"items": [
{
"object": "blocked_contact",
"contactId": "contactId 1",
"phone": "phone 1",
"lid": "lid 1"
}
],
"nextCursor": "cursor_2"
}"#);
let last = support::json(r#"{
"object": "list",
"items": [
{
"object": "blocked_contact",
"contactId": "contactId 1",
"phone": "phone 1",
"lid": "lid 1"
}
],
"nextCursor": null
}"#);
let api = support::MockApi::start(vec![
support::Reply::json(200, first),
support::Reply::json(200, last),
])
.await;
let params: types::ContactsListBlockedParams = support::from_json(r#"{"limit":50,"cursor":"cursor 1"}"#);
let items = api.client().contacts().list_blocked("k57a8m2x9d3f0q1wjh6ypc4n2d7s0vbr", params).to_vec().await.unwrap();
support::assert_json(&items, &support::json(r#"[
{
"object": "blocked_contact",
"contactId": "contactId 1",
"phone": "phone 1",
"lid": "lid 1"
},
{
"object": "blocked_contact",
"contactId": "contactId 1",
"phone": "phone 1",
"lid": "lid 1"
}
]"#));
let calls = api.calls().await;
assert_eq!(calls.len(), 2);
assert_eq!(calls[0].method, "GET");
assert_eq!(calls[0].path, "/v1/accounts/k57a8m2x9d3f0q1wjh6ypc4n2d7s0vbr/blocklist");
assert_eq!(calls[0].query, support::pairs(&[("limit", "50"), ("cursor", "cursor 1")]));
assert_eq!(calls[1].query, support::pairs(&[("limit", "50"), ("cursor", "cursor_2")]));
}
#[tokio::test]
async fn list_blocked_fetches_one_page() {
let page = support::json(r#"{
"object": "list",
"items": [
{
"object": "blocked_contact",
"contactId": "contactId 1",
"phone": "phone 1",
"lid": "lid 1"
}
],
"nextCursor": null
}"#);
let api = support::MockApi::start(vec![support::Reply::json(200, page.clone())]).await;
let result = api.client().contacts().list_blocked("k57a8m2x9d3f0q1wjh6ypc4n2d7s0vbr", Default::default()).page().await.unwrap();
support::assert_json(&result, &page);
let calls = api.calls().await;
assert_eq!(calls.len(), 1);
assert_eq!(calls[0].method, "GET");
assert_eq!(calls[0].path, "/v1/accounts/k57a8m2x9d3f0q1wjh6ypc4n2d7s0vbr/blocklist");
assert_eq!(calls[0].query, support::pairs(&[]));
}
#[tokio::test]
async fn get_link() {
let response = support::json(r#"{"object":"contact_link","url":"url 1"}"#);
let api = support::MockApi::start(vec![support::Reply::json(200, response.clone())]).await;
let result = api.client().contacts().get_link("k57a8m2x9d3f0q1wjh6ypc4n2d7s0vbr").await.unwrap();
support::assert_json(&result, &response);
let calls = api.calls().await;
assert_eq!(calls.len(), 1);
assert_eq!(calls[0].method, "GET");
assert_eq!(calls[0].path, "/v1/accounts/k57a8m2x9d3f0q1wjh6ypc4n2d7s0vbr/contact-link");
assert_eq!(calls[0].query, support::pairs(&[]));
assert!(calls[0].body.is_none());
assert!(calls[0].header(sdk::IDEMPOTENCY_HEADER).is_none());
}
#[tokio::test]
async fn reset_link() {
let response = support::json(r#"{"object":"contact_link","url":"url 1"}"#);
let api = support::MockApi::start(vec![support::Reply::json(200, response.clone())]).await;
let result = api.client().contacts().reset_link("k57a8m2x9d3f0q1wjh6ypc4n2d7s0vbr").await.unwrap();
support::assert_json(&result, &response);
let calls = api.calls().await;
assert_eq!(calls.len(), 1);
assert_eq!(calls[0].method, "POST");
assert_eq!(calls[0].path, "/v1/accounts/k57a8m2x9d3f0q1wjh6ypc4n2d7s0vbr/contact-link/reset");
assert_eq!(calls[0].query, support::pairs(&[]));
assert!(calls[0].body.is_none());
assert!(calls[0].header(sdk::IDEMPOTENCY_HEADER).is_some_and(|key| !key.is_empty()));
}
#[tokio::test]
async fn reset_link_retries_with_one_key() {
let response = support::json(r#"{"object":"contact_link","url":"url 1"}"#);
let api = support::MockApi::start(vec![support::Reply::status(503), support::Reply::json(200, response.clone())]).await;
let result = api.client().contacts().reset_link("k57a8m2x9d3f0q1wjh6ypc4n2d7s0vbr").await.unwrap();
support::assert_json(&result, &response);
let calls = api.calls().await;
assert_eq!(calls.len(), 2);
let key = calls[0].header(sdk::IDEMPOTENCY_HEADER).unwrap();
assert!(!key.is_empty());
assert_eq!(calls[1].header(sdk::IDEMPOTENCY_HEADER), Some(key));
assert_eq!(calls[0].body, calls[1].body);
}
#[tokio::test]
async fn resolve_link() {
let response = support::json(r#"{
"object": "resolved_link",
"kind": "contact",
"contactId": "contactId 1",
"type": "type 1",
"profileName": "profileName 1",
"businessName": "businessName 1",
"verifiedLevel": "verifiedLevel 1",
"prefilledText": "prefilledText 1"
}"#);
let api = support::MockApi::start(vec![support::Reply::json(200, response.clone())]).await;
let params: types::ContactsResolveLinkParams = support::from_json(r#"{"kind":"contact","code":"code 1"}"#);
let result = api.client().contacts().resolve_link("k57a8m2x9d3f0q1wjh6ypc4n2d7s0vbr", params).await.unwrap();
support::assert_json(&result, &response);
let calls = api.calls().await;
assert_eq!(calls.len(), 1);
assert_eq!(calls[0].method, "POST");
assert_eq!(calls[0].path, "/v1/accounts/k57a8m2x9d3f0q1wjh6ypc4n2d7s0vbr/links/resolve");
assert_eq!(calls[0].query, support::pairs(&[]));
support::assert_json(&calls[0].body, &support::json(r#"{"kind":"contact","code":"code 1"}"#));
assert!(calls[0].header(sdk::IDEMPOTENCY_HEADER).is_some_and(|key| !key.is_empty()));
}
#[tokio::test]
async fn resolve_link_retries_with_one_key() {
let response = support::json(r#"{
"object": "resolved_link",
"kind": "contact",
"contactId": "contactId 1",
"type": "type 1",
"profileName": "profileName 1",
"businessName": "businessName 1",
"verifiedLevel": "verifiedLevel 1",
"prefilledText": "prefilledText 1"
}"#);
let api = support::MockApi::start(vec![support::Reply::status(503), support::Reply::json(200, response.clone())]).await;
let params: types::ContactsResolveLinkParams = support::from_json(r#"{"kind":"contact","code":"code 1"}"#);
let result = api.client().contacts().resolve_link("k57a8m2x9d3f0q1wjh6ypc4n2d7s0vbr", params).await.unwrap();
support::assert_json(&result, &response);
let calls = api.calls().await;
assert_eq!(calls.len(), 2);
let key = calls[0].header(sdk::IDEMPOTENCY_HEADER).unwrap();
assert!(!key.is_empty());
assert_eq!(calls[1].header(sdk::IDEMPOTENCY_HEADER), Some(key));
assert_eq!(calls[0].body, calls[1].body);
}
}
mod bots {
use super::*;
#[tokio::test]
async fn list_streams_every_page() {
let first = support::json(r#"{
"object": "list",
"items": [
{
"object": "bot",
"id": "id 1",
"personaId": "personaId 1",
"name": "name 1",
"description": "description 1",
"category": "category 1",
"default": true,
"prompts": [
"prompts 1"
],
"commands": [
{
"name": "name 1",
"description": "description 1"
}
]
}
],
"nextCursor": "cursor_2"
}"#);
let last = support::json(r#"{
"object": "list",
"items": [
{
"object": "bot",
"id": "id 1",
"personaId": "personaId 1",
"name": "name 1",
"description": "description 1",
"category": "category 1",
"default": true,
"prompts": [
"prompts 1"
],
"commands": [
{
"name": "name 1",
"description": "description 1"
}
]
}
],
"nextCursor": null
}"#);
let api = support::MockApi::start(vec![
support::Reply::json(200, first),
support::Reply::json(200, last),
])
.await;
let params: types::BotsListParams = support::from_json(r#"{"limit":50,"cursor":"cursor 1"}"#);
let items = api.client().bots().list("k57a8m2x9d3f0q1wjh6ypc4n2d7s0vbr", params).to_vec().await.unwrap();
support::assert_json(&items, &support::json(r#"[
{
"object": "bot",
"id": "id 1",
"personaId": "personaId 1",
"name": "name 1",
"description": "description 1",
"category": "category 1",
"default": true,
"prompts": [
"prompts 1"
],
"commands": [
{
"name": "name 1",
"description": "description 1"
}
]
},
{
"object": "bot",
"id": "id 1",
"personaId": "personaId 1",
"name": "name 1",
"description": "description 1",
"category": "category 1",
"default": true,
"prompts": [
"prompts 1"
],
"commands": [
{
"name": "name 1",
"description": "description 1"
}
]
}
]"#));
let calls = api.calls().await;
assert_eq!(calls.len(), 2);
assert_eq!(calls[0].method, "GET");
assert_eq!(calls[0].path, "/v1/accounts/k57a8m2x9d3f0q1wjh6ypc4n2d7s0vbr/bots");
assert_eq!(calls[0].query, support::pairs(&[("limit", "50"), ("cursor", "cursor 1")]));
assert_eq!(calls[1].query, support::pairs(&[("limit", "50"), ("cursor", "cursor_2")]));
}
#[tokio::test]
async fn list_fetches_one_page() {
let page = support::json(r#"{
"object": "list",
"items": [
{
"object": "bot",
"id": "id 1",
"personaId": "personaId 1",
"name": "name 1",
"description": "description 1",
"category": "category 1",
"default": true,
"prompts": [
"prompts 1"
],
"commands": [
{
"name": "name 1",
"description": "description 1"
}
]
}
],
"nextCursor": null
}"#);
let api = support::MockApi::start(vec![support::Reply::json(200, page.clone())]).await;
let result = api.client().bots().list("k57a8m2x9d3f0q1wjh6ypc4n2d7s0vbr", Default::default()).page().await.unwrap();
support::assert_json(&result, &page);
let calls = api.calls().await;
assert_eq!(calls.len(), 1);
assert_eq!(calls[0].method, "GET");
assert_eq!(calls[0].path, "/v1/accounts/k57a8m2x9d3f0q1wjh6ypc4n2d7s0vbr/bots");
assert_eq!(calls[0].query, support::pairs(&[]));
}
}
mod profile {
use super::*;
#[tokio::test]
async fn update() {
let api = support::MockApi::start(vec![support::Reply::status(204)]).await;
let params: types::ProfileUpdateParams = support::from_json(r#"{"about":"about 1","name":"name 1"}"#);
api.client().profile().update("k57a8m2x9d3f0q1wjh6ypc4n2d7s0vbr", params).await.unwrap();
let calls = api.calls().await;
assert_eq!(calls.len(), 1);
assert_eq!(calls[0].method, "PATCH");
assert_eq!(calls[0].path, "/v1/accounts/k57a8m2x9d3f0q1wjh6ypc4n2d7s0vbr/profile");
assert_eq!(calls[0].query, support::pairs(&[]));
support::assert_json(&calls[0].body, &support::json(r#"{"about":"about 1","name":"name 1"}"#));
assert!(calls[0].header(sdk::IDEMPOTENCY_HEADER).is_none());
}
#[tokio::test]
async fn update_without_params() {
let api = support::MockApi::start(vec![support::Reply::status(204)]).await;
api.client().profile().update("k57a8m2x9d3f0q1wjh6ypc4n2d7s0vbr", Default::default()).await.unwrap();
let calls = api.calls().await;
assert_eq!(calls.len(), 1);
assert_eq!(calls[0].method, "PATCH");
assert_eq!(calls[0].path, "/v1/accounts/k57a8m2x9d3f0q1wjh6ypc4n2d7s0vbr/profile");
assert_eq!(calls[0].query, support::pairs(&[]));
support::assert_json(&calls[0].body, &support::json(r#"{}"#));
assert!(calls[0].header(sdk::IDEMPOTENCY_HEADER).is_none());
}
#[tokio::test]
async fn update_is_not_repeated() {
let api = support::MockApi::start(vec![
support::Reply::status(503),
support::Reply::status(503),
])
.await;
let params: types::ProfileUpdateParams = support::from_json(r#"{"about":"about 1","name":"name 1"}"#);
let error = api.client().profile().update("k57a8m2x9d3f0q1wjh6ypc4n2d7s0vbr", params).await.unwrap_err();
assert_eq!(error.status(), Some(503));
assert_eq!(api.calls().await.len(), 1);
}
#[tokio::test]
async fn set_picture() {
let response = support::json(r#"{"object":"picture","id":"id 1","url":"url 1","preview":true}"#);
let api = support::MockApi::start(vec![support::Reply::json(200, response.clone())]).await;
let params: types::ProfileSetPictureParams = support::from_json(r#"{"url":"https://example.com/url"}"#);
let result = api.client().profile().set_picture("k57a8m2x9d3f0q1wjh6ypc4n2d7s0vbr", params).await.unwrap();
support::assert_json(&result, &response);
let calls = api.calls().await;
assert_eq!(calls.len(), 1);
assert_eq!(calls[0].method, "PUT");
assert_eq!(calls[0].path, "/v1/accounts/k57a8m2x9d3f0q1wjh6ypc4n2d7s0vbr/profile/picture");
assert_eq!(calls[0].query, support::pairs(&[]));
support::assert_json(&calls[0].body, &support::json(r#"{"url":"https://example.com/url"}"#));
assert!(calls[0].header(sdk::IDEMPOTENCY_HEADER).is_none());
}
#[tokio::test]
async fn delete_picture() {
let api = support::MockApi::start(vec![support::Reply::status(204)]).await;
api.client().profile().delete_picture("k57a8m2x9d3f0q1wjh6ypc4n2d7s0vbr").await.unwrap();
let calls = api.calls().await;
assert_eq!(calls.len(), 1);
assert_eq!(calls[0].method, "DELETE");
assert_eq!(calls[0].path, "/v1/accounts/k57a8m2x9d3f0q1wjh6ypc4n2d7s0vbr/profile/picture");
assert_eq!(calls[0].query, support::pairs(&[]));
assert!(calls[0].body.is_none());
assert!(calls[0].header(sdk::IDEMPOTENCY_HEADER).is_none());
}
}
mod privacy {
use super::*;
#[tokio::test]
async fn get() {
let response = support::json(r#"{
"object": "privacy_settings",
"groupAdd": "groupAdd 1",
"lastSeen": "lastSeen 1",
"stories": "stories 1",
"profile": "profile 1",
"readReceipts": "readReceipts 1",
"online": "online 1",
"callAdd": "callAdd 1",
"messages": "messages 1",
"defense": "defense 1",
"stickers": "stickers 1"
}"#);
let api = support::MockApi::start(vec![support::Reply::json(200, response.clone())]).await;
let result = api.client().privacy().get("k57a8m2x9d3f0q1wjh6ypc4n2d7s0vbr").await.unwrap();
support::assert_json(&result, &response);
let calls = api.calls().await;
assert_eq!(calls.len(), 1);
assert_eq!(calls[0].method, "GET");
assert_eq!(calls[0].path, "/v1/accounts/k57a8m2x9d3f0q1wjh6ypc4n2d7s0vbr/privacy");
assert_eq!(calls[0].query, support::pairs(&[]));
assert!(calls[0].body.is_none());
assert!(calls[0].header(sdk::IDEMPOTENCY_HEADER).is_none());
}
#[tokio::test]
async fn update() {
let response = support::json(r#"{
"object": "privacy_settings",
"groupAdd": "groupAdd 1",
"lastSeen": "lastSeen 1",
"stories": "stories 1",
"profile": "profile 1",
"readReceipts": "readReceipts 1",
"online": "online 1",
"callAdd": "callAdd 1",
"messages": "messages 1",
"defense": "defense 1",
"stickers": "stickers 1"
}"#);
let api = support::MockApi::start(vec![support::Reply::json(200, response.clone())]).await;
let params: types::PrivacyUpdateParams = support::from_json(r#"{
"groupAdd": "groupAdd 1",
"lastSeen": "lastSeen 1",
"stories": "stories 1",
"profile": "profile 1",
"readReceipts": "readReceipts 1",
"online": "online 1",
"callAdd": "callAdd 1",
"messages": "messages 1"
}"#);
let result = api.client().privacy().update("k57a8m2x9d3f0q1wjh6ypc4n2d7s0vbr", params).await.unwrap();
support::assert_json(&result, &response);
let calls = api.calls().await;
assert_eq!(calls.len(), 1);
assert_eq!(calls[0].method, "PATCH");
assert_eq!(calls[0].path, "/v1/accounts/k57a8m2x9d3f0q1wjh6ypc4n2d7s0vbr/privacy");
assert_eq!(calls[0].query, support::pairs(&[]));
support::assert_json(&calls[0].body, &support::json(r#"{
"groupAdd": "groupAdd 1",
"lastSeen": "lastSeen 1",
"stories": "stories 1",
"profile": "profile 1",
"readReceipts": "readReceipts 1",
"online": "online 1",
"callAdd": "callAdd 1",
"messages": "messages 1"
}"#));
assert!(calls[0].header(sdk::IDEMPOTENCY_HEADER).is_none());
}
#[tokio::test]
async fn update_without_params() {
let response = support::json(r#"{
"object": "privacy_settings",
"groupAdd": "groupAdd 1",
"lastSeen": "lastSeen 1",
"stories": "stories 1",
"profile": "profile 1",
"readReceipts": "readReceipts 1",
"online": "online 1",
"callAdd": "callAdd 1",
"messages": "messages 1",
"defense": "defense 1",
"stickers": "stickers 1"
}"#);
let api = support::MockApi::start(vec![support::Reply::json(200, response.clone())]).await;
let result = api.client().privacy().update("k57a8m2x9d3f0q1wjh6ypc4n2d7s0vbr", Default::default()).await.unwrap();
support::assert_json(&result, &response);
let calls = api.calls().await;
assert_eq!(calls.len(), 1);
assert_eq!(calls[0].method, "PATCH");
assert_eq!(calls[0].path, "/v1/accounts/k57a8m2x9d3f0q1wjh6ypc4n2d7s0vbr/privacy");
assert_eq!(calls[0].query, support::pairs(&[]));
support::assert_json(&calls[0].body, &support::json(r#"{}"#));
assert!(calls[0].header(sdk::IDEMPOTENCY_HEADER).is_none());
}
#[tokio::test]
async fn update_is_not_repeated() {
let api = support::MockApi::start(vec![
support::Reply::status(503),
support::Reply::status(503),
])
.await;
let params: types::PrivacyUpdateParams = support::from_json(r#"{
"groupAdd": "groupAdd 1",
"lastSeen": "lastSeen 1",
"stories": "stories 1",
"profile": "profile 1",
"readReceipts": "readReceipts 1",
"online": "online 1",
"callAdd": "callAdd 1",
"messages": "messages 1"
}"#);
let error = api.client().privacy().update("k57a8m2x9d3f0q1wjh6ypc4n2d7s0vbr", params).await.unwrap_err();
assert_eq!(error.status(), Some(503));
assert_eq!(api.calls().await.len(), 1);
}
#[tokio::test]
async fn get_story_privacy() {
let response = support::json(r#"{
"object": "story_privacy",
"lists": [
{
"type": "contacts",
"contactIds": [
"contactIds 1"
],
"default": true
}
]
}"#);
let api = support::MockApi::start(vec![support::Reply::json(200, response.clone())]).await;
let result = api.client().privacy().get_story_privacy("k57a8m2x9d3f0q1wjh6ypc4n2d7s0vbr").await.unwrap();
support::assert_json(&result, &response);
let calls = api.calls().await;
assert_eq!(calls.len(), 1);
assert_eq!(calls[0].method, "GET");
assert_eq!(calls[0].path, "/v1/accounts/k57a8m2x9d3f0q1wjh6ypc4n2d7s0vbr/privacy/stories");
assert_eq!(calls[0].query, support::pairs(&[]));
assert!(calls[0].body.is_none());
assert!(calls[0].header(sdk::IDEMPOTENCY_HEADER).is_none());
}
}
mod calls {
use super::*;
#[tokio::test]
async fn reject() {
let api = support::MockApi::start(vec![support::Reply::status(204)]).await;
let params: types::CallsRejectParams = support::from_json(r#"{"from":"from 1"}"#);
api.client().calls().reject("k57a8m2x9d3f0q1wjh6ypc4n2d7s0vbr", "3EB0C4A1F2D7B96E5A10", params).await.unwrap();
let calls = api.calls().await;
assert_eq!(calls.len(), 1);
assert_eq!(calls[0].method, "POST");
assert_eq!(calls[0].path, "/v1/accounts/k57a8m2x9d3f0q1wjh6ypc4n2d7s0vbr/calls/3EB0C4A1F2D7B96E5A10/reject");
assert_eq!(calls[0].query, support::pairs(&[]));
support::assert_json(&calls[0].body, &support::json(r#"{"from":"from 1"}"#));
assert!(calls[0].header(sdk::IDEMPOTENCY_HEADER).is_some_and(|key| !key.is_empty()));
}
#[tokio::test]
async fn reject_retries_with_one_key() {
let api = support::MockApi::start(vec![support::Reply::status(503), support::Reply::status(204)]).await;
let params: types::CallsRejectParams = support::from_json(r#"{"from":"from 1"}"#);
api.client().calls().reject("k57a8m2x9d3f0q1wjh6ypc4n2d7s0vbr", "3EB0C4A1F2D7B96E5A10", params).await.unwrap();
let calls = api.calls().await;
assert_eq!(calls.len(), 2);
let key = calls[0].header(sdk::IDEMPOTENCY_HEADER).unwrap();
assert!(!key.is_empty());
assert_eq!(calls[1].header(sdk::IDEMPOTENCY_HEADER), Some(key));
assert_eq!(calls[0].body, calls[1].body);
}
}
mod sticker_packs {
use super::*;
#[tokio::test]
async fn get() {
let response = support::json(r#"{
"object": "sticker_pack",
"id": "id 1",
"name": "name 1",
"publisher": "publisher 1",
"description": "description 1",
"animated": true,
"trayImageId": "trayImageId 1",
"stickers": [
{
"url": "url 1",
"directPath": "directPath 1",
"sizeBytes": 1,
"mimeType": "mimeType 1",
"width": 1,
"height": 1,
"emojis": [
"emojis 1"
]
}
]
}"#);
let api = support::MockApi::start(vec![support::Reply::json(200, response.clone())]).await;
let result = api.client().sticker_packs().get("k57a8m2x9d3f0q1wjh6ypc4n2d7s0vbr", "4a0b1c2d-sticker-pack").await.unwrap();
support::assert_json(&result, &response);
let calls = api.calls().await;
assert_eq!(calls.len(), 1);
assert_eq!(calls[0].method, "GET");
assert_eq!(calls[0].path, "/v1/accounts/k57a8m2x9d3f0q1wjh6ypc4n2d7s0vbr/sticker-packs/4a0b1c2d-sticker-pack");
assert_eq!(calls[0].query, support::pairs(&[]));
assert!(calls[0].body.is_none());
assert!(calls[0].header(sdk::IDEMPOTENCY_HEADER).is_none());
}
}
mod favorite_stickers {
use super::*;
#[tokio::test]
async fn list_streams_every_page() {
let first = support::json(r#"{
"object": "list",
"items": [
{
"object": "favorite_sticker",
"id": "id 1",
"accountId": "accountId 1",
"mimeType": "mimeType 1",
"animated": true,
"lottie": true,
"width": 1,
"height": 1,
"size": 1,
"emojis": [
"emojis 1"
],
"favoritedAt": "2026-09-24T09:00:00.000Z",
"media": {
"url": "url 1",
"downloaded": true
}
}
],
"nextCursor": "cursor_2"
}"#);
let last = support::json(r#"{
"object": "list",
"items": [
{
"object": "favorite_sticker",
"id": "id 1",
"accountId": "accountId 1",
"mimeType": "mimeType 1",
"animated": true,
"lottie": true,
"width": 1,
"height": 1,
"size": 1,
"emojis": [
"emojis 1"
],
"favoritedAt": "2026-09-24T09:00:00.000Z",
"media": {
"url": "url 1",
"downloaded": true
}
}
],
"nextCursor": null
}"#);
let api = support::MockApi::start(vec![
support::Reply::json(200, first),
support::Reply::json(200, last),
])
.await;
let params: types::FavoriteStickersListParams = support::from_json(r#"{"limit":50,"cursor":"cursor 1"}"#);
let items = api.client().favorite_stickers().list("k57a8m2x9d3f0q1wjh6ypc4n2d7s0vbr", params).to_vec().await.unwrap();
support::assert_json(&items, &support::json(r#"[
{
"object": "favorite_sticker",
"id": "id 1",
"accountId": "accountId 1",
"mimeType": "mimeType 1",
"animated": true,
"lottie": true,
"width": 1,
"height": 1,
"size": 1,
"emojis": [
"emojis 1"
],
"favoritedAt": "2026-09-24T09:00:00.000Z",
"media": {
"url": "url 1",
"downloaded": true
}
},
{
"object": "favorite_sticker",
"id": "id 1",
"accountId": "accountId 1",
"mimeType": "mimeType 1",
"animated": true,
"lottie": true,
"width": 1,
"height": 1,
"size": 1,
"emojis": [
"emojis 1"
],
"favoritedAt": "2026-09-24T09:00:00.000Z",
"media": {
"url": "url 1",
"downloaded": true
}
}
]"#));
let calls = api.calls().await;
assert_eq!(calls.len(), 2);
assert_eq!(calls[0].method, "GET");
assert_eq!(calls[0].path, "/v1/accounts/k57a8m2x9d3f0q1wjh6ypc4n2d7s0vbr/stickers/favorites");
assert_eq!(calls[0].query, support::pairs(&[("limit", "50"), ("cursor", "cursor 1")]));
assert_eq!(calls[1].query, support::pairs(&[("limit", "50"), ("cursor", "cursor_2")]));
}
#[tokio::test]
async fn list_fetches_one_page() {
let page = support::json(r#"{
"object": "list",
"items": [
{
"object": "favorite_sticker",
"id": "id 1",
"accountId": "accountId 1",
"mimeType": "mimeType 1",
"animated": true,
"lottie": true,
"width": 1,
"height": 1,
"size": 1,
"emojis": [
"emojis 1"
],
"favoritedAt": "2026-09-24T09:00:00.000Z",
"media": {
"url": "url 1",
"downloaded": true
}
}
],
"nextCursor": null
}"#);
let api = support::MockApi::start(vec![support::Reply::json(200, page.clone())]).await;
let result = api.client().favorite_stickers().list("k57a8m2x9d3f0q1wjh6ypc4n2d7s0vbr", Default::default()).page().await.unwrap();
support::assert_json(&result, &page);
let calls = api.calls().await;
assert_eq!(calls.len(), 1);
assert_eq!(calls[0].method, "GET");
assert_eq!(calls[0].path, "/v1/accounts/k57a8m2x9d3f0q1wjh6ypc4n2d7s0vbr/stickers/favorites");
assert_eq!(calls[0].query, support::pairs(&[]));
}
#[tokio::test]
async fn add() {
let response = support::json(r#"{
"object": "favorite_sticker",
"id": "id 1",
"accountId": "accountId 1",
"mimeType": "mimeType 1",
"animated": true,
"lottie": true,
"width": 1,
"height": 1,
"size": 1,
"emojis": [
"emojis 1"
],
"favoritedAt": "2026-09-24T09:00:00.000Z",
"media": {
"url": "url 1",
"downloaded": true
}
}"#);
let api = support::MockApi::start(vec![support::Reply::json(201, response.clone())]).await;
let params: types::FavoriteStickersAddParams = support::from_json(r#"{"messageId":"messageId 1"}"#);
let result = api.client().favorite_stickers().add("k57a8m2x9d3f0q1wjh6ypc4n2d7s0vbr", params).await.unwrap();
support::assert_json(&result, &response);
let calls = api.calls().await;
assert_eq!(calls.len(), 1);
assert_eq!(calls[0].method, "POST");
assert_eq!(calls[0].path, "/v1/accounts/k57a8m2x9d3f0q1wjh6ypc4n2d7s0vbr/stickers/favorites");
assert_eq!(calls[0].query, support::pairs(&[]));
support::assert_json(&calls[0].body, &support::json(r#"{"messageId":"messageId 1"}"#));
assert!(calls[0].header(sdk::IDEMPOTENCY_HEADER).is_some_and(|key| !key.is_empty()));
}
#[tokio::test]
async fn add_retries_with_one_key() {
let response = support::json(r#"{
"object": "favorite_sticker",
"id": "id 1",
"accountId": "accountId 1",
"mimeType": "mimeType 1",
"animated": true,
"lottie": true,
"width": 1,
"height": 1,
"size": 1,
"emojis": [
"emojis 1"
],
"favoritedAt": "2026-09-24T09:00:00.000Z",
"media": {
"url": "url 1",
"downloaded": true
}
}"#);
let api = support::MockApi::start(vec![support::Reply::status(503), support::Reply::json(201, response.clone())]).await;
let params: types::FavoriteStickersAddParams = support::from_json(r#"{"messageId":"messageId 1"}"#);
let result = api.client().favorite_stickers().add("k57a8m2x9d3f0q1wjh6ypc4n2d7s0vbr", params).await.unwrap();
support::assert_json(&result, &response);
let calls = api.calls().await;
assert_eq!(calls.len(), 2);
let key = calls[0].header(sdk::IDEMPOTENCY_HEADER).unwrap();
assert!(!key.is_empty());
assert_eq!(calls[1].header(sdk::IDEMPOTENCY_HEADER), Some(key));
assert_eq!(calls[0].body, calls[1].body);
}
#[tokio::test]
async fn remove() {
let api = support::MockApi::start(vec![support::Reply::status(204)]).await;
api.client().favorite_stickers().remove("k57a8m2x9d3f0q1wjh6ypc4n2d7s0vbr", "p97f3h6k9m2q5t8w1z4c7e0g3j6n9r2u").await.unwrap();
let calls = api.calls().await;
assert_eq!(calls.len(), 1);
assert_eq!(calls[0].method, "DELETE");
assert_eq!(calls[0].path, "/v1/accounts/k57a8m2x9d3f0q1wjh6ypc4n2d7s0vbr/stickers/favorites/p97f3h6k9m2q5t8w1z4c7e0g3j6n9r2u");
assert_eq!(calls[0].query, support::pairs(&[]));
assert!(calls[0].body.is_none());
assert!(calls[0].header(sdk::IDEMPOTENCY_HEADER).is_none());
}
#[tokio::test]
async fn get_media() {
let response = support::json(r#"{
"object": "media",
"stickerId": "stickerId 1",
"url": "url 1",
"mimeType": "mimeType 1",
"size": 1
}"#);
let api = support::MockApi::start(vec![support::Reply::json(200, response.clone())]).await;
let params: types::FavoriteStickersGetMediaParams = support::from_json(r#"{"redirect":true}"#);
let result = api.client().favorite_stickers().get_media("k57a8m2x9d3f0q1wjh6ypc4n2d7s0vbr", "p97f3h6k9m2q5t8w1z4c7e0g3j6n9r2u", params).await.unwrap();
support::assert_json(&result, &response);
let calls = api.calls().await;
assert_eq!(calls.len(), 1);
assert_eq!(calls[0].method, "GET");
assert_eq!(calls[0].path, "/v1/accounts/k57a8m2x9d3f0q1wjh6ypc4n2d7s0vbr/stickers/favorites/p97f3h6k9m2q5t8w1z4c7e0g3j6n9r2u/media");
assert_eq!(calls[0].query, support::pairs(&[("redirect", "true")]));
assert!(calls[0].body.is_none());
assert!(calls[0].header(sdk::IDEMPOTENCY_HEADER).is_none());
}
#[tokio::test]
async fn get_media_without_params() {
let response = support::json(r#"{
"object": "media",
"stickerId": "stickerId 1",
"url": "url 1",
"mimeType": "mimeType 1",
"size": 1
}"#);
let api = support::MockApi::start(vec![support::Reply::json(200, response.clone())]).await;
let result = api.client().favorite_stickers().get_media("k57a8m2x9d3f0q1wjh6ypc4n2d7s0vbr", "p97f3h6k9m2q5t8w1z4c7e0g3j6n9r2u", Default::default()).await.unwrap();
support::assert_json(&result, &response);
let calls = api.calls().await;
assert_eq!(calls.len(), 1);
assert_eq!(calls[0].method, "GET");
assert_eq!(calls[0].path, "/v1/accounts/k57a8m2x9d3f0q1wjh6ypc4n2d7s0vbr/stickers/favorites/p97f3h6k9m2q5t8w1z4c7e0g3j6n9r2u/media");
assert_eq!(calls[0].query, support::pairs(&[]));
assert!(calls[0].body.is_none());
assert!(calls[0].header(sdk::IDEMPOTENCY_HEADER).is_none());
}
}
mod orders {
use super::*;
#[tokio::test]
async fn get() {
let response = support::json(r#"{
"object": "order",
"id": "id 1",
"currency": "currency 1",
"subtotalCents": 1,
"totalCents": 1,
"products": [
{
"id": "id 1",
"name": "name 1",
"quantity": 1,
"priceCents": 1,
"currency": "currency 1",
"imageUrl": "imageUrl 1"
}
],
"createdAt": "2026-09-24T09:00:00.000Z"
}"#);
let api = support::MockApi::start(vec![support::Reply::json(200, response.clone())]).await;
let params: types::OrdersGetParams = support::from_json(r#"{"token":"token 1"}"#);
let result = api.client().orders().get("k57a8m2x9d3f0q1wjh6ypc4n2d7s0vbr", "1234567890123456", params).await.unwrap();
support::assert_json(&result, &response);
let calls = api.calls().await;
assert_eq!(calls.len(), 1);
assert_eq!(calls[0].method, "GET");
assert_eq!(calls[0].path, "/v1/accounts/k57a8m2x9d3f0q1wjh6ypc4n2d7s0vbr/orders/1234567890123456");
assert_eq!(calls[0].query, support::pairs(&[("token", "token 1")]));
assert!(calls[0].body.is_none());
assert!(calls[0].header(sdk::IDEMPOTENCY_HEADER).is_none());
}
}
mod groups {
use super::*;
#[tokio::test]
async fn list_streams_every_page() {
let first = support::json(r#"{
"object": "list",
"items": [
{
"object": "group",
"id": "id 1",
"accountId": "accountId 1",
"name": "name 1",
"description": "description 1",
"ownerId": "ownerId 1",
"community": true,
"communityId": "communityId 1",
"default": true,
"locked": true,
"announce": true,
"participants": [
{
"contactId": "contactId 1",
"name": "name 1",
"role": "member"
}
],
"createdAt": "2026-09-24T09:00:00.000Z"
}
],
"nextCursor": "cursor_2"
}"#);
let last = support::json(r#"{
"object": "list",
"items": [
{
"object": "group",
"id": "id 1",
"accountId": "accountId 1",
"name": "name 1",
"description": "description 1",
"ownerId": "ownerId 1",
"community": true,
"communityId": "communityId 1",
"default": true,
"locked": true,
"announce": true,
"participants": [
{
"contactId": "contactId 1",
"name": "name 1",
"role": "member"
}
],
"createdAt": "2026-09-24T09:00:00.000Z"
}
],
"nextCursor": null
}"#);
let api = support::MockApi::start(vec![
support::Reply::json(200, first),
support::Reply::json(200, last),
])
.await;
let params: types::GroupsListParams = support::from_json(r#"{"limit":50,"cursor":"cursor 1"}"#);
let items = api.client().groups().list("k57a8m2x9d3f0q1wjh6ypc4n2d7s0vbr", params).to_vec().await.unwrap();
support::assert_json(&items, &support::json(r#"[
{
"object": "group",
"id": "id 1",
"accountId": "accountId 1",
"name": "name 1",
"description": "description 1",
"ownerId": "ownerId 1",
"community": true,
"communityId": "communityId 1",
"default": true,
"locked": true,
"announce": true,
"participants": [
{
"contactId": "contactId 1",
"name": "name 1",
"role": "member"
}
],
"createdAt": "2026-09-24T09:00:00.000Z"
},
{
"object": "group",
"id": "id 1",
"accountId": "accountId 1",
"name": "name 1",
"description": "description 1",
"ownerId": "ownerId 1",
"community": true,
"communityId": "communityId 1",
"default": true,
"locked": true,
"announce": true,
"participants": [
{
"contactId": "contactId 1",
"name": "name 1",
"role": "member"
}
],
"createdAt": "2026-09-24T09:00:00.000Z"
}
]"#));
let calls = api.calls().await;
assert_eq!(calls.len(), 2);
assert_eq!(calls[0].method, "GET");
assert_eq!(calls[0].path, "/v1/accounts/k57a8m2x9d3f0q1wjh6ypc4n2d7s0vbr/groups");
assert_eq!(calls[0].query, support::pairs(&[("limit", "50"), ("cursor", "cursor 1")]));
assert_eq!(calls[1].query, support::pairs(&[("limit", "50"), ("cursor", "cursor_2")]));
}
#[tokio::test]
async fn list_fetches_one_page() {
let page = support::json(r#"{
"object": "list",
"items": [
{
"object": "group",
"id": "id 1",
"accountId": "accountId 1",
"name": "name 1",
"description": "description 1",
"ownerId": "ownerId 1",
"community": true,
"communityId": "communityId 1",
"default": true,
"locked": true,
"announce": true,
"participants": [
{
"contactId": "contactId 1",
"name": "name 1",
"role": "member"
}
],
"createdAt": "2026-09-24T09:00:00.000Z"
}
],
"nextCursor": null
}"#);
let api = support::MockApi::start(vec![support::Reply::json(200, page.clone())]).await;
let result = api.client().groups().list("k57a8m2x9d3f0q1wjh6ypc4n2d7s0vbr", Default::default()).page().await.unwrap();
support::assert_json(&result, &page);
let calls = api.calls().await;
assert_eq!(calls.len(), 1);
assert_eq!(calls[0].method, "GET");
assert_eq!(calls[0].path, "/v1/accounts/k57a8m2x9d3f0q1wjh6ypc4n2d7s0vbr/groups");
assert_eq!(calls[0].query, support::pairs(&[]));
}
#[tokio::test]
async fn create() {
let response = support::json(r#"{
"object": "group",
"id": "id 1",
"accountId": "accountId 1",
"name": "name 1",
"description": "description 1",
"ownerId": "ownerId 1",
"community": true,
"communityId": "communityId 1",
"default": true,
"locked": true,
"announce": true,
"participants": [
{
"contactId": "contactId 1",
"name": "name 1",
"role": "member"
}
],
"createdAt": "2026-09-24T09:00:00.000Z"
}"#);
let api = support::MockApi::start(vec![support::Reply::json(201, response.clone())]).await;
let params: types::GroupsCreateParams = support::from_json(r#"{
"name": "name 1",
"participants": [
"participants 1"
],
"community": true,
"communityId": "communityId 1"
}"#);
let result = api.client().groups().create("k57a8m2x9d3f0q1wjh6ypc4n2d7s0vbr", params).await.unwrap();
support::assert_json(&result, &response);
let calls = api.calls().await;
assert_eq!(calls.len(), 1);
assert_eq!(calls[0].method, "POST");
assert_eq!(calls[0].path, "/v1/accounts/k57a8m2x9d3f0q1wjh6ypc4n2d7s0vbr/groups");
assert_eq!(calls[0].query, support::pairs(&[]));
support::assert_json(&calls[0].body, &support::json(r#"{
"name": "name 1",
"participants": [
"participants 1"
],
"community": true,
"communityId": "communityId 1"
}"#));
assert!(calls[0].header(sdk::IDEMPOTENCY_HEADER).is_some_and(|key| !key.is_empty()));
}
#[tokio::test]
async fn create_retries_with_one_key() {
let response = support::json(r#"{
"object": "group",
"id": "id 1",
"accountId": "accountId 1",
"name": "name 1",
"description": "description 1",
"ownerId": "ownerId 1",
"community": true,
"communityId": "communityId 1",
"default": true,
"locked": true,
"announce": true,
"participants": [
{
"contactId": "contactId 1",
"name": "name 1",
"role": "member"
}
],
"createdAt": "2026-09-24T09:00:00.000Z"
}"#);
let api = support::MockApi::start(vec![support::Reply::status(503), support::Reply::json(201, response.clone())]).await;
let params: types::GroupsCreateParams = support::from_json(r#"{
"name": "name 1",
"participants": [
"participants 1"
],
"community": true,
"communityId": "communityId 1"
}"#);
let result = api.client().groups().create("k57a8m2x9d3f0q1wjh6ypc4n2d7s0vbr", params).await.unwrap();
support::assert_json(&result, &response);
let calls = api.calls().await;
assert_eq!(calls.len(), 2);
let key = calls[0].header(sdk::IDEMPOTENCY_HEADER).unwrap();
assert!(!key.is_empty());
assert_eq!(calls[1].header(sdk::IDEMPOTENCY_HEADER), Some(key));
assert_eq!(calls[0].body, calls[1].body);
}
#[tokio::test]
async fn join() {
let response = support::json(r#"{"object":"group_join","accountId":"accountId 1","groupId":"groupId 1"}"#);
let api = support::MockApi::start(vec![support::Reply::json(200, response.clone())]).await;
let params: types::GroupsJoinParams = support::from_json(r#"{"code":"code 1"}"#);
let result = api.client().groups().join("k57a8m2x9d3f0q1wjh6ypc4n2d7s0vbr", params).await.unwrap();
support::assert_json(&result, &response);
let calls = api.calls().await;
assert_eq!(calls.len(), 1);
assert_eq!(calls[0].method, "POST");
assert_eq!(calls[0].path, "/v1/accounts/k57a8m2x9d3f0q1wjh6ypc4n2d7s0vbr/groups/join");
assert_eq!(calls[0].query, support::pairs(&[]));
support::assert_json(&calls[0].body, &support::json(r#"{"code":"code 1"}"#));
assert!(calls[0].header(sdk::IDEMPOTENCY_HEADER).is_some_and(|key| !key.is_empty()));
}
#[tokio::test]
async fn join_retries_with_one_key() {
let response = support::json(r#"{"object":"group_join","accountId":"accountId 1","groupId":"groupId 1"}"#);
let api = support::MockApi::start(vec![support::Reply::status(503), support::Reply::json(200, response.clone())]).await;
let params: types::GroupsJoinParams = support::from_json(r#"{"code":"code 1"}"#);
let result = api.client().groups().join("k57a8m2x9d3f0q1wjh6ypc4n2d7s0vbr", params).await.unwrap();
support::assert_json(&result, &response);
let calls = api.calls().await;
assert_eq!(calls.len(), 2);
let key = calls[0].header(sdk::IDEMPOTENCY_HEADER).unwrap();
assert!(!key.is_empty());
assert_eq!(calls[1].header(sdk::IDEMPOTENCY_HEADER), Some(key));
assert_eq!(calls[0].body, calls[1].body);
}
#[tokio::test]
async fn get_invite() {
let response = support::json(r#"{
"object": "group",
"id": "id 1",
"accountId": "accountId 1",
"name": "name 1",
"description": "description 1",
"ownerId": "ownerId 1",
"community": true,
"communityId": "communityId 1",
"default": true,
"locked": true,
"announce": true,
"participants": [
{
"contactId": "contactId 1",
"name": "name 1",
"role": "member"
}
],
"createdAt": "2026-09-24T09:00:00.000Z"
}"#);
let api = support::MockApi::start(vec![support::Reply::json(200, response.clone())]).await;
let result = api.client().groups().get_invite("k57a8m2x9d3f0q1wjh6ypc4n2d7s0vbr", "AbCdEf123456").await.unwrap();
support::assert_json(&result, &response);
let calls = api.calls().await;
assert_eq!(calls.len(), 1);
assert_eq!(calls[0].method, "GET");
assert_eq!(calls[0].path, "/v1/accounts/k57a8m2x9d3f0q1wjh6ypc4n2d7s0vbr/groups/invites/AbCdEf123456");
assert_eq!(calls[0].query, support::pairs(&[]));
assert!(calls[0].body.is_none());
assert!(calls[0].header(sdk::IDEMPOTENCY_HEADER).is_none());
}
#[tokio::test]
async fn get() {
let response = support::json(r#"{
"object": "group",
"id": "id 1",
"accountId": "accountId 1",
"name": "name 1",
"description": "description 1",
"ownerId": "ownerId 1",
"community": true,
"communityId": "communityId 1",
"default": true,
"locked": true,
"announce": true,
"participants": [
{
"contactId": "contactId 1",
"name": "name 1",
"role": "member"
}
],
"createdAt": "2026-09-24T09:00:00.000Z"
}"#);
let api = support::MockApi::start(vec![support::Reply::json(200, response.clone())]).await;
let result = api.client().groups().get("k57a8m2x9d3f0q1wjh6ypc4n2d7s0vbr", "120363041234567890@g.us").await.unwrap();
support::assert_json(&result, &response);
let calls = api.calls().await;
assert_eq!(calls.len(), 1);
assert_eq!(calls[0].method, "GET");
assert_eq!(calls[0].path, "/v1/accounts/k57a8m2x9d3f0q1wjh6ypc4n2d7s0vbr/groups/120363041234567890%40g.us");
assert_eq!(calls[0].query, support::pairs(&[]));
assert!(calls[0].body.is_none());
assert!(calls[0].header(sdk::IDEMPOTENCY_HEADER).is_none());
}
#[tokio::test]
async fn update() {
let response = support::json(r#"{
"object": "group",
"id": "id 1",
"accountId": "accountId 1",
"name": "name 1",
"description": "description 1",
"ownerId": "ownerId 1",
"community": true,
"communityId": "communityId 1",
"default": true,
"locked": true,
"announce": true,
"participants": [
{
"contactId": "contactId 1",
"name": "name 1",
"role": "member"
}
],
"createdAt": "2026-09-24T09:00:00.000Z"
}"#);
let api = support::MockApi::start(vec![support::Reply::json(200, response.clone())]).await;
let params: types::GroupsUpdateParams = support::from_json(r#"{
"name": "name 1",
"description": "description 1",
"announce": true,
"locked": true,
"joinApproval": true,
"memberAddMode": "admins"
}"#);
let result = api.client().groups().update("k57a8m2x9d3f0q1wjh6ypc4n2d7s0vbr", "120363041234567890@g.us", params).await.unwrap();
support::assert_json(&result, &response);
let calls = api.calls().await;
assert_eq!(calls.len(), 1);
assert_eq!(calls[0].method, "PATCH");
assert_eq!(calls[0].path, "/v1/accounts/k57a8m2x9d3f0q1wjh6ypc4n2d7s0vbr/groups/120363041234567890%40g.us");
assert_eq!(calls[0].query, support::pairs(&[]));
support::assert_json(&calls[0].body, &support::json(r#"{
"name": "name 1",
"description": "description 1",
"announce": true,
"locked": true,
"joinApproval": true,
"memberAddMode": "admins"
}"#));
assert!(calls[0].header(sdk::IDEMPOTENCY_HEADER).is_none());
}
#[tokio::test]
async fn update_without_params() {
let response = support::json(r#"{
"object": "group",
"id": "id 1",
"accountId": "accountId 1",
"name": "name 1",
"description": "description 1",
"ownerId": "ownerId 1",
"community": true,
"communityId": "communityId 1",
"default": true,
"locked": true,
"announce": true,
"participants": [
{
"contactId": "contactId 1",
"name": "name 1",
"role": "member"
}
],
"createdAt": "2026-09-24T09:00:00.000Z"
}"#);
let api = support::MockApi::start(vec![support::Reply::json(200, response.clone())]).await;
let result = api.client().groups().update("k57a8m2x9d3f0q1wjh6ypc4n2d7s0vbr", "120363041234567890@g.us", Default::default()).await.unwrap();
support::assert_json(&result, &response);
let calls = api.calls().await;
assert_eq!(calls.len(), 1);
assert_eq!(calls[0].method, "PATCH");
assert_eq!(calls[0].path, "/v1/accounts/k57a8m2x9d3f0q1wjh6ypc4n2d7s0vbr/groups/120363041234567890%40g.us");
assert_eq!(calls[0].query, support::pairs(&[]));
support::assert_json(&calls[0].body, &support::json(r#"{}"#));
assert!(calls[0].header(sdk::IDEMPOTENCY_HEADER).is_none());
}
#[tokio::test]
async fn update_is_not_repeated() {
let api = support::MockApi::start(vec![
support::Reply::status(503),
support::Reply::status(503),
])
.await;
let params: types::GroupsUpdateParams = support::from_json(r#"{
"name": "name 1",
"description": "description 1",
"announce": true,
"locked": true,
"joinApproval": true,
"memberAddMode": "admins"
}"#);
let error = api.client().groups().update("k57a8m2x9d3f0q1wjh6ypc4n2d7s0vbr", "120363041234567890@g.us", params).await.unwrap_err();
assert_eq!(error.status(), Some(503));
assert_eq!(api.calls().await.len(), 1);
}
#[tokio::test]
async fn leave() {
let api = support::MockApi::start(vec![support::Reply::status(204)]).await;
api.client().groups().leave("k57a8m2x9d3f0q1wjh6ypc4n2d7s0vbr", "120363041234567890@g.us").await.unwrap();
let calls = api.calls().await;
assert_eq!(calls.len(), 1);
assert_eq!(calls[0].method, "POST");
assert_eq!(calls[0].path, "/v1/accounts/k57a8m2x9d3f0q1wjh6ypc4n2d7s0vbr/groups/120363041234567890%40g.us/leave");
assert_eq!(calls[0].query, support::pairs(&[]));
assert!(calls[0].body.is_none());
assert!(calls[0].header(sdk::IDEMPOTENCY_HEADER).is_some_and(|key| !key.is_empty()));
}
#[tokio::test]
async fn leave_retries_with_one_key() {
let api = support::MockApi::start(vec![support::Reply::status(503), support::Reply::status(204)]).await;
api.client().groups().leave("k57a8m2x9d3f0q1wjh6ypc4n2d7s0vbr", "120363041234567890@g.us").await.unwrap();
let calls = api.calls().await;
assert_eq!(calls.len(), 2);
let key = calls[0].header(sdk::IDEMPOTENCY_HEADER).unwrap();
assert!(!key.is_empty());
assert_eq!(calls[1].header(sdk::IDEMPOTENCY_HEADER), Some(key));
assert_eq!(calls[0].body, calls[1].body);
}
#[tokio::test]
async fn add_participants() {
let response = support::json(r#"{
"object": "list",
"items": [
{
"object": "participant_result",
"contactId": "contactId 1",
"error": "error 1",
"inviteCode": "inviteCode 1"
}
],
"nextCursor": "nextCursor 1"
}"#);
let api = support::MockApi::start(vec![support::Reply::json(200, response.clone())]).await;
let params: types::GroupsAddParticipantsParams = support::from_json(r#"{"contactIds":["contactIds 1"]}"#);
let result = api.client().groups().add_participants("k57a8m2x9d3f0q1wjh6ypc4n2d7s0vbr", "120363041234567890@g.us", params).await.unwrap();
support::assert_json(&result, &response);
let calls = api.calls().await;
assert_eq!(calls.len(), 1);
assert_eq!(calls[0].method, "POST");
assert_eq!(calls[0].path, "/v1/accounts/k57a8m2x9d3f0q1wjh6ypc4n2d7s0vbr/groups/120363041234567890%40g.us/participants/add");
assert_eq!(calls[0].query, support::pairs(&[]));
support::assert_json(&calls[0].body, &support::json(r#"{"contactIds":["contactIds 1"]}"#));
assert!(calls[0].header(sdk::IDEMPOTENCY_HEADER).is_some_and(|key| !key.is_empty()));
}
#[tokio::test]
async fn add_participants_retries_with_one_key() {
let response = support::json(r#"{
"object": "list",
"items": [
{
"object": "participant_result",
"contactId": "contactId 1",
"error": "error 1",
"inviteCode": "inviteCode 1"
}
],
"nextCursor": "nextCursor 1"
}"#);
let api = support::MockApi::start(vec![support::Reply::status(503), support::Reply::json(200, response.clone())]).await;
let params: types::GroupsAddParticipantsParams = support::from_json(r#"{"contactIds":["contactIds 1"]}"#);
let result = api.client().groups().add_participants("k57a8m2x9d3f0q1wjh6ypc4n2d7s0vbr", "120363041234567890@g.us", params).await.unwrap();
support::assert_json(&result, &response);
let calls = api.calls().await;
assert_eq!(calls.len(), 2);
let key = calls[0].header(sdk::IDEMPOTENCY_HEADER).unwrap();
assert!(!key.is_empty());
assert_eq!(calls[1].header(sdk::IDEMPOTENCY_HEADER), Some(key));
assert_eq!(calls[0].body, calls[1].body);
}
#[tokio::test]
async fn remove_participants() {
let response = support::json(r#"{
"object": "list",
"items": [
{
"object": "participant_result",
"contactId": "contactId 1",
"error": "error 1",
"inviteCode": "inviteCode 1"
}
],
"nextCursor": "nextCursor 1"
}"#);
let api = support::MockApi::start(vec![support::Reply::json(200, response.clone())]).await;
let params: types::GroupsRemoveParticipantsParams = support::from_json(r#"{"contactIds":["contactIds 1"]}"#);
let result = api.client().groups().remove_participants("k57a8m2x9d3f0q1wjh6ypc4n2d7s0vbr", "120363041234567890@g.us", params).await.unwrap();
support::assert_json(&result, &response);
let calls = api.calls().await;
assert_eq!(calls.len(), 1);
assert_eq!(calls[0].method, "POST");
assert_eq!(calls[0].path, "/v1/accounts/k57a8m2x9d3f0q1wjh6ypc4n2d7s0vbr/groups/120363041234567890%40g.us/participants/remove");
assert_eq!(calls[0].query, support::pairs(&[]));
support::assert_json(&calls[0].body, &support::json(r#"{"contactIds":["contactIds 1"]}"#));
assert!(calls[0].header(sdk::IDEMPOTENCY_HEADER).is_some_and(|key| !key.is_empty()));
}
#[tokio::test]
async fn remove_participants_retries_with_one_key() {
let response = support::json(r#"{
"object": "list",
"items": [
{
"object": "participant_result",
"contactId": "contactId 1",
"error": "error 1",
"inviteCode": "inviteCode 1"
}
],
"nextCursor": "nextCursor 1"
}"#);
let api = support::MockApi::start(vec![support::Reply::status(503), support::Reply::json(200, response.clone())]).await;
let params: types::GroupsRemoveParticipantsParams = support::from_json(r#"{"contactIds":["contactIds 1"]}"#);
let result = api.client().groups().remove_participants("k57a8m2x9d3f0q1wjh6ypc4n2d7s0vbr", "120363041234567890@g.us", params).await.unwrap();
support::assert_json(&result, &response);
let calls = api.calls().await;
assert_eq!(calls.len(), 2);
let key = calls[0].header(sdk::IDEMPOTENCY_HEADER).unwrap();
assert!(!key.is_empty());
assert_eq!(calls[1].header(sdk::IDEMPOTENCY_HEADER), Some(key));
assert_eq!(calls[0].body, calls[1].body);
}
#[tokio::test]
async fn promote_participants() {
let response = support::json(r#"{
"object": "list",
"items": [
{
"object": "participant_result",
"contactId": "contactId 1",
"error": "error 1",
"inviteCode": "inviteCode 1"
}
],
"nextCursor": "nextCursor 1"
}"#);
let api = support::MockApi::start(vec![support::Reply::json(200, response.clone())]).await;
let params: types::GroupsPromoteParticipantsParams = support::from_json(r#"{"contactIds":["contactIds 1"]}"#);
let result = api.client().groups().promote_participants("k57a8m2x9d3f0q1wjh6ypc4n2d7s0vbr", "120363041234567890@g.us", params).await.unwrap();
support::assert_json(&result, &response);
let calls = api.calls().await;
assert_eq!(calls.len(), 1);
assert_eq!(calls[0].method, "POST");
assert_eq!(calls[0].path, "/v1/accounts/k57a8m2x9d3f0q1wjh6ypc4n2d7s0vbr/groups/120363041234567890%40g.us/participants/promote");
assert_eq!(calls[0].query, support::pairs(&[]));
support::assert_json(&calls[0].body, &support::json(r#"{"contactIds":["contactIds 1"]}"#));
assert!(calls[0].header(sdk::IDEMPOTENCY_HEADER).is_some_and(|key| !key.is_empty()));
}
#[tokio::test]
async fn promote_participants_retries_with_one_key() {
let response = support::json(r#"{
"object": "list",
"items": [
{
"object": "participant_result",
"contactId": "contactId 1",
"error": "error 1",
"inviteCode": "inviteCode 1"
}
],
"nextCursor": "nextCursor 1"
}"#);
let api = support::MockApi::start(vec![support::Reply::status(503), support::Reply::json(200, response.clone())]).await;
let params: types::GroupsPromoteParticipantsParams = support::from_json(r#"{"contactIds":["contactIds 1"]}"#);
let result = api.client().groups().promote_participants("k57a8m2x9d3f0q1wjh6ypc4n2d7s0vbr", "120363041234567890@g.us", params).await.unwrap();
support::assert_json(&result, &response);
let calls = api.calls().await;
assert_eq!(calls.len(), 2);
let key = calls[0].header(sdk::IDEMPOTENCY_HEADER).unwrap();
assert!(!key.is_empty());
assert_eq!(calls[1].header(sdk::IDEMPOTENCY_HEADER), Some(key));
assert_eq!(calls[0].body, calls[1].body);
}
#[tokio::test]
async fn demote_participants() {
let response = support::json(r#"{
"object": "list",
"items": [
{
"object": "participant_result",
"contactId": "contactId 1",
"error": "error 1",
"inviteCode": "inviteCode 1"
}
],
"nextCursor": "nextCursor 1"
}"#);
let api = support::MockApi::start(vec![support::Reply::json(200, response.clone())]).await;
let params: types::GroupsDemoteParticipantsParams = support::from_json(r#"{"contactIds":["contactIds 1"]}"#);
let result = api.client().groups().demote_participants("k57a8m2x9d3f0q1wjh6ypc4n2d7s0vbr", "120363041234567890@g.us", params).await.unwrap();
support::assert_json(&result, &response);
let calls = api.calls().await;
assert_eq!(calls.len(), 1);
assert_eq!(calls[0].method, "POST");
assert_eq!(calls[0].path, "/v1/accounts/k57a8m2x9d3f0q1wjh6ypc4n2d7s0vbr/groups/120363041234567890%40g.us/participants/demote");
assert_eq!(calls[0].query, support::pairs(&[]));
support::assert_json(&calls[0].body, &support::json(r#"{"contactIds":["contactIds 1"]}"#));
assert!(calls[0].header(sdk::IDEMPOTENCY_HEADER).is_some_and(|key| !key.is_empty()));
}
#[tokio::test]
async fn demote_participants_retries_with_one_key() {
let response = support::json(r#"{
"object": "list",
"items": [
{
"object": "participant_result",
"contactId": "contactId 1",
"error": "error 1",
"inviteCode": "inviteCode 1"
}
],
"nextCursor": "nextCursor 1"
}"#);
let api = support::MockApi::start(vec![support::Reply::status(503), support::Reply::json(200, response.clone())]).await;
let params: types::GroupsDemoteParticipantsParams = support::from_json(r#"{"contactIds":["contactIds 1"]}"#);
let result = api.client().groups().demote_participants("k57a8m2x9d3f0q1wjh6ypc4n2d7s0vbr", "120363041234567890@g.us", params).await.unwrap();
support::assert_json(&result, &response);
let calls = api.calls().await;
assert_eq!(calls.len(), 2);
let key = calls[0].header(sdk::IDEMPOTENCY_HEADER).unwrap();
assert!(!key.is_empty());
assert_eq!(calls[1].header(sdk::IDEMPOTENCY_HEADER), Some(key));
assert_eq!(calls[0].body, calls[1].body);
}
#[tokio::test]
async fn get_invite_link() {
let response = support::json(r#"{"object":"group_invite_link","groupId":"groupId 1","url":"url 1"}"#);
let api = support::MockApi::start(vec![support::Reply::json(200, response.clone())]).await;
let result = api.client().groups().get_invite_link("k57a8m2x9d3f0q1wjh6ypc4n2d7s0vbr", "120363041234567890@g.us").await.unwrap();
support::assert_json(&result, &response);
let calls = api.calls().await;
assert_eq!(calls.len(), 1);
assert_eq!(calls[0].method, "GET");
assert_eq!(calls[0].path, "/v1/accounts/k57a8m2x9d3f0q1wjh6ypc4n2d7s0vbr/groups/120363041234567890%40g.us/invite-link");
assert_eq!(calls[0].query, support::pairs(&[]));
assert!(calls[0].body.is_none());
assert!(calls[0].header(sdk::IDEMPOTENCY_HEADER).is_none());
}
#[tokio::test]
async fn reset_invite_link() {
let response = support::json(r#"{"object":"group_invite_link","groupId":"groupId 1","url":"url 1"}"#);
let api = support::MockApi::start(vec![support::Reply::json(200, response.clone())]).await;
let result = api.client().groups().reset_invite_link("k57a8m2x9d3f0q1wjh6ypc4n2d7s0vbr", "120363041234567890@g.us").await.unwrap();
support::assert_json(&result, &response);
let calls = api.calls().await;
assert_eq!(calls.len(), 1);
assert_eq!(calls[0].method, "POST");
assert_eq!(calls[0].path, "/v1/accounts/k57a8m2x9d3f0q1wjh6ypc4n2d7s0vbr/groups/120363041234567890%40g.us/invite-link/reset");
assert_eq!(calls[0].query, support::pairs(&[]));
assert!(calls[0].body.is_none());
assert!(calls[0].header(sdk::IDEMPOTENCY_HEADER).is_some_and(|key| !key.is_empty()));
}
#[tokio::test]
async fn reset_invite_link_retries_with_one_key() {
let response = support::json(r#"{"object":"group_invite_link","groupId":"groupId 1","url":"url 1"}"#);
let api = support::MockApi::start(vec![support::Reply::status(503), support::Reply::json(200, response.clone())]).await;
let result = api.client().groups().reset_invite_link("k57a8m2x9d3f0q1wjh6ypc4n2d7s0vbr", "120363041234567890@g.us").await.unwrap();
support::assert_json(&result, &response);
let calls = api.calls().await;
assert_eq!(calls.len(), 2);
let key = calls[0].header(sdk::IDEMPOTENCY_HEADER).unwrap();
assert!(!key.is_empty());
assert_eq!(calls[1].header(sdk::IDEMPOTENCY_HEADER), Some(key));
assert_eq!(calls[0].body, calls[1].body);
}
#[tokio::test]
async fn set_picture() {
let response = support::json(r#"{"object":"picture","id":"id 1","url":"url 1","preview":true}"#);
let api = support::MockApi::start(vec![support::Reply::json(200, response.clone())]).await;
let params: types::GroupsSetPictureParams = support::from_json(r#"{"url":"https://example.com/url"}"#);
let result = api.client().groups().set_picture("k57a8m2x9d3f0q1wjh6ypc4n2d7s0vbr", "120363041234567890@g.us", params).await.unwrap();
support::assert_json(&result, &response);
let calls = api.calls().await;
assert_eq!(calls.len(), 1);
assert_eq!(calls[0].method, "PUT");
assert_eq!(calls[0].path, "/v1/accounts/k57a8m2x9d3f0q1wjh6ypc4n2d7s0vbr/groups/120363041234567890%40g.us/picture");
assert_eq!(calls[0].query, support::pairs(&[]));
support::assert_json(&calls[0].body, &support::json(r#"{"url":"https://example.com/url"}"#));
assert!(calls[0].header(sdk::IDEMPOTENCY_HEADER).is_none());
}
#[tokio::test]
async fn delete_picture() {
let api = support::MockApi::start(vec![support::Reply::status(204)]).await;
api.client().groups().delete_picture("k57a8m2x9d3f0q1wjh6ypc4n2d7s0vbr", "120363041234567890@g.us").await.unwrap();
let calls = api.calls().await;
assert_eq!(calls.len(), 1);
assert_eq!(calls[0].method, "DELETE");
assert_eq!(calls[0].path, "/v1/accounts/k57a8m2x9d3f0q1wjh6ypc4n2d7s0vbr/groups/120363041234567890%40g.us/picture");
assert_eq!(calls[0].query, support::pairs(&[]));
assert!(calls[0].body.is_none());
assert!(calls[0].header(sdk::IDEMPOTENCY_HEADER).is_none());
}
#[tokio::test]
async fn list_join_requests_streams_every_page() {
let first = support::json(r#"{
"object": "list",
"items": [
{
"object": "group_join_request",
"accountId": "accountId 1",
"groupId": "groupId 1",
"contactId": "contactId 1",
"requestedAt": "2026-09-24T09:00:00.000Z"
}
],
"nextCursor": "cursor_2"
}"#);
let last = support::json(r#"{
"object": "list",
"items": [
{
"object": "group_join_request",
"accountId": "accountId 1",
"groupId": "groupId 1",
"contactId": "contactId 1",
"requestedAt": "2026-09-24T09:00:00.000Z"
}
],
"nextCursor": null
}"#);
let api = support::MockApi::start(vec![
support::Reply::json(200, first),
support::Reply::json(200, last),
])
.await;
let params: types::GroupsListJoinRequestsParams = support::from_json(r#"{"limit":50,"cursor":"cursor 1"}"#);
let items = api.client().groups().list_join_requests("k57a8m2x9d3f0q1wjh6ypc4n2d7s0vbr", "120363041234567890@g.us", params).to_vec().await.unwrap();
support::assert_json(&items, &support::json(r#"[
{
"object": "group_join_request",
"accountId": "accountId 1",
"groupId": "groupId 1",
"contactId": "contactId 1",
"requestedAt": "2026-09-24T09:00:00.000Z"
},
{
"object": "group_join_request",
"accountId": "accountId 1",
"groupId": "groupId 1",
"contactId": "contactId 1",
"requestedAt": "2026-09-24T09:00:00.000Z"
}
]"#));
let calls = api.calls().await;
assert_eq!(calls.len(), 2);
assert_eq!(calls[0].method, "GET");
assert_eq!(calls[0].path, "/v1/accounts/k57a8m2x9d3f0q1wjh6ypc4n2d7s0vbr/groups/120363041234567890%40g.us/join-requests");
assert_eq!(calls[0].query, support::pairs(&[("limit", "50"), ("cursor", "cursor 1")]));
assert_eq!(calls[1].query, support::pairs(&[("limit", "50"), ("cursor", "cursor_2")]));
}
#[tokio::test]
async fn list_join_requests_fetches_one_page() {
let page = support::json(r#"{
"object": "list",
"items": [
{
"object": "group_join_request",
"accountId": "accountId 1",
"groupId": "groupId 1",
"contactId": "contactId 1",
"requestedAt": "2026-09-24T09:00:00.000Z"
}
],
"nextCursor": null
}"#);
let api = support::MockApi::start(vec![support::Reply::json(200, page.clone())]).await;
let result = api.client().groups().list_join_requests("k57a8m2x9d3f0q1wjh6ypc4n2d7s0vbr", "120363041234567890@g.us", Default::default()).page().await.unwrap();
support::assert_json(&result, &page);
let calls = api.calls().await;
assert_eq!(calls.len(), 1);
assert_eq!(calls[0].method, "GET");
assert_eq!(calls[0].path, "/v1/accounts/k57a8m2x9d3f0q1wjh6ypc4n2d7s0vbr/groups/120363041234567890%40g.us/join-requests");
assert_eq!(calls[0].query, support::pairs(&[]));
}
#[tokio::test]
async fn approve_join_requests() {
let response = support::json(r#"{
"object": "list",
"items": [
{
"object": "participant_result",
"contactId": "contactId 1",
"error": "error 1",
"inviteCode": "inviteCode 1"
}
],
"nextCursor": "nextCursor 1"
}"#);
let api = support::MockApi::start(vec![support::Reply::json(200, response.clone())]).await;
let params: types::GroupsApproveJoinRequestsParams = support::from_json(r#"{"contactIds":["contactIds 1"]}"#);
let result = api.client().groups().approve_join_requests("k57a8m2x9d3f0q1wjh6ypc4n2d7s0vbr", "120363041234567890@g.us", params).await.unwrap();
support::assert_json(&result, &response);
let calls = api.calls().await;
assert_eq!(calls.len(), 1);
assert_eq!(calls[0].method, "POST");
assert_eq!(calls[0].path, "/v1/accounts/k57a8m2x9d3f0q1wjh6ypc4n2d7s0vbr/groups/120363041234567890%40g.us/join-requests/approve");
assert_eq!(calls[0].query, support::pairs(&[]));
support::assert_json(&calls[0].body, &support::json(r#"{"contactIds":["contactIds 1"]}"#));
assert!(calls[0].header(sdk::IDEMPOTENCY_HEADER).is_some_and(|key| !key.is_empty()));
}
#[tokio::test]
async fn approve_join_requests_retries_with_one_key() {
let response = support::json(r#"{
"object": "list",
"items": [
{
"object": "participant_result",
"contactId": "contactId 1",
"error": "error 1",
"inviteCode": "inviteCode 1"
}
],
"nextCursor": "nextCursor 1"
}"#);
let api = support::MockApi::start(vec![support::Reply::status(503), support::Reply::json(200, response.clone())]).await;
let params: types::GroupsApproveJoinRequestsParams = support::from_json(r#"{"contactIds":["contactIds 1"]}"#);
let result = api.client().groups().approve_join_requests("k57a8m2x9d3f0q1wjh6ypc4n2d7s0vbr", "120363041234567890@g.us", params).await.unwrap();
support::assert_json(&result, &response);
let calls = api.calls().await;
assert_eq!(calls.len(), 2);
let key = calls[0].header(sdk::IDEMPOTENCY_HEADER).unwrap();
assert!(!key.is_empty());
assert_eq!(calls[1].header(sdk::IDEMPOTENCY_HEADER), Some(key));
assert_eq!(calls[0].body, calls[1].body);
}
#[tokio::test]
async fn reject_join_requests() {
let response = support::json(r#"{
"object": "list",
"items": [
{
"object": "participant_result",
"contactId": "contactId 1",
"error": "error 1",
"inviteCode": "inviteCode 1"
}
],
"nextCursor": "nextCursor 1"
}"#);
let api = support::MockApi::start(vec![support::Reply::json(200, response.clone())]).await;
let params: types::GroupsRejectJoinRequestsParams = support::from_json(r#"{"contactIds":["contactIds 1"]}"#);
let result = api.client().groups().reject_join_requests("k57a8m2x9d3f0q1wjh6ypc4n2d7s0vbr", "120363041234567890@g.us", params).await.unwrap();
support::assert_json(&result, &response);
let calls = api.calls().await;
assert_eq!(calls.len(), 1);
assert_eq!(calls[0].method, "POST");
assert_eq!(calls[0].path, "/v1/accounts/k57a8m2x9d3f0q1wjh6ypc4n2d7s0vbr/groups/120363041234567890%40g.us/join-requests/reject");
assert_eq!(calls[0].query, support::pairs(&[]));
support::assert_json(&calls[0].body, &support::json(r#"{"contactIds":["contactIds 1"]}"#));
assert!(calls[0].header(sdk::IDEMPOTENCY_HEADER).is_some_and(|key| !key.is_empty()));
}
#[tokio::test]
async fn reject_join_requests_retries_with_one_key() {
let response = support::json(r#"{
"object": "list",
"items": [
{
"object": "participant_result",
"contactId": "contactId 1",
"error": "error 1",
"inviteCode": "inviteCode 1"
}
],
"nextCursor": "nextCursor 1"
}"#);
let api = support::MockApi::start(vec![support::Reply::status(503), support::Reply::json(200, response.clone())]).await;
let params: types::GroupsRejectJoinRequestsParams = support::from_json(r#"{"contactIds":["contactIds 1"]}"#);
let result = api.client().groups().reject_join_requests("k57a8m2x9d3f0q1wjh6ypc4n2d7s0vbr", "120363041234567890@g.us", params).await.unwrap();
support::assert_json(&result, &response);
let calls = api.calls().await;
assert_eq!(calls.len(), 2);
let key = calls[0].header(sdk::IDEMPOTENCY_HEADER).unwrap();
assert!(!key.is_empty());
assert_eq!(calls[1].header(sdk::IDEMPOTENCY_HEADER), Some(key));
assert_eq!(calls[0].body, calls[1].body);
}
#[tokio::test]
async fn list_subgroups_streams_every_page() {
let first = support::json(r#"{
"object": "list",
"items": [
{
"object": "subgroup",
"id": "id 1",
"name": "name 1",
"default": true
}
],
"nextCursor": "cursor_2"
}"#);
let last = support::json(r#"{
"object": "list",
"items": [
{
"object": "subgroup",
"id": "id 1",
"name": "name 1",
"default": true
}
],
"nextCursor": null
}"#);
let api = support::MockApi::start(vec![
support::Reply::json(200, first),
support::Reply::json(200, last),
])
.await;
let params: types::GroupsListSubgroupsParams = support::from_json(r#"{"limit":50,"cursor":"cursor 1"}"#);
let items = api.client().groups().list_subgroups("k57a8m2x9d3f0q1wjh6ypc4n2d7s0vbr", "120363041234567890@g.us", params).to_vec().await.unwrap();
support::assert_json(&items, &support::json(r#"[
{
"object": "subgroup",
"id": "id 1",
"name": "name 1",
"default": true
},
{
"object": "subgroup",
"id": "id 1",
"name": "name 1",
"default": true
}
]"#));
let calls = api.calls().await;
assert_eq!(calls.len(), 2);
assert_eq!(calls[0].method, "GET");
assert_eq!(calls[0].path, "/v1/accounts/k57a8m2x9d3f0q1wjh6ypc4n2d7s0vbr/groups/120363041234567890%40g.us/subgroups");
assert_eq!(calls[0].query, support::pairs(&[("limit", "50"), ("cursor", "cursor 1")]));
assert_eq!(calls[1].query, support::pairs(&[("limit", "50"), ("cursor", "cursor_2")]));
}
#[tokio::test]
async fn list_subgroups_fetches_one_page() {
let page = support::json(r#"{
"object": "list",
"items": [
{
"object": "subgroup",
"id": "id 1",
"name": "name 1",
"default": true
}
],
"nextCursor": null
}"#);
let api = support::MockApi::start(vec![support::Reply::json(200, page.clone())]).await;
let result = api.client().groups().list_subgroups("k57a8m2x9d3f0q1wjh6ypc4n2d7s0vbr", "120363041234567890@g.us", Default::default()).page().await.unwrap();
support::assert_json(&result, &page);
let calls = api.calls().await;
assert_eq!(calls.len(), 1);
assert_eq!(calls[0].method, "GET");
assert_eq!(calls[0].path, "/v1/accounts/k57a8m2x9d3f0q1wjh6ypc4n2d7s0vbr/groups/120363041234567890%40g.us/subgroups");
assert_eq!(calls[0].query, support::pairs(&[]));
}
#[tokio::test]
async fn link_subgroup() {
let api = support::MockApi::start(vec![support::Reply::status(204)]).await;
let params: types::GroupsLinkSubgroupParams = support::from_json(r#"{"groupId":"groupId 1"}"#);
api.client().groups().link_subgroup("k57a8m2x9d3f0q1wjh6ypc4n2d7s0vbr", "120363041234567890@g.us", params).await.unwrap();
let calls = api.calls().await;
assert_eq!(calls.len(), 1);
assert_eq!(calls[0].method, "POST");
assert_eq!(calls[0].path, "/v1/accounts/k57a8m2x9d3f0q1wjh6ypc4n2d7s0vbr/groups/120363041234567890%40g.us/subgroups");
assert_eq!(calls[0].query, support::pairs(&[]));
support::assert_json(&calls[0].body, &support::json(r#"{"groupId":"groupId 1"}"#));
assert!(calls[0].header(sdk::IDEMPOTENCY_HEADER).is_some_and(|key| !key.is_empty()));
}
#[tokio::test]
async fn link_subgroup_retries_with_one_key() {
let api = support::MockApi::start(vec![support::Reply::status(503), support::Reply::status(204)]).await;
let params: types::GroupsLinkSubgroupParams = support::from_json(r#"{"groupId":"groupId 1"}"#);
api.client().groups().link_subgroup("k57a8m2x9d3f0q1wjh6ypc4n2d7s0vbr", "120363041234567890@g.us", params).await.unwrap();
let calls = api.calls().await;
assert_eq!(calls.len(), 2);
let key = calls[0].header(sdk::IDEMPOTENCY_HEADER).unwrap();
assert!(!key.is_empty());
assert_eq!(calls[1].header(sdk::IDEMPOTENCY_HEADER), Some(key));
assert_eq!(calls[0].body, calls[1].body);
}
#[tokio::test]
async fn unlink_subgroup() {
let api = support::MockApi::start(vec![support::Reply::status(204)]).await;
api.client().groups().unlink_subgroup("k57a8m2x9d3f0q1wjh6ypc4n2d7s0vbr", "120363041234567890@g.us", "120363055512345678@g.us").await.unwrap();
let calls = api.calls().await;
assert_eq!(calls.len(), 1);
assert_eq!(calls[0].method, "DELETE");
assert_eq!(calls[0].path, "/v1/accounts/k57a8m2x9d3f0q1wjh6ypc4n2d7s0vbr/groups/120363041234567890%40g.us/subgroups/120363055512345678%40g.us");
assert_eq!(calls[0].query, support::pairs(&[]));
assert!(calls[0].body.is_none());
assert!(calls[0].header(sdk::IDEMPOTENCY_HEADER).is_none());
}
#[tokio::test]
async fn list_community_participants_streams_every_page() {
let first = support::json(r#"{
"object": "list",
"items": [
{
"object": "community_participant",
"contactId": "contactId 1"
}
],
"nextCursor": "cursor_2"
}"#);
let last = support::json(r#"{
"object": "list",
"items": [
{
"object": "community_participant",
"contactId": "contactId 1"
}
],
"nextCursor": null
}"#);
let api = support::MockApi::start(vec![
support::Reply::json(200, first),
support::Reply::json(200, last),
])
.await;
let params: types::GroupsListCommunityParticipantsParams = support::from_json(r#"{"limit":50,"cursor":"cursor 1"}"#);
let items = api.client().groups().list_community_participants("k57a8m2x9d3f0q1wjh6ypc4n2d7s0vbr", "120363041234567890@g.us", params).to_vec().await.unwrap();
support::assert_json(&items, &support::json(r#"[
{
"object": "community_participant",
"contactId": "contactId 1"
},
{
"object": "community_participant",
"contactId": "contactId 1"
}
]"#));
let calls = api.calls().await;
assert_eq!(calls.len(), 2);
assert_eq!(calls[0].method, "GET");
assert_eq!(calls[0].path, "/v1/accounts/k57a8m2x9d3f0q1wjh6ypc4n2d7s0vbr/groups/120363041234567890%40g.us/community-participants");
assert_eq!(calls[0].query, support::pairs(&[("limit", "50"), ("cursor", "cursor 1")]));
assert_eq!(calls[1].query, support::pairs(&[("limit", "50"), ("cursor", "cursor_2")]));
}
#[tokio::test]
async fn list_community_participants_fetches_one_page() {
let page = support::json(r#"{
"object": "list",
"items": [
{
"object": "community_participant",
"contactId": "contactId 1"
}
],
"nextCursor": null
}"#);
let api = support::MockApi::start(vec![support::Reply::json(200, page.clone())]).await;
let result = api.client().groups().list_community_participants("k57a8m2x9d3f0q1wjh6ypc4n2d7s0vbr", "120363041234567890@g.us", Default::default()).page().await.unwrap();
support::assert_json(&result, &page);
let calls = api.calls().await;
assert_eq!(calls.len(), 1);
assert_eq!(calls[0].method, "GET");
assert_eq!(calls[0].path, "/v1/accounts/k57a8m2x9d3f0q1wjh6ypc4n2d7s0vbr/groups/120363041234567890%40g.us/community-participants");
assert_eq!(calls[0].query, support::pairs(&[]));
}
}
mod channels {
use super::*;
#[tokio::test]
async fn list_streams_every_page() {
let first = support::json(r#"{
"object": "list",
"items": [
{
"object": "channel",
"id": "id 1",
"accountId": "accountId 1",
"name": "name 1",
"description": "description 1",
"inviteCode": "inviteCode 1",
"subscriberCount": 1,
"verified": true,
"status": "status 1",
"role": "role 1",
"muted": true,
"pictureUrl": "pictureUrl 1",
"previewUrl": "previewUrl 1",
"createdAt": "2026-09-24T09:00:00.000Z"
}
],
"nextCursor": "cursor_2"
}"#);
let last = support::json(r#"{
"object": "list",
"items": [
{
"object": "channel",
"id": "id 1",
"accountId": "accountId 1",
"name": "name 1",
"description": "description 1",
"inviteCode": "inviteCode 1",
"subscriberCount": 1,
"verified": true,
"status": "status 1",
"role": "role 1",
"muted": true,
"pictureUrl": "pictureUrl 1",
"previewUrl": "previewUrl 1",
"createdAt": "2026-09-24T09:00:00.000Z"
}
],
"nextCursor": null
}"#);
let api = support::MockApi::start(vec![
support::Reply::json(200, first),
support::Reply::json(200, last),
])
.await;
let params: types::ChannelsListParams = support::from_json(r#"{"limit":50,"cursor":"cursor 1"}"#);
let items = api.client().channels().list("k57a8m2x9d3f0q1wjh6ypc4n2d7s0vbr", params).to_vec().await.unwrap();
support::assert_json(&items, &support::json(r#"[
{
"object": "channel",
"id": "id 1",
"accountId": "accountId 1",
"name": "name 1",
"description": "description 1",
"inviteCode": "inviteCode 1",
"subscriberCount": 1,
"verified": true,
"status": "status 1",
"role": "role 1",
"muted": true,
"pictureUrl": "pictureUrl 1",
"previewUrl": "previewUrl 1",
"createdAt": "2026-09-24T09:00:00.000Z"
},
{
"object": "channel",
"id": "id 1",
"accountId": "accountId 1",
"name": "name 1",
"description": "description 1",
"inviteCode": "inviteCode 1",
"subscriberCount": 1,
"verified": true,
"status": "status 1",
"role": "role 1",
"muted": true,
"pictureUrl": "pictureUrl 1",
"previewUrl": "previewUrl 1",
"createdAt": "2026-09-24T09:00:00.000Z"
}
]"#));
let calls = api.calls().await;
assert_eq!(calls.len(), 2);
assert_eq!(calls[0].method, "GET");
assert_eq!(calls[0].path, "/v1/accounts/k57a8m2x9d3f0q1wjh6ypc4n2d7s0vbr/channels");
assert_eq!(calls[0].query, support::pairs(&[("limit", "50"), ("cursor", "cursor 1")]));
assert_eq!(calls[1].query, support::pairs(&[("limit", "50"), ("cursor", "cursor_2")]));
}
#[tokio::test]
async fn list_fetches_one_page() {
let page = support::json(r#"{
"object": "list",
"items": [
{
"object": "channel",
"id": "id 1",
"accountId": "accountId 1",
"name": "name 1",
"description": "description 1",
"inviteCode": "inviteCode 1",
"subscriberCount": 1,
"verified": true,
"status": "status 1",
"role": "role 1",
"muted": true,
"pictureUrl": "pictureUrl 1",
"previewUrl": "previewUrl 1",
"createdAt": "2026-09-24T09:00:00.000Z"
}
],
"nextCursor": null
}"#);
let api = support::MockApi::start(vec![support::Reply::json(200, page.clone())]).await;
let result = api.client().channels().list("k57a8m2x9d3f0q1wjh6ypc4n2d7s0vbr", Default::default()).page().await.unwrap();
support::assert_json(&result, &page);
let calls = api.calls().await;
assert_eq!(calls.len(), 1);
assert_eq!(calls[0].method, "GET");
assert_eq!(calls[0].path, "/v1/accounts/k57a8m2x9d3f0q1wjh6ypc4n2d7s0vbr/channels");
assert_eq!(calls[0].query, support::pairs(&[]));
}
#[tokio::test]
async fn create() {
let response = support::json(r#"{
"object": "channel",
"id": "id 1",
"accountId": "accountId 1",
"name": "name 1",
"description": "description 1",
"inviteCode": "inviteCode 1",
"subscriberCount": 1,
"verified": true,
"status": "status 1",
"role": "role 1",
"muted": true,
"pictureUrl": "pictureUrl 1",
"previewUrl": "previewUrl 1",
"createdAt": "2026-09-24T09:00:00.000Z"
}"#);
let api = support::MockApi::start(vec![support::Reply::json(201, response.clone())]).await;
let params: types::ChannelsCreateParams = support::from_json(r#"{"name":"name 1","description":"description 1","pictureBase64":"pictureBase64 1"}"#);
let result = api.client().channels().create("k57a8m2x9d3f0q1wjh6ypc4n2d7s0vbr", params).await.unwrap();
support::assert_json(&result, &response);
let calls = api.calls().await;
assert_eq!(calls.len(), 1);
assert_eq!(calls[0].method, "POST");
assert_eq!(calls[0].path, "/v1/accounts/k57a8m2x9d3f0q1wjh6ypc4n2d7s0vbr/channels");
assert_eq!(calls[0].query, support::pairs(&[]));
support::assert_json(&calls[0].body, &support::json(r#"{"name":"name 1","description":"description 1","pictureBase64":"pictureBase64 1"}"#));
assert!(calls[0].header(sdk::IDEMPOTENCY_HEADER).is_some_and(|key| !key.is_empty()));
}
#[tokio::test]
async fn create_retries_with_one_key() {
let response = support::json(r#"{
"object": "channel",
"id": "id 1",
"accountId": "accountId 1",
"name": "name 1",
"description": "description 1",
"inviteCode": "inviteCode 1",
"subscriberCount": 1,
"verified": true,
"status": "status 1",
"role": "role 1",
"muted": true,
"pictureUrl": "pictureUrl 1",
"previewUrl": "previewUrl 1",
"createdAt": "2026-09-24T09:00:00.000Z"
}"#);
let api = support::MockApi::start(vec![support::Reply::status(503), support::Reply::json(201, response.clone())]).await;
let params: types::ChannelsCreateParams = support::from_json(r#"{"name":"name 1","description":"description 1","pictureBase64":"pictureBase64 1"}"#);
let result = api.client().channels().create("k57a8m2x9d3f0q1wjh6ypc4n2d7s0vbr", params).await.unwrap();
support::assert_json(&result, &response);
let calls = api.calls().await;
assert_eq!(calls.len(), 2);
let key = calls[0].header(sdk::IDEMPOTENCY_HEADER).unwrap();
assert!(!key.is_empty());
assert_eq!(calls[1].header(sdk::IDEMPOTENCY_HEADER), Some(key));
assert_eq!(calls[0].body, calls[1].body);
}
#[tokio::test]
async fn get_invite() {
let response = support::json(r#"{
"object": "channel",
"id": "id 1",
"accountId": "accountId 1",
"name": "name 1",
"description": "description 1",
"inviteCode": "inviteCode 1",
"subscriberCount": 1,
"verified": true,
"status": "status 1",
"role": "role 1",
"muted": true,
"pictureUrl": "pictureUrl 1",
"previewUrl": "previewUrl 1",
"createdAt": "2026-09-24T09:00:00.000Z"
}"#);
let api = support::MockApi::start(vec![support::Reply::json(200, response.clone())]).await;
let result = api.client().channels().get_invite("k57a8m2x9d3f0q1wjh6ypc4n2d7s0vbr", "AbCdEf123456").await.unwrap();
support::assert_json(&result, &response);
let calls = api.calls().await;
assert_eq!(calls.len(), 1);
assert_eq!(calls[0].method, "GET");
assert_eq!(calls[0].path, "/v1/accounts/k57a8m2x9d3f0q1wjh6ypc4n2d7s0vbr/channels/invites/AbCdEf123456");
assert_eq!(calls[0].query, support::pairs(&[]));
assert!(calls[0].body.is_none());
assert!(calls[0].header(sdk::IDEMPOTENCY_HEADER).is_none());
}
#[tokio::test]
async fn get() {
let response = support::json(r#"{
"object": "channel",
"id": "id 1",
"accountId": "accountId 1",
"name": "name 1",
"description": "description 1",
"inviteCode": "inviteCode 1",
"subscriberCount": 1,
"verified": true,
"status": "status 1",
"role": "role 1",
"muted": true,
"pictureUrl": "pictureUrl 1",
"previewUrl": "previewUrl 1",
"createdAt": "2026-09-24T09:00:00.000Z"
}"#);
let api = support::MockApi::start(vec![support::Reply::json(200, response.clone())]).await;
let result = api.client().channels().get("k57a8m2x9d3f0q1wjh6ypc4n2d7s0vbr", "120363198765432101@newsletter").await.unwrap();
support::assert_json(&result, &response);
let calls = api.calls().await;
assert_eq!(calls.len(), 1);
assert_eq!(calls[0].method, "GET");
assert_eq!(calls[0].path, "/v1/accounts/k57a8m2x9d3f0q1wjh6ypc4n2d7s0vbr/channels/120363198765432101%40newsletter");
assert_eq!(calls[0].query, support::pairs(&[]));
assert!(calls[0].body.is_none());
assert!(calls[0].header(sdk::IDEMPOTENCY_HEADER).is_none());
}
#[tokio::test]
async fn follow() {
let api = support::MockApi::start(vec![support::Reply::status(204)]).await;
api.client().channels().follow("k57a8m2x9d3f0q1wjh6ypc4n2d7s0vbr", "120363198765432101@newsletter").await.unwrap();
let calls = api.calls().await;
assert_eq!(calls.len(), 1);
assert_eq!(calls[0].method, "POST");
assert_eq!(calls[0].path, "/v1/accounts/k57a8m2x9d3f0q1wjh6ypc4n2d7s0vbr/channels/120363198765432101%40newsletter/follow");
assert_eq!(calls[0].query, support::pairs(&[]));
assert!(calls[0].body.is_none());
assert!(calls[0].header(sdk::IDEMPOTENCY_HEADER).is_some_and(|key| !key.is_empty()));
}
#[tokio::test]
async fn follow_retries_with_one_key() {
let api = support::MockApi::start(vec![support::Reply::status(503), support::Reply::status(204)]).await;
api.client().channels().follow("k57a8m2x9d3f0q1wjh6ypc4n2d7s0vbr", "120363198765432101@newsletter").await.unwrap();
let calls = api.calls().await;
assert_eq!(calls.len(), 2);
let key = calls[0].header(sdk::IDEMPOTENCY_HEADER).unwrap();
assert!(!key.is_empty());
assert_eq!(calls[1].header(sdk::IDEMPOTENCY_HEADER), Some(key));
assert_eq!(calls[0].body, calls[1].body);
}
#[tokio::test]
async fn unfollow() {
let api = support::MockApi::start(vec![support::Reply::status(204)]).await;
api.client().channels().unfollow("k57a8m2x9d3f0q1wjh6ypc4n2d7s0vbr", "120363198765432101@newsletter").await.unwrap();
let calls = api.calls().await;
assert_eq!(calls.len(), 1);
assert_eq!(calls[0].method, "POST");
assert_eq!(calls[0].path, "/v1/accounts/k57a8m2x9d3f0q1wjh6ypc4n2d7s0vbr/channels/120363198765432101%40newsletter/unfollow");
assert_eq!(calls[0].query, support::pairs(&[]));
assert!(calls[0].body.is_none());
assert!(calls[0].header(sdk::IDEMPOTENCY_HEADER).is_some_and(|key| !key.is_empty()));
}
#[tokio::test]
async fn unfollow_retries_with_one_key() {
let api = support::MockApi::start(vec![support::Reply::status(503), support::Reply::status(204)]).await;
api.client().channels().unfollow("k57a8m2x9d3f0q1wjh6ypc4n2d7s0vbr", "120363198765432101@newsletter").await.unwrap();
let calls = api.calls().await;
assert_eq!(calls.len(), 2);
let key = calls[0].header(sdk::IDEMPOTENCY_HEADER).unwrap();
assert!(!key.is_empty());
assert_eq!(calls[1].header(sdk::IDEMPOTENCY_HEADER), Some(key));
assert_eq!(calls[0].body, calls[1].body);
}
#[tokio::test]
async fn mute() {
let api = support::MockApi::start(vec![support::Reply::status(204)]).await;
api.client().channels().mute("k57a8m2x9d3f0q1wjh6ypc4n2d7s0vbr", "120363198765432101@newsletter").await.unwrap();
let calls = api.calls().await;
assert_eq!(calls.len(), 1);
assert_eq!(calls[0].method, "POST");
assert_eq!(calls[0].path, "/v1/accounts/k57a8m2x9d3f0q1wjh6ypc4n2d7s0vbr/channels/120363198765432101%40newsletter/mute");
assert_eq!(calls[0].query, support::pairs(&[]));
assert!(calls[0].body.is_none());
assert!(calls[0].header(sdk::IDEMPOTENCY_HEADER).is_some_and(|key| !key.is_empty()));
}
#[tokio::test]
async fn mute_retries_with_one_key() {
let api = support::MockApi::start(vec![support::Reply::status(503), support::Reply::status(204)]).await;
api.client().channels().mute("k57a8m2x9d3f0q1wjh6ypc4n2d7s0vbr", "120363198765432101@newsletter").await.unwrap();
let calls = api.calls().await;
assert_eq!(calls.len(), 2);
let key = calls[0].header(sdk::IDEMPOTENCY_HEADER).unwrap();
assert!(!key.is_empty());
assert_eq!(calls[1].header(sdk::IDEMPOTENCY_HEADER), Some(key));
assert_eq!(calls[0].body, calls[1].body);
}
#[tokio::test]
async fn unmute() {
let api = support::MockApi::start(vec![support::Reply::status(204)]).await;
api.client().channels().unmute("k57a8m2x9d3f0q1wjh6ypc4n2d7s0vbr", "120363198765432101@newsletter").await.unwrap();
let calls = api.calls().await;
assert_eq!(calls.len(), 1);
assert_eq!(calls[0].method, "POST");
assert_eq!(calls[0].path, "/v1/accounts/k57a8m2x9d3f0q1wjh6ypc4n2d7s0vbr/channels/120363198765432101%40newsletter/unmute");
assert_eq!(calls[0].query, support::pairs(&[]));
assert!(calls[0].body.is_none());
assert!(calls[0].header(sdk::IDEMPOTENCY_HEADER).is_some_and(|key| !key.is_empty()));
}
#[tokio::test]
async fn unmute_retries_with_one_key() {
let api = support::MockApi::start(vec![support::Reply::status(503), support::Reply::status(204)]).await;
api.client().channels().unmute("k57a8m2x9d3f0q1wjh6ypc4n2d7s0vbr", "120363198765432101@newsletter").await.unwrap();
let calls = api.calls().await;
assert_eq!(calls.len(), 2);
let key = calls[0].header(sdk::IDEMPOTENCY_HEADER).unwrap();
assert!(!key.is_empty());
assert_eq!(calls[1].header(sdk::IDEMPOTENCY_HEADER), Some(key));
assert_eq!(calls[0].body, calls[1].body);
}
#[tokio::test]
async fn list_messages_streams_every_page() {
let first = support::json(r#"{
"object": "list",
"items": [
{
"object": "channel_message",
"id": "id 1",
"accountId": "accountId 1",
"channelId": "channelId 1",
"type": "type 1",
"text": "text 1",
"viewCount": 1,
"reactions": {
"key": 1
},
"sentAt": "2026-09-24T09:00:00.000Z"
}
],
"nextCursor": "cursor_2"
}"#);
let last = support::json(r#"{
"object": "list",
"items": [
{
"object": "channel_message",
"id": "id 1",
"accountId": "accountId 1",
"channelId": "channelId 1",
"type": "type 1",
"text": "text 1",
"viewCount": 1,
"reactions": {
"key": 1
},
"sentAt": "2026-09-24T09:00:00.000Z"
}
],
"nextCursor": null
}"#);
let api = support::MockApi::start(vec![
support::Reply::json(200, first),
support::Reply::json(200, last),
])
.await;
let params: types::ChannelsListMessagesParams = support::from_json(r#"{"limit":50,"cursor":"cursor 1"}"#);
let items = api.client().channels().list_messages("k57a8m2x9d3f0q1wjh6ypc4n2d7s0vbr", "120363198765432101@newsletter", params).to_vec().await.unwrap();
support::assert_json(&items, &support::json(r#"[
{
"object": "channel_message",
"id": "id 1",
"accountId": "accountId 1",
"channelId": "channelId 1",
"type": "type 1",
"text": "text 1",
"viewCount": 1,
"reactions": {
"key": 1
},
"sentAt": "2026-09-24T09:00:00.000Z"
},
{
"object": "channel_message",
"id": "id 1",
"accountId": "accountId 1",
"channelId": "channelId 1",
"type": "type 1",
"text": "text 1",
"viewCount": 1,
"reactions": {
"key": 1
},
"sentAt": "2026-09-24T09:00:00.000Z"
}
]"#));
let calls = api.calls().await;
assert_eq!(calls.len(), 2);
assert_eq!(calls[0].method, "GET");
assert_eq!(calls[0].path, "/v1/accounts/k57a8m2x9d3f0q1wjh6ypc4n2d7s0vbr/channels/120363198765432101%40newsletter/messages");
assert_eq!(calls[0].query, support::pairs(&[("limit", "50"), ("cursor", "cursor 1")]));
assert_eq!(calls[1].query, support::pairs(&[("limit", "50"), ("cursor", "cursor_2")]));
}
#[tokio::test]
async fn list_messages_fetches_one_page() {
let page = support::json(r#"{
"object": "list",
"items": [
{
"object": "channel_message",
"id": "id 1",
"accountId": "accountId 1",
"channelId": "channelId 1",
"type": "type 1",
"text": "text 1",
"viewCount": 1,
"reactions": {
"key": 1
},
"sentAt": "2026-09-24T09:00:00.000Z"
}
],
"nextCursor": null
}"#);
let api = support::MockApi::start(vec![support::Reply::json(200, page.clone())]).await;
let result = api.client().channels().list_messages("k57a8m2x9d3f0q1wjh6ypc4n2d7s0vbr", "120363198765432101@newsletter", Default::default()).page().await.unwrap();
support::assert_json(&result, &page);
let calls = api.calls().await;
assert_eq!(calls.len(), 1);
assert_eq!(calls[0].method, "GET");
assert_eq!(calls[0].path, "/v1/accounts/k57a8m2x9d3f0q1wjh6ypc4n2d7s0vbr/channels/120363198765432101%40newsletter/messages");
assert_eq!(calls[0].query, support::pairs(&[]));
}
#[tokio::test]
async fn react() {
let api = support::MockApi::start(vec![support::Reply::status(204)]).await;
let params: types::ChannelsReactParams = support::from_json(r#"{"emoji":"emoji 1"}"#);
api.client().channels().react("k57a8m2x9d3f0q1wjh6ypc4n2d7s0vbr", "120363198765432101@newsletter", "142", params).await.unwrap();
let calls = api.calls().await;
assert_eq!(calls.len(), 1);
assert_eq!(calls[0].method, "POST");
assert_eq!(calls[0].path, "/v1/accounts/k57a8m2x9d3f0q1wjh6ypc4n2d7s0vbr/channels/120363198765432101%40newsletter/messages/142/react");
assert_eq!(calls[0].query, support::pairs(&[]));
support::assert_json(&calls[0].body, &support::json(r#"{"emoji":"emoji 1"}"#));
assert!(calls[0].header(sdk::IDEMPOTENCY_HEADER).is_some_and(|key| !key.is_empty()));
}
#[tokio::test]
async fn react_retries_with_one_key() {
let api = support::MockApi::start(vec![support::Reply::status(503), support::Reply::status(204)]).await;
let params: types::ChannelsReactParams = support::from_json(r#"{"emoji":"emoji 1"}"#);
api.client().channels().react("k57a8m2x9d3f0q1wjh6ypc4n2d7s0vbr", "120363198765432101@newsletter", "142", params).await.unwrap();
let calls = api.calls().await;
assert_eq!(calls.len(), 2);
let key = calls[0].header(sdk::IDEMPOTENCY_HEADER).unwrap();
assert!(!key.is_empty());
assert_eq!(calls[1].header(sdk::IDEMPOTENCY_HEADER), Some(key));
assert_eq!(calls[0].body, calls[1].body);
}
#[tokio::test]
async fn mark_viewed() {
let api = support::MockApi::start(vec![support::Reply::status(204)]).await;
let params: types::ChannelsMarkViewedParams = support::from_json(r#"{"channelMessageIds":["channelMessageIds 1"]}"#);
api.client().channels().mark_viewed("k57a8m2x9d3f0q1wjh6ypc4n2d7s0vbr", "120363198765432101@newsletter", params).await.unwrap();
let calls = api.calls().await;
assert_eq!(calls.len(), 1);
assert_eq!(calls[0].method, "POST");
assert_eq!(calls[0].path, "/v1/accounts/k57a8m2x9d3f0q1wjh6ypc4n2d7s0vbr/channels/120363198765432101%40newsletter/mark-viewed");
assert_eq!(calls[0].query, support::pairs(&[]));
support::assert_json(&calls[0].body, &support::json(r#"{"channelMessageIds":["channelMessageIds 1"]}"#));
assert!(calls[0].header(sdk::IDEMPOTENCY_HEADER).is_some_and(|key| !key.is_empty()));
}
#[tokio::test]
async fn mark_viewed_retries_with_one_key() {
let api = support::MockApi::start(vec![support::Reply::status(503), support::Reply::status(204)]).await;
let params: types::ChannelsMarkViewedParams = support::from_json(r#"{"channelMessageIds":["channelMessageIds 1"]}"#);
api.client().channels().mark_viewed("k57a8m2x9d3f0q1wjh6ypc4n2d7s0vbr", "120363198765432101@newsletter", params).await.unwrap();
let calls = api.calls().await;
assert_eq!(calls.len(), 2);
let key = calls[0].header(sdk::IDEMPOTENCY_HEADER).unwrap();
assert!(!key.is_empty());
assert_eq!(calls[1].header(sdk::IDEMPOTENCY_HEADER), Some(key));
assert_eq!(calls[0].body, calls[1].body);
}
}
mod webhook_endpoints {
use super::*;
#[tokio::test]
async fn list_streams_every_page() {
let first = support::json(r#"{
"object": "list",
"items": [
{
"object": "webhook_endpoint",
"id": "id 1",
"projectId": "projectId 1",
"url": "https://example.com/url",
"events": [
"account.qr_code_issued"
],
"active": true,
"createdAt": "2026-09-24T09:00:00.000Z",
"updatedAt": "2026-09-24T09:00:00.000Z"
}
],
"nextCursor": "cursor_2"
}"#);
let last = support::json(r#"{
"object": "list",
"items": [
{
"object": "webhook_endpoint",
"id": "id 1",
"projectId": "projectId 1",
"url": "https://example.com/url",
"events": [
"account.qr_code_issued"
],
"active": true,
"createdAt": "2026-09-24T09:00:00.000Z",
"updatedAt": "2026-09-24T09:00:00.000Z"
}
],
"nextCursor": null
}"#);
let api = support::MockApi::start(vec![
support::Reply::json(200, first),
support::Reply::json(200, last),
])
.await;
let params: types::WebhookEndpointsListParams = support::from_json(r#"{"limit":50,"cursor":"cursor 1","projectId":"ext:customer_8812"}"#);
let items = api.client().webhook_endpoints().list(params).to_vec().await.unwrap();
support::assert_json(&items, &support::json(r#"[
{
"object": "webhook_endpoint",
"id": "id 1",
"projectId": "projectId 1",
"url": "https://example.com/url",
"events": [
"account.qr_code_issued"
],
"active": true,
"createdAt": "2026-09-24T09:00:00.000Z",
"updatedAt": "2026-09-24T09:00:00.000Z"
},
{
"object": "webhook_endpoint",
"id": "id 1",
"projectId": "projectId 1",
"url": "https://example.com/url",
"events": [
"account.qr_code_issued"
],
"active": true,
"createdAt": "2026-09-24T09:00:00.000Z",
"updatedAt": "2026-09-24T09:00:00.000Z"
}
]"#));
let calls = api.calls().await;
assert_eq!(calls.len(), 2);
assert_eq!(calls[0].method, "GET");
assert_eq!(calls[0].path, "/v1/webhook-endpoints");
assert_eq!(calls[0].query, support::pairs(&[("limit", "50"), ("projectId", "ext:customer_8812"), ("cursor", "cursor 1")]));
assert_eq!(calls[1].query, support::pairs(&[("limit", "50"), ("projectId", "ext:customer_8812"), ("cursor", "cursor_2")]));
}
#[tokio::test]
async fn list_fetches_one_page() {
let page = support::json(r#"{
"object": "list",
"items": [
{
"object": "webhook_endpoint",
"id": "id 1",
"projectId": "projectId 1",
"url": "https://example.com/url",
"events": [
"account.qr_code_issued"
],
"active": true,
"createdAt": "2026-09-24T09:00:00.000Z",
"updatedAt": "2026-09-24T09:00:00.000Z"
}
],
"nextCursor": null
}"#);
let api = support::MockApi::start(vec![support::Reply::json(200, page.clone())]).await;
let result = api.client().webhook_endpoints().list(Default::default()).page().await.unwrap();
support::assert_json(&result, &page);
let calls = api.calls().await;
assert_eq!(calls.len(), 1);
assert_eq!(calls[0].method, "GET");
assert_eq!(calls[0].path, "/v1/webhook-endpoints");
assert_eq!(calls[0].query, support::pairs(&[]));
}
#[tokio::test]
async fn create() {
let response = support::json(r#"{
"object": "webhook_endpoint",
"id": "id 1",
"projectId": "projectId 1",
"url": "https://example.com/url",
"events": [
"account.qr_code_issued"
],
"active": true,
"createdAt": "2026-09-24T09:00:00.000Z",
"updatedAt": "2026-09-24T09:00:00.000Z"
}"#);
let api = support::MockApi::start(vec![support::Reply::json(201, response.clone())]).await;
let params: types::WebhookEndpointsCreateParams = support::from_json(r#"{
"url": "https://example.com/url",
"events": [
"account.qr_code_issued"
],
"projectId": "projectId 1"
}"#);
let result = api.client().webhook_endpoints().create(params).await.unwrap();
support::assert_json(&result, &response);
let calls = api.calls().await;
assert_eq!(calls.len(), 1);
assert_eq!(calls[0].method, "POST");
assert_eq!(calls[0].path, "/v1/webhook-endpoints");
assert_eq!(calls[0].query, support::pairs(&[]));
support::assert_json(&calls[0].body, &support::json(r#"{
"url": "https://example.com/url",
"events": [
"account.qr_code_issued"
],
"projectId": "projectId 1"
}"#));
assert!(calls[0].header(sdk::IDEMPOTENCY_HEADER).is_some_and(|key| !key.is_empty()));
}
#[tokio::test]
async fn create_retries_with_one_key() {
let response = support::json(r#"{
"object": "webhook_endpoint",
"id": "id 1",
"projectId": "projectId 1",
"url": "https://example.com/url",
"events": [
"account.qr_code_issued"
],
"active": true,
"createdAt": "2026-09-24T09:00:00.000Z",
"updatedAt": "2026-09-24T09:00:00.000Z"
}"#);
let api = support::MockApi::start(vec![support::Reply::status(503), support::Reply::json(201, response.clone())]).await;
let params: types::WebhookEndpointsCreateParams = support::from_json(r#"{
"url": "https://example.com/url",
"events": [
"account.qr_code_issued"
],
"projectId": "projectId 1"
}"#);
let result = api.client().webhook_endpoints().create(params).await.unwrap();
support::assert_json(&result, &response);
let calls = api.calls().await;
assert_eq!(calls.len(), 2);
let key = calls[0].header(sdk::IDEMPOTENCY_HEADER).unwrap();
assert!(!key.is_empty());
assert_eq!(calls[1].header(sdk::IDEMPOTENCY_HEADER), Some(key));
assert_eq!(calls[0].body, calls[1].body);
}
#[tokio::test]
async fn get() {
let response = support::json(r#"{
"object": "webhook_endpoint",
"id": "id 1",
"projectId": "projectId 1",
"url": "https://example.com/url",
"events": [
"account.qr_code_issued"
],
"active": true,
"createdAt": "2026-09-24T09:00:00.000Z",
"updatedAt": "2026-09-24T09:00:00.000Z"
}"#);
let api = support::MockApi::start(vec![support::Reply::json(200, response.clone())]).await;
let result = api.client().webhook_endpoints().get("n97p31n8b5c7z2y4u6ebt5gr1ew3qa8s").await.unwrap();
support::assert_json(&result, &response);
let calls = api.calls().await;
assert_eq!(calls.len(), 1);
assert_eq!(calls[0].method, "GET");
assert_eq!(calls[0].path, "/v1/webhook-endpoints/n97p31n8b5c7z2y4u6ebt5gr1ew3qa8s");
assert_eq!(calls[0].query, support::pairs(&[]));
assert!(calls[0].body.is_none());
assert!(calls[0].header(sdk::IDEMPOTENCY_HEADER).is_none());
}
#[tokio::test]
async fn update() {
let response = support::json(r#"{
"object": "webhook_endpoint",
"id": "id 1",
"projectId": "projectId 1",
"url": "https://example.com/url",
"events": [
"account.qr_code_issued"
],
"active": true,
"createdAt": "2026-09-24T09:00:00.000Z",
"updatedAt": "2026-09-24T09:00:00.000Z"
}"#);
let api = support::MockApi::start(vec![support::Reply::json(200, response.clone())]).await;
let params: types::WebhookEndpointsUpdateParams = support::from_json(r#"{"url":"https://example.com/url","events":["account.qr_code_issued"],"active":true}"#);
let result = api.client().webhook_endpoints().update("n97p31n8b5c7z2y4u6ebt5gr1ew3qa8s", params).await.unwrap();
support::assert_json(&result, &response);
let calls = api.calls().await;
assert_eq!(calls.len(), 1);
assert_eq!(calls[0].method, "PATCH");
assert_eq!(calls[0].path, "/v1/webhook-endpoints/n97p31n8b5c7z2y4u6ebt5gr1ew3qa8s");
assert_eq!(calls[0].query, support::pairs(&[]));
support::assert_json(&calls[0].body, &support::json(r#"{"url":"https://example.com/url","events":["account.qr_code_issued"],"active":true}"#));
assert!(calls[0].header(sdk::IDEMPOTENCY_HEADER).is_none());
}
#[tokio::test]
async fn update_without_params() {
let response = support::json(r#"{
"object": "webhook_endpoint",
"id": "id 1",
"projectId": "projectId 1",
"url": "https://example.com/url",
"events": [
"account.qr_code_issued"
],
"active": true,
"createdAt": "2026-09-24T09:00:00.000Z",
"updatedAt": "2026-09-24T09:00:00.000Z"
}"#);
let api = support::MockApi::start(vec![support::Reply::json(200, response.clone())]).await;
let result = api.client().webhook_endpoints().update("n97p31n8b5c7z2y4u6ebt5gr1ew3qa8s", Default::default()).await.unwrap();
support::assert_json(&result, &response);
let calls = api.calls().await;
assert_eq!(calls.len(), 1);
assert_eq!(calls[0].method, "PATCH");
assert_eq!(calls[0].path, "/v1/webhook-endpoints/n97p31n8b5c7z2y4u6ebt5gr1ew3qa8s");
assert_eq!(calls[0].query, support::pairs(&[]));
support::assert_json(&calls[0].body, &support::json(r#"{}"#));
assert!(calls[0].header(sdk::IDEMPOTENCY_HEADER).is_none());
}
#[tokio::test]
async fn update_is_not_repeated() {
let api = support::MockApi::start(vec![
support::Reply::status(503),
support::Reply::status(503),
])
.await;
let params: types::WebhookEndpointsUpdateParams = support::from_json(r#"{"url":"https://example.com/url","events":["account.qr_code_issued"],"active":true}"#);
let error = api.client().webhook_endpoints().update("n97p31n8b5c7z2y4u6ebt5gr1ew3qa8s", params).await.unwrap_err();
assert_eq!(error.status(), Some(503));
assert_eq!(api.calls().await.len(), 1);
}
#[tokio::test]
async fn delete() {
let api = support::MockApi::start(vec![support::Reply::status(204)]).await;
api.client().webhook_endpoints().delete("n97p31n8b5c7z2y4u6ebt5gr1ew3qa8s").await.unwrap();
let calls = api.calls().await;
assert_eq!(calls.len(), 1);
assert_eq!(calls[0].method, "DELETE");
assert_eq!(calls[0].path, "/v1/webhook-endpoints/n97p31n8b5c7z2y4u6ebt5gr1ew3qa8s");
assert_eq!(calls[0].query, support::pairs(&[]));
assert!(calls[0].body.is_none());
assert!(calls[0].header(sdk::IDEMPOTENCY_HEADER).is_none());
}
#[tokio::test]
async fn rotate_secret() {
let response = support::json(r#"{
"object": "webhook_endpoint",
"id": "id 1",
"projectId": "projectId 1",
"url": "https://example.com/url",
"events": [
"account.qr_code_issued"
],
"active": true,
"createdAt": "2026-09-24T09:00:00.000Z",
"updatedAt": "2026-09-24T09:00:00.000Z"
}"#);
let api = support::MockApi::start(vec![support::Reply::json(200, response.clone())]).await;
let result = api.client().webhook_endpoints().rotate_secret("n97p31n8b5c7z2y4u6ebt5gr1ew3qa8s").await.unwrap();
support::assert_json(&result, &response);
let calls = api.calls().await;
assert_eq!(calls.len(), 1);
assert_eq!(calls[0].method, "POST");
assert_eq!(calls[0].path, "/v1/webhook-endpoints/n97p31n8b5c7z2y4u6ebt5gr1ew3qa8s/rotate-secret");
assert_eq!(calls[0].query, support::pairs(&[]));
assert!(calls[0].body.is_none());
assert!(calls[0].header(sdk::IDEMPOTENCY_HEADER).is_some_and(|key| !key.is_empty()));
}
#[tokio::test]
async fn rotate_secret_retries_with_one_key() {
let response = support::json(r#"{
"object": "webhook_endpoint",
"id": "id 1",
"projectId": "projectId 1",
"url": "https://example.com/url",
"events": [
"account.qr_code_issued"
],
"active": true,
"createdAt": "2026-09-24T09:00:00.000Z",
"updatedAt": "2026-09-24T09:00:00.000Z"
}"#);
let api = support::MockApi::start(vec![support::Reply::status(503), support::Reply::json(200, response.clone())]).await;
let result = api.client().webhook_endpoints().rotate_secret("n97p31n8b5c7z2y4u6ebt5gr1ew3qa8s").await.unwrap();
support::assert_json(&result, &response);
let calls = api.calls().await;
assert_eq!(calls.len(), 2);
let key = calls[0].header(sdk::IDEMPOTENCY_HEADER).unwrap();
assert!(!key.is_empty());
assert_eq!(calls[1].header(sdk::IDEMPOTENCY_HEADER), Some(key));
assert_eq!(calls[0].body, calls[1].body);
}
}
mod incoming_webhooks {
use super::*;
#[tokio::test]
async fn list_streams_every_page() {
let first = support::json(r#"{
"object": "list",
"items": [
{
"object": "incoming_webhook",
"id": "id 1",
"accountId": "accountId 1",
"projectId": "projectId 1",
"name": "name 1",
"to": "to 1",
"enabled": true,
"url": "https://example.com/url",
"createdAt": "2026-09-24T09:00:00.000Z",
"updatedAt": "2026-09-24T09:00:00.000Z"
}
],
"nextCursor": "cursor_2"
}"#);
let last = support::json(r#"{
"object": "list",
"items": [
{
"object": "incoming_webhook",
"id": "id 1",
"accountId": "accountId 1",
"projectId": "projectId 1",
"name": "name 1",
"to": "to 1",
"enabled": true,
"url": "https://example.com/url",
"createdAt": "2026-09-24T09:00:00.000Z",
"updatedAt": "2026-09-24T09:00:00.000Z"
}
],
"nextCursor": null
}"#);
let api = support::MockApi::start(vec![
support::Reply::json(200, first),
support::Reply::json(200, last),
])
.await;
let params: types::IncomingWebhooksListParams = support::from_json(r#"{"limit":50,"cursor":"cursor 1","projectId":"ext:customer_8812"}"#);
let items = api.client().incoming_webhooks().list(params).to_vec().await.unwrap();
support::assert_json(&items, &support::json(r#"[
{
"object": "incoming_webhook",
"id": "id 1",
"accountId": "accountId 1",
"projectId": "projectId 1",
"name": "name 1",
"to": "to 1",
"enabled": true,
"url": "https://example.com/url",
"createdAt": "2026-09-24T09:00:00.000Z",
"updatedAt": "2026-09-24T09:00:00.000Z"
},
{
"object": "incoming_webhook",
"id": "id 1",
"accountId": "accountId 1",
"projectId": "projectId 1",
"name": "name 1",
"to": "to 1",
"enabled": true,
"url": "https://example.com/url",
"createdAt": "2026-09-24T09:00:00.000Z",
"updatedAt": "2026-09-24T09:00:00.000Z"
}
]"#));
let calls = api.calls().await;
assert_eq!(calls.len(), 2);
assert_eq!(calls[0].method, "GET");
assert_eq!(calls[0].path, "/v1/incoming-webhooks");
assert_eq!(calls[0].query, support::pairs(&[("limit", "50"), ("projectId", "ext:customer_8812"), ("cursor", "cursor 1")]));
assert_eq!(calls[1].query, support::pairs(&[("limit", "50"), ("projectId", "ext:customer_8812"), ("cursor", "cursor_2")]));
}
#[tokio::test]
async fn list_fetches_one_page() {
let page = support::json(r#"{
"object": "list",
"items": [
{
"object": "incoming_webhook",
"id": "id 1",
"accountId": "accountId 1",
"projectId": "projectId 1",
"name": "name 1",
"to": "to 1",
"enabled": true,
"url": "https://example.com/url",
"createdAt": "2026-09-24T09:00:00.000Z",
"updatedAt": "2026-09-24T09:00:00.000Z"
}
],
"nextCursor": null
}"#);
let api = support::MockApi::start(vec![support::Reply::json(200, page.clone())]).await;
let result = api.client().incoming_webhooks().list(Default::default()).page().await.unwrap();
support::assert_json(&result, &page);
let calls = api.calls().await;
assert_eq!(calls.len(), 1);
assert_eq!(calls[0].method, "GET");
assert_eq!(calls[0].path, "/v1/incoming-webhooks");
assert_eq!(calls[0].query, support::pairs(&[]));
}
#[tokio::test]
async fn create() {
let response = support::json(r#"{
"object": "incoming_webhook",
"id": "id 1",
"accountId": "accountId 1",
"projectId": "projectId 1",
"name": "name 1",
"to": "to 1",
"enabled": true,
"url": "https://example.com/url",
"createdAt": "2026-09-24T09:00:00.000Z",
"updatedAt": "2026-09-24T09:00:00.000Z"
}"#);
let api = support::MockApi::start(vec![support::Reply::json(201, response.clone())]).await;
let params: types::IncomingWebhooksCreateParams = support::from_json(r#"{"accountId":"accountId 1","name":"name 1","to":"to 1"}"#);
let result = api.client().incoming_webhooks().create(params).await.unwrap();
support::assert_json(&result, &response);
let calls = api.calls().await;
assert_eq!(calls.len(), 1);
assert_eq!(calls[0].method, "POST");
assert_eq!(calls[0].path, "/v1/incoming-webhooks");
assert_eq!(calls[0].query, support::pairs(&[]));
support::assert_json(&calls[0].body, &support::json(r#"{"accountId":"accountId 1","name":"name 1","to":"to 1"}"#));
assert!(calls[0].header(sdk::IDEMPOTENCY_HEADER).is_some_and(|key| !key.is_empty()));
}
#[tokio::test]
async fn create_retries_with_one_key() {
let response = support::json(r#"{
"object": "incoming_webhook",
"id": "id 1",
"accountId": "accountId 1",
"projectId": "projectId 1",
"name": "name 1",
"to": "to 1",
"enabled": true,
"url": "https://example.com/url",
"createdAt": "2026-09-24T09:00:00.000Z",
"updatedAt": "2026-09-24T09:00:00.000Z"
}"#);
let api = support::MockApi::start(vec![support::Reply::status(503), support::Reply::json(201, response.clone())]).await;
let params: types::IncomingWebhooksCreateParams = support::from_json(r#"{"accountId":"accountId 1","name":"name 1","to":"to 1"}"#);
let result = api.client().incoming_webhooks().create(params).await.unwrap();
support::assert_json(&result, &response);
let calls = api.calls().await;
assert_eq!(calls.len(), 2);
let key = calls[0].header(sdk::IDEMPOTENCY_HEADER).unwrap();
assert!(!key.is_empty());
assert_eq!(calls[1].header(sdk::IDEMPOTENCY_HEADER), Some(key));
assert_eq!(calls[0].body, calls[1].body);
}
#[tokio::test]
async fn get() {
let response = support::json(r#"{
"object": "incoming_webhook",
"id": "id 1",
"accountId": "accountId 1",
"projectId": "projectId 1",
"name": "name 1",
"to": "to 1",
"enabled": true,
"url": "https://example.com/url",
"createdAt": "2026-09-24T09:00:00.000Z",
"updatedAt": "2026-09-24T09:00:00.000Z"
}"#);
let api = support::MockApi::start(vec![support::Reply::json(200, response.clone())]).await;
let result = api.client().incoming_webhooks().get("k57d9x3m2q8v1b6n4c0h7j5pwa9r2ytz").await.unwrap();
support::assert_json(&result, &response);
let calls = api.calls().await;
assert_eq!(calls.len(), 1);
assert_eq!(calls[0].method, "GET");
assert_eq!(calls[0].path, "/v1/incoming-webhooks/k57d9x3m2q8v1b6n4c0h7j5pwa9r2ytz");
assert_eq!(calls[0].query, support::pairs(&[]));
assert!(calls[0].body.is_none());
assert!(calls[0].header(sdk::IDEMPOTENCY_HEADER).is_none());
}
#[tokio::test]
async fn update() {
let response = support::json(r#"{
"object": "incoming_webhook",
"id": "id 1",
"accountId": "accountId 1",
"projectId": "projectId 1",
"name": "name 1",
"to": "to 1",
"enabled": true,
"url": "https://example.com/url",
"createdAt": "2026-09-24T09:00:00.000Z",
"updatedAt": "2026-09-24T09:00:00.000Z"
}"#);
let api = support::MockApi::start(vec![support::Reply::json(200, response.clone())]).await;
let params: types::IncomingWebhooksUpdateParams = support::from_json(r#"{"name":"name 1","enabled":true,"rotateUrl":true}"#);
let result = api.client().incoming_webhooks().update("k57d9x3m2q8v1b6n4c0h7j5pwa9r2ytz", params).await.unwrap();
support::assert_json(&result, &response);
let calls = api.calls().await;
assert_eq!(calls.len(), 1);
assert_eq!(calls[0].method, "PATCH");
assert_eq!(calls[0].path, "/v1/incoming-webhooks/k57d9x3m2q8v1b6n4c0h7j5pwa9r2ytz");
assert_eq!(calls[0].query, support::pairs(&[]));
support::assert_json(&calls[0].body, &support::json(r#"{"name":"name 1","enabled":true,"rotateUrl":true}"#));
assert!(calls[0].header(sdk::IDEMPOTENCY_HEADER).is_none());
}
#[tokio::test]
async fn update_without_params() {
let response = support::json(r#"{
"object": "incoming_webhook",
"id": "id 1",
"accountId": "accountId 1",
"projectId": "projectId 1",
"name": "name 1",
"to": "to 1",
"enabled": true,
"url": "https://example.com/url",
"createdAt": "2026-09-24T09:00:00.000Z",
"updatedAt": "2026-09-24T09:00:00.000Z"
}"#);
let api = support::MockApi::start(vec![support::Reply::json(200, response.clone())]).await;
let result = api.client().incoming_webhooks().update("k57d9x3m2q8v1b6n4c0h7j5pwa9r2ytz", Default::default()).await.unwrap();
support::assert_json(&result, &response);
let calls = api.calls().await;
assert_eq!(calls.len(), 1);
assert_eq!(calls[0].method, "PATCH");
assert_eq!(calls[0].path, "/v1/incoming-webhooks/k57d9x3m2q8v1b6n4c0h7j5pwa9r2ytz");
assert_eq!(calls[0].query, support::pairs(&[]));
support::assert_json(&calls[0].body, &support::json(r#"{}"#));
assert!(calls[0].header(sdk::IDEMPOTENCY_HEADER).is_none());
}
#[tokio::test]
async fn update_is_not_repeated() {
let api = support::MockApi::start(vec![
support::Reply::status(503),
support::Reply::status(503),
])
.await;
let params: types::IncomingWebhooksUpdateParams = support::from_json(r#"{"name":"name 1","enabled":true,"rotateUrl":true}"#);
let error = api.client().incoming_webhooks().update("k57d9x3m2q8v1b6n4c0h7j5pwa9r2ytz", params).await.unwrap_err();
assert_eq!(error.status(), Some(503));
assert_eq!(api.calls().await.len(), 1);
}
#[tokio::test]
async fn delete() {
let api = support::MockApi::start(vec![support::Reply::status(204)]).await;
api.client().incoming_webhooks().delete("k57d9x3m2q8v1b6n4c0h7j5pwa9r2ytz").await.unwrap();
let calls = api.calls().await;
assert_eq!(calls.len(), 1);
assert_eq!(calls[0].method, "DELETE");
assert_eq!(calls[0].path, "/v1/incoming-webhooks/k57d9x3m2q8v1b6n4c0h7j5pwa9r2ytz");
assert_eq!(calls[0].query, support::pairs(&[]));
assert!(calls[0].body.is_none());
assert!(calls[0].header(sdk::IDEMPOTENCY_HEADER).is_none());
}
}
mod projects {
use super::*;
#[tokio::test]
async fn create() {
let response = support::json(r#"{
"object": "project",
"id": "id 1",
"name": "name 1",
"externalId": "externalId 1",
"metadata": {
"key": "value 1"
},
"status": "active",
"maxAccounts": 1,
"accountCount": 1,
"createdAt": "2026-09-24T09:00:00.000Z",
"updatedAt": "2026-09-24T09:00:00.000Z"
}"#);
let api = support::MockApi::start(vec![support::Reply::json(201, response.clone())]).await;
let params: types::ProjectsCreateParams = support::from_json(r#"{
"name": "name 1",
"externalId": "externalId 1",
"metadata": {
"key": "value 1"
},
"maxAccounts": 0
}"#);
let result = api.client().projects().create(params).await.unwrap();
support::assert_json(&result, &response);
let calls = api.calls().await;
assert_eq!(calls.len(), 1);
assert_eq!(calls[0].method, "POST");
assert_eq!(calls[0].path, "/v1/projects");
assert_eq!(calls[0].query, support::pairs(&[]));
support::assert_json(&calls[0].body, &support::json(r#"{
"name": "name 1",
"externalId": "externalId 1",
"metadata": {
"key": "value 1"
},
"maxAccounts": 0
}"#));
assert!(calls[0].header(sdk::IDEMPOTENCY_HEADER).is_some_and(|key| !key.is_empty()));
}
#[tokio::test]
async fn create_retries_with_one_key() {
let response = support::json(r#"{
"object": "project",
"id": "id 1",
"name": "name 1",
"externalId": "externalId 1",
"metadata": {
"key": "value 1"
},
"status": "active",
"maxAccounts": 1,
"accountCount": 1,
"createdAt": "2026-09-24T09:00:00.000Z",
"updatedAt": "2026-09-24T09:00:00.000Z"
}"#);
let api = support::MockApi::start(vec![support::Reply::status(503), support::Reply::json(201, response.clone())]).await;
let params: types::ProjectsCreateParams = support::from_json(r#"{
"name": "name 1",
"externalId": "externalId 1",
"metadata": {
"key": "value 1"
},
"maxAccounts": 0
}"#);
let result = api.client().projects().create(params).await.unwrap();
support::assert_json(&result, &response);
let calls = api.calls().await;
assert_eq!(calls.len(), 2);
let key = calls[0].header(sdk::IDEMPOTENCY_HEADER).unwrap();
assert!(!key.is_empty());
assert_eq!(calls[1].header(sdk::IDEMPOTENCY_HEADER), Some(key));
assert_eq!(calls[0].body, calls[1].body);
}
#[tokio::test]
async fn list_streams_every_page() {
let first = support::json(r#"{
"object": "list",
"items": [
{
"object": "project",
"id": "id 1",
"name": "name 1",
"externalId": "externalId 1",
"metadata": {
"key": "value 1"
},
"status": "active",
"maxAccounts": 1,
"accountCount": 1,
"createdAt": "2026-09-24T09:00:00.000Z",
"updatedAt": "2026-09-24T09:00:00.000Z"
}
],
"nextCursor": "cursor_2"
}"#);
let last = support::json(r#"{
"object": "list",
"items": [
{
"object": "project",
"id": "id 1",
"name": "name 1",
"externalId": "externalId 1",
"metadata": {
"key": "value 1"
},
"status": "active",
"maxAccounts": 1,
"accountCount": 1,
"createdAt": "2026-09-24T09:00:00.000Z",
"updatedAt": "2026-09-24T09:00:00.000Z"
}
],
"nextCursor": null
}"#);
let api = support::MockApi::start(vec![
support::Reply::json(200, first),
support::Reply::json(200, last),
])
.await;
let params: types::ProjectsListParams = support::from_json(r#"{"limit":50,"cursor":"cursor 1","externalId":"externalId 1","status":"active"}"#);
let items = api.client().projects().list(params).to_vec().await.unwrap();
support::assert_json(&items, &support::json(r#"[
{
"object": "project",
"id": "id 1",
"name": "name 1",
"externalId": "externalId 1",
"metadata": {
"key": "value 1"
},
"status": "active",
"maxAccounts": 1,
"accountCount": 1,
"createdAt": "2026-09-24T09:00:00.000Z",
"updatedAt": "2026-09-24T09:00:00.000Z"
},
{
"object": "project",
"id": "id 1",
"name": "name 1",
"externalId": "externalId 1",
"metadata": {
"key": "value 1"
},
"status": "active",
"maxAccounts": 1,
"accountCount": 1,
"createdAt": "2026-09-24T09:00:00.000Z",
"updatedAt": "2026-09-24T09:00:00.000Z"
}
]"#));
let calls = api.calls().await;
assert_eq!(calls.len(), 2);
assert_eq!(calls[0].method, "GET");
assert_eq!(calls[0].path, "/v1/projects");
assert_eq!(calls[0].query, support::pairs(&[("limit", "50"), ("externalId", "externalId 1"), ("status", "active"), ("cursor", "cursor 1")]));
assert_eq!(calls[1].query, support::pairs(&[("limit", "50"), ("externalId", "externalId 1"), ("status", "active"), ("cursor", "cursor_2")]));
}
#[tokio::test]
async fn list_fetches_one_page() {
let page = support::json(r#"{
"object": "list",
"items": [
{
"object": "project",
"id": "id 1",
"name": "name 1",
"externalId": "externalId 1",
"metadata": {
"key": "value 1"
},
"status": "active",
"maxAccounts": 1,
"accountCount": 1,
"createdAt": "2026-09-24T09:00:00.000Z",
"updatedAt": "2026-09-24T09:00:00.000Z"
}
],
"nextCursor": null
}"#);
let api = support::MockApi::start(vec![support::Reply::json(200, page.clone())]).await;
let result = api.client().projects().list(Default::default()).page().await.unwrap();
support::assert_json(&result, &page);
let calls = api.calls().await;
assert_eq!(calls.len(), 1);
assert_eq!(calls[0].method, "GET");
assert_eq!(calls[0].path, "/v1/projects");
assert_eq!(calls[0].query, support::pairs(&[]));
}
#[tokio::test]
async fn get() {
let response = support::json(r#"{
"object": "project",
"id": "id 1",
"name": "name 1",
"externalId": "externalId 1",
"metadata": {
"key": "value 1"
},
"status": "active",
"maxAccounts": 1,
"accountCount": 1,
"createdAt": "2026-09-24T09:00:00.000Z",
"updatedAt": "2026-09-24T09:00:00.000Z"
}"#);
let api = support::MockApi::start(vec![support::Reply::json(200, response.clone())]).await;
let result = api.client().projects().get("p23f9g0h1j2k3l4m5n6o7q8r9s0t1u2v").await.unwrap();
support::assert_json(&result, &response);
let calls = api.calls().await;
assert_eq!(calls.len(), 1);
assert_eq!(calls[0].method, "GET");
assert_eq!(calls[0].path, "/v1/projects/p23f9g0h1j2k3l4m5n6o7q8r9s0t1u2v");
assert_eq!(calls[0].query, support::pairs(&[]));
assert!(calls[0].body.is_none());
assert!(calls[0].header(sdk::IDEMPOTENCY_HEADER).is_none());
}
#[tokio::test]
async fn update() {
let response = support::json(r#"{
"object": "project",
"id": "id 1",
"name": "name 1",
"externalId": "externalId 1",
"metadata": {
"key": "value 1"
},
"status": "active",
"maxAccounts": 1,
"accountCount": 1,
"createdAt": "2026-09-24T09:00:00.000Z",
"updatedAt": "2026-09-24T09:00:00.000Z"
}"#);
let api = support::MockApi::start(vec![support::Reply::json(200, response.clone())]).await;
let params: types::ProjectsUpdateParams = support::from_json(r#"{
"name": "name 1",
"externalId": "externalId 1",
"metadata": {
"key": "value 1"
},
"maxAccounts": 0,
"status": "active"
}"#);
let result = api.client().projects().update("p23f9g0h1j2k3l4m5n6o7q8r9s0t1u2v", params).await.unwrap();
support::assert_json(&result, &response);
let calls = api.calls().await;
assert_eq!(calls.len(), 1);
assert_eq!(calls[0].method, "PATCH");
assert_eq!(calls[0].path, "/v1/projects/p23f9g0h1j2k3l4m5n6o7q8r9s0t1u2v");
assert_eq!(calls[0].query, support::pairs(&[]));
support::assert_json(&calls[0].body, &support::json(r#"{
"name": "name 1",
"externalId": "externalId 1",
"metadata": {
"key": "value 1"
},
"maxAccounts": 0,
"status": "active"
}"#));
assert!(calls[0].header(sdk::IDEMPOTENCY_HEADER).is_none());
}
#[tokio::test]
async fn update_without_params() {
let response = support::json(r#"{
"object": "project",
"id": "id 1",
"name": "name 1",
"externalId": "externalId 1",
"metadata": {
"key": "value 1"
},
"status": "active",
"maxAccounts": 1,
"accountCount": 1,
"createdAt": "2026-09-24T09:00:00.000Z",
"updatedAt": "2026-09-24T09:00:00.000Z"
}"#);
let api = support::MockApi::start(vec![support::Reply::json(200, response.clone())]).await;
let result = api.client().projects().update("p23f9g0h1j2k3l4m5n6o7q8r9s0t1u2v", Default::default()).await.unwrap();
support::assert_json(&result, &response);
let calls = api.calls().await;
assert_eq!(calls.len(), 1);
assert_eq!(calls[0].method, "PATCH");
assert_eq!(calls[0].path, "/v1/projects/p23f9g0h1j2k3l4m5n6o7q8r9s0t1u2v");
assert_eq!(calls[0].query, support::pairs(&[]));
support::assert_json(&calls[0].body, &support::json(r#"{}"#));
assert!(calls[0].header(sdk::IDEMPOTENCY_HEADER).is_none());
}
#[tokio::test]
async fn update_is_not_repeated() {
let api = support::MockApi::start(vec![
support::Reply::status(503),
support::Reply::status(503),
])
.await;
let params: types::ProjectsUpdateParams = support::from_json(r#"{
"name": "name 1",
"externalId": "externalId 1",
"metadata": {
"key": "value 1"
},
"maxAccounts": 0,
"status": "active"
}"#);
let error = api.client().projects().update("p23f9g0h1j2k3l4m5n6o7q8r9s0t1u2v", params).await.unwrap_err();
assert_eq!(error.status(), Some(503));
assert_eq!(api.calls().await.len(), 1);
}
#[tokio::test]
async fn delete() {
let api = support::MockApi::start(vec![support::Reply::status(204)]).await;
api.client().projects().delete("p23f9g0h1j2k3l4m5n6o7q8r9s0t1u2v").await.unwrap();
let calls = api.calls().await;
assert_eq!(calls.len(), 1);
assert_eq!(calls[0].method, "DELETE");
assert_eq!(calls[0].path, "/v1/projects/p23f9g0h1j2k3l4m5n6o7q8r9s0t1u2v");
assert_eq!(calls[0].query, support::pairs(&[]));
assert!(calls[0].body.is_none());
assert!(calls[0].header(sdk::IDEMPOTENCY_HEADER).is_none());
}
#[tokio::test]
async fn get_usage() {
let response = support::json(r#"{
"object": "project_usage",
"projectId": "projectId 1",
"period": {
"startsAt": "2026-09-24T09:00:00.000Z",
"endsAt": "2026-09-24T09:00:00.000Z"
},
"billableAccountCount": 1,
"accountCount": 1,
"proxyBytes": 1,
"sentMessageCount": 1,
"receivedMessageCount": 1
}"#);
let api = support::MockApi::start(vec![support::Reply::json(200, response.clone())]).await;
let params: types::ProjectsGetUsageParams = support::from_json(r#"{"month":"2026-09"}"#);
let result = api.client().projects().get_usage("p23f9g0h1j2k3l4m5n6o7q8r9s0t1u2v", params).await.unwrap();
support::assert_json(&result, &response);
let calls = api.calls().await;
assert_eq!(calls.len(), 1);
assert_eq!(calls[0].method, "GET");
assert_eq!(calls[0].path, "/v1/projects/p23f9g0h1j2k3l4m5n6o7q8r9s0t1u2v/usage");
assert_eq!(calls[0].query, support::pairs(&[("month", "2026-09")]));
assert!(calls[0].body.is_none());
assert!(calls[0].header(sdk::IDEMPOTENCY_HEADER).is_none());
}
#[tokio::test]
async fn get_usage_without_params() {
let response = support::json(r#"{
"object": "project_usage",
"projectId": "projectId 1",
"period": {
"startsAt": "2026-09-24T09:00:00.000Z",
"endsAt": "2026-09-24T09:00:00.000Z"
},
"billableAccountCount": 1,
"accountCount": 1,
"proxyBytes": 1,
"sentMessageCount": 1,
"receivedMessageCount": 1
}"#);
let api = support::MockApi::start(vec![support::Reply::json(200, response.clone())]).await;
let result = api.client().projects().get_usage("p23f9g0h1j2k3l4m5n6o7q8r9s0t1u2v", Default::default()).await.unwrap();
support::assert_json(&result, &response);
let calls = api.calls().await;
assert_eq!(calls.len(), 1);
assert_eq!(calls[0].method, "GET");
assert_eq!(calls[0].path, "/v1/projects/p23f9g0h1j2k3l4m5n6o7q8r9s0t1u2v/usage");
assert_eq!(calls[0].query, support::pairs(&[]));
assert!(calls[0].body.is_none());
assert!(calls[0].header(sdk::IDEMPOTENCY_HEADER).is_none());
}
mod api_keys {
use super::*;
#[tokio::test]
async fn list_streams_every_page() {
let first = support::json(r#"{
"object": "list",
"items": [
{
"object": "api_key",
"id": "id 1",
"name": "name 1",
"projectId": "projectId 1",
"keyPrefix": "keyPrefix 1",
"last4": "last4 1",
"createdAt": "2026-09-24T09:00:00.000Z",
"lastUsedAt": "2026-09-24T09:00:00.000Z",
"revokedAt": "2026-09-24T09:00:00.000Z"
}
],
"nextCursor": "cursor_2"
}"#);
let last = support::json(r#"{
"object": "list",
"items": [
{
"object": "api_key",
"id": "id 1",
"name": "name 1",
"projectId": "projectId 1",
"keyPrefix": "keyPrefix 1",
"last4": "last4 1",
"createdAt": "2026-09-24T09:00:00.000Z",
"lastUsedAt": "2026-09-24T09:00:00.000Z",
"revokedAt": "2026-09-24T09:00:00.000Z"
}
],
"nextCursor": null
}"#);
let api = support::MockApi::start(vec![
support::Reply::json(200, first),
support::Reply::json(200, last),
])
.await;
let params: types::ProjectsApiKeysListParams = support::from_json(r#"{"limit":50,"cursor":"cursor 1"}"#);
let items = api.client().projects().api_keys().list("p23f9g0h1j2k3l4m5n6o7q8r9s0t1u2v", params).to_vec().await.unwrap();
support::assert_json(&items, &support::json(r#"[
{
"object": "api_key",
"id": "id 1",
"name": "name 1",
"projectId": "projectId 1",
"keyPrefix": "keyPrefix 1",
"last4": "last4 1",
"createdAt": "2026-09-24T09:00:00.000Z",
"lastUsedAt": "2026-09-24T09:00:00.000Z",
"revokedAt": "2026-09-24T09:00:00.000Z"
},
{
"object": "api_key",
"id": "id 1",
"name": "name 1",
"projectId": "projectId 1",
"keyPrefix": "keyPrefix 1",
"last4": "last4 1",
"createdAt": "2026-09-24T09:00:00.000Z",
"lastUsedAt": "2026-09-24T09:00:00.000Z",
"revokedAt": "2026-09-24T09:00:00.000Z"
}
]"#));
let calls = api.calls().await;
assert_eq!(calls.len(), 2);
assert_eq!(calls[0].method, "GET");
assert_eq!(calls[0].path, "/v1/projects/p23f9g0h1j2k3l4m5n6o7q8r9s0t1u2v/api-keys");
assert_eq!(calls[0].query, support::pairs(&[("limit", "50"), ("cursor", "cursor 1")]));
assert_eq!(calls[1].query, support::pairs(&[("limit", "50"), ("cursor", "cursor_2")]));
}
#[tokio::test]
async fn list_fetches_one_page() {
let page = support::json(r#"{
"object": "list",
"items": [
{
"object": "api_key",
"id": "id 1",
"name": "name 1",
"projectId": "projectId 1",
"keyPrefix": "keyPrefix 1",
"last4": "last4 1",
"createdAt": "2026-09-24T09:00:00.000Z",
"lastUsedAt": "2026-09-24T09:00:00.000Z",
"revokedAt": "2026-09-24T09:00:00.000Z"
}
],
"nextCursor": null
}"#);
let api = support::MockApi::start(vec![support::Reply::json(200, page.clone())]).await;
let result = api.client().projects().api_keys().list("p23f9g0h1j2k3l4m5n6o7q8r9s0t1u2v", Default::default()).page().await.unwrap();
support::assert_json(&result, &page);
let calls = api.calls().await;
assert_eq!(calls.len(), 1);
assert_eq!(calls[0].method, "GET");
assert_eq!(calls[0].path, "/v1/projects/p23f9g0h1j2k3l4m5n6o7q8r9s0t1u2v/api-keys");
assert_eq!(calls[0].query, support::pairs(&[]));
}
#[tokio::test]
async fn create() {
let response = support::json(r#"{
"object": "api_key",
"id": "id 1",
"name": "name 1",
"projectId": "projectId 1",
"keyPrefix": "keyPrefix 1",
"last4": "last4 1",
"createdAt": "2026-09-24T09:00:00.000Z",
"lastUsedAt": "2026-09-24T09:00:00.000Z",
"revokedAt": "2026-09-24T09:00:00.000Z"
}"#);
let api = support::MockApi::start(vec![support::Reply::json(201, response.clone())]).await;
let params: types::ProjectsApiKeysCreateParams = support::from_json(r#"{"name":"name 1"}"#);
let result = api.client().projects().api_keys().create("p23f9g0h1j2k3l4m5n6o7q8r9s0t1u2v", params).await.unwrap();
support::assert_json(&result, &response);
let calls = api.calls().await;
assert_eq!(calls.len(), 1);
assert_eq!(calls[0].method, "POST");
assert_eq!(calls[0].path, "/v1/projects/p23f9g0h1j2k3l4m5n6o7q8r9s0t1u2v/api-keys");
assert_eq!(calls[0].query, support::pairs(&[]));
support::assert_json(&calls[0].body, &support::json(r#"{"name":"name 1"}"#));
assert!(calls[0].header(sdk::IDEMPOTENCY_HEADER).is_some_and(|key| !key.is_empty()));
}
#[tokio::test]
async fn create_retries_with_one_key() {
let response = support::json(r#"{
"object": "api_key",
"id": "id 1",
"name": "name 1",
"projectId": "projectId 1",
"keyPrefix": "keyPrefix 1",
"last4": "last4 1",
"createdAt": "2026-09-24T09:00:00.000Z",
"lastUsedAt": "2026-09-24T09:00:00.000Z",
"revokedAt": "2026-09-24T09:00:00.000Z"
}"#);
let api = support::MockApi::start(vec![support::Reply::status(503), support::Reply::json(201, response.clone())]).await;
let params: types::ProjectsApiKeysCreateParams = support::from_json(r#"{"name":"name 1"}"#);
let result = api.client().projects().api_keys().create("p23f9g0h1j2k3l4m5n6o7q8r9s0t1u2v", params).await.unwrap();
support::assert_json(&result, &response);
let calls = api.calls().await;
assert_eq!(calls.len(), 2);
let key = calls[0].header(sdk::IDEMPOTENCY_HEADER).unwrap();
assert!(!key.is_empty());
assert_eq!(calls[1].header(sdk::IDEMPOTENCY_HEADER), Some(key));
assert_eq!(calls[0].body, calls[1].body);
}
#[tokio::test]
async fn revoke() {
let api = support::MockApi::start(vec![support::Reply::status(204)]).await;
api.client().projects().api_keys().revoke("p23f9g0h1j2k3l4m5n6o7q8r9s0t1u2v", "j48c2d5e8f1g4h7i0k3l6m9n2p5q8r1s").await.unwrap();
let calls = api.calls().await;
assert_eq!(calls.len(), 1);
assert_eq!(calls[0].method, "DELETE");
assert_eq!(calls[0].path, "/v1/projects/p23f9g0h1j2k3l4m5n6o7q8r9s0t1u2v/api-keys/j48c2d5e8f1g4h7i0k3l6m9n2p5q8r1s");
assert_eq!(calls[0].query, support::pairs(&[]));
assert!(calls[0].body.is_none());
assert!(calls[0].header(sdk::IDEMPOTENCY_HEADER).is_none());
}
}
}
mod invitations {
use super::*;
#[tokio::test]
async fn create() {
let response = support::json(r#"{
"object": "invitation",
"id": "id 1",
"projectId": "projectId 1",
"status": "pending",
"url": "url 1",
"inviteeName": "inviteeName 1",
"inviteeEmail": "inviteeEmail 1",
"inviteePhone": "inviteePhone 1",
"suggestedCountry": "suggestedCountry 1",
"proxyLocation": {
"country": "country 1",
"city": "city 1",
"strictCity": false
},
"methods": [
"qr_code"
],
"historySync": "none",
"accountName": "accountName 1",
"accountId": "accountId 1",
"failureReason": "failureReason 1",
"returnUrl": "returnUrl 1",
"metadata": {
"key": "value 1"
},
"emailSentAt": "2026-09-24T09:00:00.000Z",
"expiresAt": "2026-09-24T09:00:00.000Z",
"viewedAt": "2026-09-24T09:00:00.000Z",
"startedAt": "2026-09-24T09:00:00.000Z",
"completedAt": "2026-09-24T09:00:00.000Z",
"createdAt": "2026-09-24T09:00:00.000Z",
"updatedAt": "2026-09-24T09:00:00.000Z"
}"#);
let api = support::MockApi::start(vec![support::Reply::json(201, response.clone())]).await;
let params: types::InvitationsCreateParams = support::from_json(r#"{
"projectId": "projectId 1",
"accountName": "accountName 1",
"inviteeName": "inviteeName 1",
"inviteeEmail": "user@example.com",
"inviteePhone": "inviteePhone 1",
"suggestedCountry": "suggestedCountry 1",
"proxyLocation": {
"country": "country 1",
"city": "city 1",
"strictCity": false
},
"methods": [
"qr_code"
],
"historySync": "none",
"returnUrl": "https://example.com/return-url",
"expiresInDays": 7,
"metadata": {
"key": "value 1"
}
}"#);
let result = api.client().invitations().create(params).await.unwrap();
support::assert_json(&result, &response);
let calls = api.calls().await;
assert_eq!(calls.len(), 1);
assert_eq!(calls[0].method, "POST");
assert_eq!(calls[0].path, "/v1/invitations");
assert_eq!(calls[0].query, support::pairs(&[]));
support::assert_json(&calls[0].body, &support::json(r#"{
"projectId": "projectId 1",
"accountName": "accountName 1",
"inviteeName": "inviteeName 1",
"inviteeEmail": "user@example.com",
"inviteePhone": "inviteePhone 1",
"suggestedCountry": "suggestedCountry 1",
"proxyLocation": {
"country": "country 1",
"city": "city 1",
"strictCity": false
},
"methods": [
"qr_code"
],
"historySync": "none",
"returnUrl": "https://example.com/return-url",
"expiresInDays": 7,
"metadata": {
"key": "value 1"
}
}"#));
assert!(calls[0].header(sdk::IDEMPOTENCY_HEADER).is_some_and(|key| !key.is_empty()));
}
#[tokio::test]
async fn create_without_params() {
let response = support::json(r#"{
"object": "invitation",
"id": "id 1",
"projectId": "projectId 1",
"status": "pending",
"url": "url 1",
"inviteeName": "inviteeName 1",
"inviteeEmail": "inviteeEmail 1",
"inviteePhone": "inviteePhone 1",
"suggestedCountry": "suggestedCountry 1",
"proxyLocation": {
"country": "country 1",
"city": "city 1",
"strictCity": false
},
"methods": [
"qr_code"
],
"historySync": "none",
"accountName": "accountName 1",
"accountId": "accountId 1",
"failureReason": "failureReason 1",
"returnUrl": "returnUrl 1",
"metadata": {
"key": "value 1"
},
"emailSentAt": "2026-09-24T09:00:00.000Z",
"expiresAt": "2026-09-24T09:00:00.000Z",
"viewedAt": "2026-09-24T09:00:00.000Z",
"startedAt": "2026-09-24T09:00:00.000Z",
"completedAt": "2026-09-24T09:00:00.000Z",
"createdAt": "2026-09-24T09:00:00.000Z",
"updatedAt": "2026-09-24T09:00:00.000Z"
}"#);
let api = support::MockApi::start(vec![support::Reply::json(201, response.clone())]).await;
let result = api.client().invitations().create(Default::default()).await.unwrap();
support::assert_json(&result, &response);
let calls = api.calls().await;
assert_eq!(calls.len(), 1);
assert_eq!(calls[0].method, "POST");
assert_eq!(calls[0].path, "/v1/invitations");
assert_eq!(calls[0].query, support::pairs(&[]));
support::assert_json(&calls[0].body, &support::json(r#"{}"#));
assert!(calls[0].header(sdk::IDEMPOTENCY_HEADER).is_some_and(|key| !key.is_empty()));
}
#[tokio::test]
async fn create_retries_with_one_key() {
let response = support::json(r#"{
"object": "invitation",
"id": "id 1",
"projectId": "projectId 1",
"status": "pending",
"url": "url 1",
"inviteeName": "inviteeName 1",
"inviteeEmail": "inviteeEmail 1",
"inviteePhone": "inviteePhone 1",
"suggestedCountry": "suggestedCountry 1",
"proxyLocation": {
"country": "country 1",
"city": "city 1",
"strictCity": false
},
"methods": [
"qr_code"
],
"historySync": "none",
"accountName": "accountName 1",
"accountId": "accountId 1",
"failureReason": "failureReason 1",
"returnUrl": "returnUrl 1",
"metadata": {
"key": "value 1"
},
"emailSentAt": "2026-09-24T09:00:00.000Z",
"expiresAt": "2026-09-24T09:00:00.000Z",
"viewedAt": "2026-09-24T09:00:00.000Z",
"startedAt": "2026-09-24T09:00:00.000Z",
"completedAt": "2026-09-24T09:00:00.000Z",
"createdAt": "2026-09-24T09:00:00.000Z",
"updatedAt": "2026-09-24T09:00:00.000Z"
}"#);
let api = support::MockApi::start(vec![support::Reply::status(503), support::Reply::json(201, response.clone())]).await;
let params: types::InvitationsCreateParams = support::from_json(r#"{
"projectId": "projectId 1",
"accountName": "accountName 1",
"inviteeName": "inviteeName 1",
"inviteeEmail": "user@example.com",
"inviteePhone": "inviteePhone 1",
"suggestedCountry": "suggestedCountry 1",
"proxyLocation": {
"country": "country 1",
"city": "city 1",
"strictCity": false
},
"methods": [
"qr_code"
],
"historySync": "none",
"returnUrl": "https://example.com/return-url",
"expiresInDays": 7,
"metadata": {
"key": "value 1"
}
}"#);
let result = api.client().invitations().create(params).await.unwrap();
support::assert_json(&result, &response);
let calls = api.calls().await;
assert_eq!(calls.len(), 2);
let key = calls[0].header(sdk::IDEMPOTENCY_HEADER).unwrap();
assert!(!key.is_empty());
assert_eq!(calls[1].header(sdk::IDEMPOTENCY_HEADER), Some(key));
assert_eq!(calls[0].body, calls[1].body);
}
#[tokio::test]
async fn list_streams_every_page() {
let first = support::json(r#"{
"object": "list",
"items": [
{
"object": "invitation",
"id": "id 1",
"projectId": "projectId 1",
"status": "pending",
"url": "url 1",
"inviteeName": "inviteeName 1",
"inviteeEmail": "inviteeEmail 1",
"inviteePhone": "inviteePhone 1",
"suggestedCountry": "suggestedCountry 1",
"proxyLocation": {
"country": "country 1",
"city": "city 1",
"strictCity": false
},
"methods": [
"qr_code"
],
"historySync": "none",
"accountName": "accountName 1",
"accountId": "accountId 1",
"failureReason": "failureReason 1",
"returnUrl": "returnUrl 1",
"metadata": {
"key": "value 1"
},
"emailSentAt": "2026-09-24T09:00:00.000Z",
"expiresAt": "2026-09-24T09:00:00.000Z",
"viewedAt": "2026-09-24T09:00:00.000Z",
"startedAt": "2026-09-24T09:00:00.000Z",
"completedAt": "2026-09-24T09:00:00.000Z",
"createdAt": "2026-09-24T09:00:00.000Z",
"updatedAt": "2026-09-24T09:00:00.000Z"
}
],
"nextCursor": "cursor_2"
}"#);
let last = support::json(r#"{
"object": "list",
"items": [
{
"object": "invitation",
"id": "id 1",
"projectId": "projectId 1",
"status": "pending",
"url": "url 1",
"inviteeName": "inviteeName 1",
"inviteeEmail": "inviteeEmail 1",
"inviteePhone": "inviteePhone 1",
"suggestedCountry": "suggestedCountry 1",
"proxyLocation": {
"country": "country 1",
"city": "city 1",
"strictCity": false
},
"methods": [
"qr_code"
],
"historySync": "none",
"accountName": "accountName 1",
"accountId": "accountId 1",
"failureReason": "failureReason 1",
"returnUrl": "returnUrl 1",
"metadata": {
"key": "value 1"
},
"emailSentAt": "2026-09-24T09:00:00.000Z",
"expiresAt": "2026-09-24T09:00:00.000Z",
"viewedAt": "2026-09-24T09:00:00.000Z",
"startedAt": "2026-09-24T09:00:00.000Z",
"completedAt": "2026-09-24T09:00:00.000Z",
"createdAt": "2026-09-24T09:00:00.000Z",
"updatedAt": "2026-09-24T09:00:00.000Z"
}
],
"nextCursor": null
}"#);
let api = support::MockApi::start(vec![
support::Reply::json(200, first),
support::Reply::json(200, last),
])
.await;
let params: types::InvitationsListParams = support::from_json(r#"{"status":"pending","limit":50,"cursor":"cursor 1","projectId":"ext:customer_8812"}"#);
let items = api.client().invitations().list(params).to_vec().await.unwrap();
support::assert_json(&items, &support::json(r#"[
{
"object": "invitation",
"id": "id 1",
"projectId": "projectId 1",
"status": "pending",
"url": "url 1",
"inviteeName": "inviteeName 1",
"inviteeEmail": "inviteeEmail 1",
"inviteePhone": "inviteePhone 1",
"suggestedCountry": "suggestedCountry 1",
"proxyLocation": {
"country": "country 1",
"city": "city 1",
"strictCity": false
},
"methods": [
"qr_code"
],
"historySync": "none",
"accountName": "accountName 1",
"accountId": "accountId 1",
"failureReason": "failureReason 1",
"returnUrl": "returnUrl 1",
"metadata": {
"key": "value 1"
},
"emailSentAt": "2026-09-24T09:00:00.000Z",
"expiresAt": "2026-09-24T09:00:00.000Z",
"viewedAt": "2026-09-24T09:00:00.000Z",
"startedAt": "2026-09-24T09:00:00.000Z",
"completedAt": "2026-09-24T09:00:00.000Z",
"createdAt": "2026-09-24T09:00:00.000Z",
"updatedAt": "2026-09-24T09:00:00.000Z"
},
{
"object": "invitation",
"id": "id 1",
"projectId": "projectId 1",
"status": "pending",
"url": "url 1",
"inviteeName": "inviteeName 1",
"inviteeEmail": "inviteeEmail 1",
"inviteePhone": "inviteePhone 1",
"suggestedCountry": "suggestedCountry 1",
"proxyLocation": {
"country": "country 1",
"city": "city 1",
"strictCity": false
},
"methods": [
"qr_code"
],
"historySync": "none",
"accountName": "accountName 1",
"accountId": "accountId 1",
"failureReason": "failureReason 1",
"returnUrl": "returnUrl 1",
"metadata": {
"key": "value 1"
},
"emailSentAt": "2026-09-24T09:00:00.000Z",
"expiresAt": "2026-09-24T09:00:00.000Z",
"viewedAt": "2026-09-24T09:00:00.000Z",
"startedAt": "2026-09-24T09:00:00.000Z",
"completedAt": "2026-09-24T09:00:00.000Z",
"createdAt": "2026-09-24T09:00:00.000Z",
"updatedAt": "2026-09-24T09:00:00.000Z"
}
]"#));
let calls = api.calls().await;
assert_eq!(calls.len(), 2);
assert_eq!(calls[0].method, "GET");
assert_eq!(calls[0].path, "/v1/invitations");
assert_eq!(calls[0].query, support::pairs(&[("status", "pending"), ("limit", "50"), ("projectId", "ext:customer_8812"), ("cursor", "cursor 1")]));
assert_eq!(calls[1].query, support::pairs(&[("status", "pending"), ("limit", "50"), ("projectId", "ext:customer_8812"), ("cursor", "cursor_2")]));
}
#[tokio::test]
async fn list_fetches_one_page() {
let page = support::json(r#"{
"object": "list",
"items": [
{
"object": "invitation",
"id": "id 1",
"projectId": "projectId 1",
"status": "pending",
"url": "url 1",
"inviteeName": "inviteeName 1",
"inviteeEmail": "inviteeEmail 1",
"inviteePhone": "inviteePhone 1",
"suggestedCountry": "suggestedCountry 1",
"proxyLocation": {
"country": "country 1",
"city": "city 1",
"strictCity": false
},
"methods": [
"qr_code"
],
"historySync": "none",
"accountName": "accountName 1",
"accountId": "accountId 1",
"failureReason": "failureReason 1",
"returnUrl": "returnUrl 1",
"metadata": {
"key": "value 1"
},
"emailSentAt": "2026-09-24T09:00:00.000Z",
"expiresAt": "2026-09-24T09:00:00.000Z",
"viewedAt": "2026-09-24T09:00:00.000Z",
"startedAt": "2026-09-24T09:00:00.000Z",
"completedAt": "2026-09-24T09:00:00.000Z",
"createdAt": "2026-09-24T09:00:00.000Z",
"updatedAt": "2026-09-24T09:00:00.000Z"
}
],
"nextCursor": null
}"#);
let api = support::MockApi::start(vec![support::Reply::json(200, page.clone())]).await;
let result = api.client().invitations().list(Default::default()).page().await.unwrap();
support::assert_json(&result, &page);
let calls = api.calls().await;
assert_eq!(calls.len(), 1);
assert_eq!(calls[0].method, "GET");
assert_eq!(calls[0].path, "/v1/invitations");
assert_eq!(calls[0].query, support::pairs(&[]));
}
#[tokio::test]
async fn get() {
let response = support::json(r#"{
"object": "invitation",
"id": "id 1",
"projectId": "projectId 1",
"status": "pending",
"url": "url 1",
"inviteeName": "inviteeName 1",
"inviteeEmail": "inviteeEmail 1",
"inviteePhone": "inviteePhone 1",
"suggestedCountry": "suggestedCountry 1",
"proxyLocation": {
"country": "country 1",
"city": "city 1",
"strictCity": false
},
"methods": [
"qr_code"
],
"historySync": "none",
"accountName": "accountName 1",
"accountId": "accountId 1",
"failureReason": "failureReason 1",
"returnUrl": "returnUrl 1",
"metadata": {
"key": "value 1"
},
"emailSentAt": "2026-09-24T09:00:00.000Z",
"expiresAt": "2026-09-24T09:00:00.000Z",
"viewedAt": "2026-09-24T09:00:00.000Z",
"startedAt": "2026-09-24T09:00:00.000Z",
"completedAt": "2026-09-24T09:00:00.000Z",
"createdAt": "2026-09-24T09:00:00.000Z",
"updatedAt": "2026-09-24T09:00:00.000Z"
}"#);
let api = support::MockApi::start(vec![support::Reply::json(200, response.clone())]).await;
let result = api.client().invitations().get("q64x2v7b1n9m3c8z5a0s4d6f2g7h1j3k").await.unwrap();
support::assert_json(&result, &response);
let calls = api.calls().await;
assert_eq!(calls.len(), 1);
assert_eq!(calls[0].method, "GET");
assert_eq!(calls[0].path, "/v1/invitations/q64x2v7b1n9m3c8z5a0s4d6f2g7h1j3k");
assert_eq!(calls[0].query, support::pairs(&[]));
assert!(calls[0].body.is_none());
assert!(calls[0].header(sdk::IDEMPOTENCY_HEADER).is_none());
}
#[tokio::test]
async fn cancel() {
let response = support::json(r#"{
"object": "invitation",
"id": "id 1",
"projectId": "projectId 1",
"status": "pending",
"url": "url 1",
"inviteeName": "inviteeName 1",
"inviteeEmail": "inviteeEmail 1",
"inviteePhone": "inviteePhone 1",
"suggestedCountry": "suggestedCountry 1",
"proxyLocation": {
"country": "country 1",
"city": "city 1",
"strictCity": false
},
"methods": [
"qr_code"
],
"historySync": "none",
"accountName": "accountName 1",
"accountId": "accountId 1",
"failureReason": "failureReason 1",
"returnUrl": "returnUrl 1",
"metadata": {
"key": "value 1"
},
"emailSentAt": "2026-09-24T09:00:00.000Z",
"expiresAt": "2026-09-24T09:00:00.000Z",
"viewedAt": "2026-09-24T09:00:00.000Z",
"startedAt": "2026-09-24T09:00:00.000Z",
"completedAt": "2026-09-24T09:00:00.000Z",
"createdAt": "2026-09-24T09:00:00.000Z",
"updatedAt": "2026-09-24T09:00:00.000Z"
}"#);
let api = support::MockApi::start(vec![support::Reply::json(200, response.clone())]).await;
let result = api.client().invitations().cancel("q64x2v7b1n9m3c8z5a0s4d6f2g7h1j3k").await.unwrap();
support::assert_json(&result, &response);
let calls = api.calls().await;
assert_eq!(calls.len(), 1);
assert_eq!(calls[0].method, "POST");
assert_eq!(calls[0].path, "/v1/invitations/q64x2v7b1n9m3c8z5a0s4d6f2g7h1j3k/cancel");
assert_eq!(calls[0].query, support::pairs(&[]));
assert!(calls[0].body.is_none());
assert!(calls[0].header(sdk::IDEMPOTENCY_HEADER).is_some_and(|key| !key.is_empty()));
}
#[tokio::test]
async fn cancel_retries_with_one_key() {
let response = support::json(r#"{
"object": "invitation",
"id": "id 1",
"projectId": "projectId 1",
"status": "pending",
"url": "url 1",
"inviteeName": "inviteeName 1",
"inviteeEmail": "inviteeEmail 1",
"inviteePhone": "inviteePhone 1",
"suggestedCountry": "suggestedCountry 1",
"proxyLocation": {
"country": "country 1",
"city": "city 1",
"strictCity": false
},
"methods": [
"qr_code"
],
"historySync": "none",
"accountName": "accountName 1",
"accountId": "accountId 1",
"failureReason": "failureReason 1",
"returnUrl": "returnUrl 1",
"metadata": {
"key": "value 1"
},
"emailSentAt": "2026-09-24T09:00:00.000Z",
"expiresAt": "2026-09-24T09:00:00.000Z",
"viewedAt": "2026-09-24T09:00:00.000Z",
"startedAt": "2026-09-24T09:00:00.000Z",
"completedAt": "2026-09-24T09:00:00.000Z",
"createdAt": "2026-09-24T09:00:00.000Z",
"updatedAt": "2026-09-24T09:00:00.000Z"
}"#);
let api = support::MockApi::start(vec![support::Reply::status(503), support::Reply::json(200, response.clone())]).await;
let result = api.client().invitations().cancel("q64x2v7b1n9m3c8z5a0s4d6f2g7h1j3k").await.unwrap();
support::assert_json(&result, &response);
let calls = api.calls().await;
assert_eq!(calls.len(), 2);
let key = calls[0].header(sdk::IDEMPOTENCY_HEADER).unwrap();
assert!(!key.is_empty());
assert_eq!(calls[1].header(sdk::IDEMPOTENCY_HEADER), Some(key));
assert_eq!(calls[0].body, calls[1].body);
}
#[tokio::test]
async fn resend() {
let response = support::json(r#"{
"object": "invitation",
"id": "id 1",
"projectId": "projectId 1",
"status": "pending",
"url": "url 1",
"inviteeName": "inviteeName 1",
"inviteeEmail": "inviteeEmail 1",
"inviteePhone": "inviteePhone 1",
"suggestedCountry": "suggestedCountry 1",
"proxyLocation": {
"country": "country 1",
"city": "city 1",
"strictCity": false
},
"methods": [
"qr_code"
],
"historySync": "none",
"accountName": "accountName 1",
"accountId": "accountId 1",
"failureReason": "failureReason 1",
"returnUrl": "returnUrl 1",
"metadata": {
"key": "value 1"
},
"emailSentAt": "2026-09-24T09:00:00.000Z",
"expiresAt": "2026-09-24T09:00:00.000Z",
"viewedAt": "2026-09-24T09:00:00.000Z",
"startedAt": "2026-09-24T09:00:00.000Z",
"completedAt": "2026-09-24T09:00:00.000Z",
"createdAt": "2026-09-24T09:00:00.000Z",
"updatedAt": "2026-09-24T09:00:00.000Z"
}"#);
let api = support::MockApi::start(vec![support::Reply::json(200, response.clone())]).await;
let result = api.client().invitations().resend("q64x2v7b1n9m3c8z5a0s4d6f2g7h1j3k").await.unwrap();
support::assert_json(&result, &response);
let calls = api.calls().await;
assert_eq!(calls.len(), 1);
assert_eq!(calls[0].method, "POST");
assert_eq!(calls[0].path, "/v1/invitations/q64x2v7b1n9m3c8z5a0s4d6f2g7h1j3k/resend");
assert_eq!(calls[0].query, support::pairs(&[]));
assert!(calls[0].body.is_none());
assert!(calls[0].header(sdk::IDEMPOTENCY_HEADER).is_some_and(|key| !key.is_empty()));
}
#[tokio::test]
async fn resend_retries_with_one_key() {
let response = support::json(r#"{
"object": "invitation",
"id": "id 1",
"projectId": "projectId 1",
"status": "pending",
"url": "url 1",
"inviteeName": "inviteeName 1",
"inviteeEmail": "inviteeEmail 1",
"inviteePhone": "inviteePhone 1",
"suggestedCountry": "suggestedCountry 1",
"proxyLocation": {
"country": "country 1",
"city": "city 1",
"strictCity": false
},
"methods": [
"qr_code"
],
"historySync": "none",
"accountName": "accountName 1",
"accountId": "accountId 1",
"failureReason": "failureReason 1",
"returnUrl": "returnUrl 1",
"metadata": {
"key": "value 1"
},
"emailSentAt": "2026-09-24T09:00:00.000Z",
"expiresAt": "2026-09-24T09:00:00.000Z",
"viewedAt": "2026-09-24T09:00:00.000Z",
"startedAt": "2026-09-24T09:00:00.000Z",
"completedAt": "2026-09-24T09:00:00.000Z",
"createdAt": "2026-09-24T09:00:00.000Z",
"updatedAt": "2026-09-24T09:00:00.000Z"
}"#);
let api = support::MockApi::start(vec![support::Reply::status(503), support::Reply::json(200, response.clone())]).await;
let result = api.client().invitations().resend("q64x2v7b1n9m3c8z5a0s4d6f2g7h1j3k").await.unwrap();
support::assert_json(&result, &response);
let calls = api.calls().await;
assert_eq!(calls.len(), 2);
let key = calls[0].header(sdk::IDEMPOTENCY_HEADER).unwrap();
assert!(!key.is_empty());
assert_eq!(calls[1].header(sdk::IDEMPOTENCY_HEADER), Some(key));
assert_eq!(calls[0].body, calls[1].body);
}
}
mod branding {
use super::*;
#[tokio::test]
async fn get() {
let response = support::json(r#"{
"object": "branding",
"displayName": "displayName 1",
"logoUrl": "logoUrl 1",
"accentColor": "accentColor 1",
"supportUrl": "supportUrl 1",
"hideWuapiBranding": true
}"#);
let api = support::MockApi::start(vec![support::Reply::json(200, response.clone())]).await;
let result = api.client().branding().get().await.unwrap();
support::assert_json(&result, &response);
let calls = api.calls().await;
assert_eq!(calls.len(), 1);
assert_eq!(calls[0].method, "GET");
assert_eq!(calls[0].path, "/v1/branding");
assert_eq!(calls[0].query, support::pairs(&[]));
assert!(calls[0].body.is_none());
assert!(calls[0].header(sdk::IDEMPOTENCY_HEADER).is_none());
}
#[tokio::test]
async fn update() {
let response = support::json(r#"{
"object": "branding",
"displayName": "displayName 1",
"logoUrl": "logoUrl 1",
"accentColor": "accentColor 1",
"supportUrl": "supportUrl 1",
"hideWuapiBranding": true
}"#);
let api = support::MockApi::start(vec![support::Reply::json(200, response.clone())]).await;
let params: types::BrandingUpdateParams = support::from_json(r#"{
"displayName": "displayName 1",
"logoUrl": "https://example.com/logo-url",
"accentColor": "accentColor 1",
"supportUrl": "https://example.com/support-url",
"hideWuapiBranding": true
}"#);
let result = api.client().branding().update(params).await.unwrap();
support::assert_json(&result, &response);
let calls = api.calls().await;
assert_eq!(calls.len(), 1);
assert_eq!(calls[0].method, "PATCH");
assert_eq!(calls[0].path, "/v1/branding");
assert_eq!(calls[0].query, support::pairs(&[]));
support::assert_json(&calls[0].body, &support::json(r#"{
"displayName": "displayName 1",
"logoUrl": "https://example.com/logo-url",
"accentColor": "accentColor 1",
"supportUrl": "https://example.com/support-url",
"hideWuapiBranding": true
}"#));
assert!(calls[0].header(sdk::IDEMPOTENCY_HEADER).is_none());
}
#[tokio::test]
async fn update_without_params() {
let response = support::json(r#"{
"object": "branding",
"displayName": "displayName 1",
"logoUrl": "logoUrl 1",
"accentColor": "accentColor 1",
"supportUrl": "supportUrl 1",
"hideWuapiBranding": true
}"#);
let api = support::MockApi::start(vec![support::Reply::json(200, response.clone())]).await;
let result = api.client().branding().update(Default::default()).await.unwrap();
support::assert_json(&result, &response);
let calls = api.calls().await;
assert_eq!(calls.len(), 1);
assert_eq!(calls[0].method, "PATCH");
assert_eq!(calls[0].path, "/v1/branding");
assert_eq!(calls[0].query, support::pairs(&[]));
support::assert_json(&calls[0].body, &support::json(r#"{}"#));
assert!(calls[0].header(sdk::IDEMPOTENCY_HEADER).is_none());
}
#[tokio::test]
async fn update_is_not_repeated() {
let api = support::MockApi::start(vec![
support::Reply::status(503),
support::Reply::status(503),
])
.await;
let params: types::BrandingUpdateParams = support::from_json(r#"{
"displayName": "displayName 1",
"logoUrl": "https://example.com/logo-url",
"accentColor": "accentColor 1",
"supportUrl": "https://example.com/support-url",
"hideWuapiBranding": true
}"#);
let error = api.client().branding().update(params).await.unwrap_err();
assert_eq!(error.status(), Some(503));
assert_eq!(api.calls().await.len(), 1);
}
}
mod usage {
use super::*;
#[tokio::test]
async fn get() {
let response = support::json(r#"{
"object": "usage",
"period": {
"startsAt": "2026-09-24T09:00:00.000Z",
"endsAt": "2026-09-24T09:00:00.000Z"
},
"currency": "usd",
"billableAccountCount": 1,
"accountUnitPriceCents": 1,
"accountFeeCents": 1,
"proxyBytes": 1,
"includedProxyBytes": 1,
"billableProxyBytes": 1,
"proxyFeeCents": 1,
"totalCents": 1
}"#);
let api = support::MockApi::start(vec![support::Reply::json(200, response.clone())]).await;
let result = api.client().usage().get().await.unwrap();
support::assert_json(&result, &response);
let calls = api.calls().await;
assert_eq!(calls.len(), 1);
assert_eq!(calls[0].method, "GET");
assert_eq!(calls[0].path, "/v1/usage");
assert_eq!(calls[0].query, support::pairs(&[]));
assert!(calls[0].body.is_none());
assert!(calls[0].header(sdk::IDEMPOTENCY_HEADER).is_none());
}
#[tokio::test]
async fn by_project() {
let response = support::json(r#"{
"object": "usage_report",
"period": {
"startsAt": "2026-09-24T09:00:00.000Z",
"endsAt": "2026-09-24T09:00:00.000Z"
},
"projects": [
{
"projectId": "projectId 1",
"externalId": "externalId 1",
"name": "name 1",
"billableAccountCount": 1,
"accountCount": 1,
"proxyBytes": 1,
"sentMessageCount": 1,
"receivedMessageCount": 1
}
],
"unassigned": {
"billableAccountCount": 1,
"accountCount": 1,
"proxyBytes": 1,
"sentMessageCount": 1,
"receivedMessageCount": 1
},
"totals": {
"billableAccountCount": 1,
"accountCount": 1,
"proxyBytes": 1,
"sentMessageCount": 1,
"receivedMessageCount": 1
}
}"#);
let api = support::MockApi::start(vec![support::Reply::json(200, response.clone())]).await;
let params: types::UsageByProjectParams = support::from_json(r#"{"month":"2026-09"}"#);
let result = api.client().usage().by_project(params).await.unwrap();
support::assert_json(&result, &response);
let calls = api.calls().await;
assert_eq!(calls.len(), 1);
assert_eq!(calls[0].method, "GET");
assert_eq!(calls[0].path, "/v1/usage/by-project");
assert_eq!(calls[0].query, support::pairs(&[("month", "2026-09")]));
assert!(calls[0].body.is_none());
assert!(calls[0].header(sdk::IDEMPOTENCY_HEADER).is_none());
}
#[tokio::test]
async fn by_project_without_params() {
let response = support::json(r#"{
"object": "usage_report",
"period": {
"startsAt": "2026-09-24T09:00:00.000Z",
"endsAt": "2026-09-24T09:00:00.000Z"
},
"projects": [
{
"projectId": "projectId 1",
"externalId": "externalId 1",
"name": "name 1",
"billableAccountCount": 1,
"accountCount": 1,
"proxyBytes": 1,
"sentMessageCount": 1,
"receivedMessageCount": 1
}
],
"unassigned": {
"billableAccountCount": 1,
"accountCount": 1,
"proxyBytes": 1,
"sentMessageCount": 1,
"receivedMessageCount": 1
},
"totals": {
"billableAccountCount": 1,
"accountCount": 1,
"proxyBytes": 1,
"sentMessageCount": 1,
"receivedMessageCount": 1
}
}"#);
let api = support::MockApi::start(vec![support::Reply::json(200, response.clone())]).await;
let result = api.client().usage().by_project(Default::default()).await.unwrap();
support::assert_json(&result, &response);
let calls = api.calls().await;
assert_eq!(calls.len(), 1);
assert_eq!(calls[0].method, "GET");
assert_eq!(calls[0].path, "/v1/usage/by-project");
assert_eq!(calls[0].query, support::pairs(&[]));
assert!(calls[0].body.is_none());
assert!(calls[0].header(sdk::IDEMPOTENCY_HEADER).is_none());
}
}