#![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 params: types::ContactsListParams = support::from_json(r#"{"q":"q 1","limit":50,"cursor":"cursor 1"}"#);
let error = api.client().contacts().list("k57a8m2x9d3f0q1wjh6ypc4n2d7s0vbr", params).page().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 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,
"phoneSync": {
"status": "pending",
"source": "manual",
"error": {
"code": "code 1",
"message": "message 1"
},
"updatedAt": "2026-09-24T09:00:00.000Z"
}
}
],
"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,
"phoneSync": {
"status": "pending",
"source": "manual",
"error": {
"code": "code 1",
"message": "message 1"
},
"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::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,
"phoneSync": {
"status": "pending",
"source": "manual",
"error": {
"code": "code 1",
"message": "message 1"
},
"updatedAt": "2026-09-24T09:00:00.000Z"
}
},
{
"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,
"phoneSync": {
"status": "pending",
"source": "manual",
"error": {
"code": "code 1",
"message": "message 1"
},
"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/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,
"phoneSync": {
"status": "pending",
"source": "manual",
"error": {
"code": "code 1",
"message": "message 1"
},
"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().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,
"phoneSync": {
"status": "pending",
"source": "manual",
"error": {
"code": "code 1",
"message": "message 1"
},
"updatedAt": "2026-09-24T09:00:00.000Z"
}
}"#);
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 update() {
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,
"phoneSync": {
"status": "pending",
"source": "manual",
"error": {
"code": "code 1",
"message": "message 1"
},
"updatedAt": "2026-09-24T09:00:00.000Z"
}
}"#);
let api = support::MockApi::start(vec![support::Reply::json(202, response.clone())]).await;
let params: types::ContactsUpdateParams = support::from_json(r#"{"savedName":"savedName 1","firstName":"firstName 1"}"#);
let result = api.client().contacts().update("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, "PATCH");
assert_eq!(calls[0].path, "/v1/accounts/k57a8m2x9d3f0q1wjh6ypc4n2d7s0vbr/contacts/%2B584241112233");
assert_eq!(calls[0].query, support::pairs(&[]));
support::assert_json(&calls[0].body, &support::json(r#"{"savedName":"savedName 1","firstName":"firstName 1"}"#));
assert!(calls[0].header(sdk::IDEMPOTENCY_HEADER).is_some_and(|key| !key.is_empty()));
}
#[tokio::test]
async fn update_retries_with_one_key() {
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,
"phoneSync": {
"status": "pending",
"source": "manual",
"error": {
"code": "code 1",
"message": "message 1"
},
"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::ContactsUpdateParams = support::from_json(r#"{"savedName":"savedName 1","firstName":"firstName 1"}"#);
let result = api.client().contacts().update("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 save_many() {
let response = support::json(r#"{
"object": "contact_batch",
"batchId": "batchId 1",
"contacts": [
{
"contactId": "contactId 1",
"status": "pending"
}
]
}"#);
let api = support::MockApi::start(vec![support::Reply::json(202, response.clone())]).await;
let params: types::ContactsSaveManyParams = support::from_json(r#"{
"contacts": [
{
"contactId": "contactId 1",
"savedName": "savedName 1",
"firstName": "firstName 1"
}
]
}"#);
let result = api.client().contacts().save_many("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/batch");
assert_eq!(calls[0].query, support::pairs(&[]));
support::assert_json(&calls[0].body, &support::json(r#"{
"contacts": [
{
"contactId": "contactId 1",
"savedName": "savedName 1",
"firstName": "firstName 1"
}
]
}"#));
assert!(calls[0].header(sdk::IDEMPOTENCY_HEADER).is_some_and(|key| !key.is_empty()));
}
#[tokio::test]
async fn save_many_retries_with_one_key() {
let response = support::json(r#"{
"object": "contact_batch",
"batchId": "batchId 1",
"contacts": [
{
"contactId": "contactId 1",
"status": "pending"
}
]
}"#);
let api = support::MockApi::start(vec![support::Reply::status(503), support::Reply::json(202, response.clone())]).await;
let params: types::ContactsSaveManyParams = support::from_json(r#"{
"contacts": [
{
"contactId": "contactId 1",
"savedName": "savedName 1",
"firstName": "firstName 1"
}
]
}"#);
let result = api.client().contacts().save_many("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 backfill_auto_save() {
let response = support::json(r#"{"object":"contact_auto_save_backfill","accountId":"accountId 1","dailyLimit":1}"#);
let api = support::MockApi::start(vec![support::Reply::json(202, response.clone())]).await;
let result = api.client().contacts().backfill_auto_save("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/contacts/auto-save/backfill");
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 backfill_auto_save_retries_with_one_key() {
let response = support::json(r#"{"object":"contact_auto_save_backfill","accountId":"accountId 1","dailyLimit":1}"#);
let api = support::MockApi::start(vec![support::Reply::status(503), support::Reply::json(202, response.clone())]).await;
let result = api.client().contacts().backfill_auto_save("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 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,
"phoneSync": {
"status": "pending",
"source": "manual",
"error": {
"code": "code 1",
"message": "message 1"
},
"updatedAt": "2026-09-24T09:00:00.000Z"
}
}
],
"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,
"phoneSync": {
"status": "pending",
"source": "manual",
"error": {
"code": "code 1",
"message": "message 1"
},
"updatedAt": "2026-09-24T09:00:00.000Z"
}
}
],
"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);
}