#![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::ChatsListParams = support::from_json(r#"{
"archived": true,
"unread": true,
"type": "direct",
"q": "q 1",
"limit": 50,
"cursor": "cursor 1"
}"#);
let error = api.client().chats().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": "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());
}