#![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::GroupsListParams = support::from_json(r#"{"limit":50,"cursor":"cursor 1"}"#);
let error = api.client().groups().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": "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(&[]));
}