use std::sync::Arc;
use serde::Serialize;
use serde_json::Value;
use crate::core::encoding::{encode_segment, to_json_vec};
use crate::core::error::Result;
use crate::core::models::buyer_conversation::{
BuyerConversationAttachment, BuyerConversationDetail, BuyerConversationList,
BuyerConversationMessage, BuyerConversationNote, BuyerConversationSummary,
};
use crate::http::client::Inner;
use crate::http::transport::HttpMethod;
use crate::resources::ValidateRequest;
use crate::resources::buyer_portal::{
ANY_FILE, BuyerFileUpload, check_extra, delete_ignoring_body,
};
#[derive(Debug, Clone)]
pub struct BuyerConversations {
inner: Arc<Inner>,
}
impl BuyerConversations {
pub(crate) fn new(inner: Arc<Inner>) -> Self {
Self { inner }
}
pub async fn list(
&self,
params: Option<&BuyerConversationListParams>,
) -> Result<BuyerConversationList> {
let query = params.map(BuyerConversationListParams::to_query);
self.inner
.request(
HttpMethod::Get,
"/buyer-conversations",
None,
query.as_deref().unwrap_or(&[]),
None,
)
.await
}
pub async fn start(
&self,
params: &BuyerConversationStartRequest,
) -> Result<BuyerConversationDetail> {
params.validate()?;
self.post("/buyer-conversations", params).await
}
pub async fn retrieve(
&self,
id: &str,
params: Option<&BuyerConversationMessagesParams>,
) -> Result<BuyerConversationDetail> {
let query = params.map(BuyerConversationMessagesParams::to_query);
self.inner
.request(
HttpMethod::Get,
&conversation_path(id),
None,
query.as_deref().unwrap_or(&[]),
None,
)
.await
}
pub async fn reply(
&self,
id: &str,
params: &BuyerConversationReplyRequest,
) -> Result<BuyerConversationMessage> {
params.validate()?;
let path = format!("{}/messages", conversation_path(id));
self.post(&path, params).await
}
pub async fn add_note(
&self,
id: &str,
params: &BuyerConversationNoteRequest,
) -> Result<BuyerConversationNote> {
params.validate()?;
let path = format!("{}/notes", conversation_path(id));
self.post(&path, params).await
}
pub async fn upload_file(
&self,
id: &str,
upload: &BuyerFileUpload<'_>,
) -> Result<BuyerConversationAttachment> {
let path = files_path(id);
let form = upload.encode();
self.inner
.request_with_content_type_and_query(
HttpMethod::Post,
&path,
&[],
&form.body,
&form.content_type,
)
.await
}
pub async fn download_file(&self, id: &str, file_id: &str) -> Result<Vec<u8>> {
let path = format!("{}/{}", files_path(id), encode_segment(file_id));
self.inner
.request_bytes(HttpMethod::Get, &path, &[], ANY_FILE)
.await
}
pub async fn remove_file(&self, id: &str, file_id: &str) -> Result<()> {
let path = format!("{}/{}", files_path(id), encode_segment(file_id));
delete_ignoring_body(&self.inner, &path, &[]).await
}
pub async fn mark_read(&self, id: &str) -> Result<BuyerConversationSummary> {
let path = format!("{}/read", conversation_path(id));
self.inner
.request_body_keyed_with_query(HttpMethod::Post, &path, None, &[], None)
.await
}
pub async fn assign(
&self,
id: &str,
params: &BuyerConversationAssignRequest,
) -> Result<BuyerConversationSummary> {
let path = format!("{}/assign", conversation_path(id));
self.post(&path, params).await
}
pub async fn set_status(
&self,
id: &str,
params: &BuyerConversationStatusRequest,
) -> Result<BuyerConversationSummary> {
let path = format!("{}/status", conversation_path(id));
self.post(&path, params).await
}
async fn post<B: Serialize, T: serde::de::DeserializeOwned>(
&self,
path: &str,
body: &B,
) -> Result<T> {
let body = to_json_vec(body)?;
self.inner
.request_body_keyed_with_query(HttpMethod::Post, path, Some(&body), &[], None)
.await
}
}
fn conversation_path(id: &str) -> String {
format!("/buyer-conversations/{}", encode_segment(id))
}
fn files_path(id: &str) -> String {
format!("/buyer-conversation-files/{}", encode_segment(id))
}
#[derive(Debug, Clone, Default)]
pub struct BuyerConversationListParams {
pub profile_id: Option<String>,
pub status: Option<String>,
pub assigned: Option<String>,
pub test_mode: Option<bool>,
pub customer_id: Option<String>,
pub limit: Option<i32>,
pub offset: Option<i32>,
}
impl BuyerConversationListParams {
pub fn new() -> Self {
Self::default()
}
#[must_use]
pub fn profile_id(mut self, profile_id: impl Into<String>) -> Self {
self.profile_id = Some(profile_id.into());
self
}
#[must_use]
pub fn status(mut self, status: impl Into<String>) -> Self {
self.status = Some(status.into());
self
}
#[must_use]
pub fn assigned(mut self, assigned: impl Into<String>) -> Self {
self.assigned = Some(assigned.into());
self
}
#[must_use]
pub fn test_mode(mut self, test_mode: bool) -> Self {
self.test_mode = Some(test_mode);
self
}
#[must_use]
pub fn customer_id(mut self, customer_id: impl Into<String>) -> Self {
self.customer_id = Some(customer_id.into());
self
}
#[must_use]
pub fn limit(mut self, limit: i32) -> Self {
self.limit = Some(limit);
self
}
#[must_use]
pub fn offset(mut self, offset: i32) -> Self {
self.offset = Some(offset);
self
}
fn to_query(&self) -> Vec<(&'static str, String)> {
let mut q = Vec::new();
if let Some(v) = &self.profile_id {
q.push(("profile_id", v.clone()));
}
if let Some(v) = &self.status {
q.push(("status", v.clone()));
}
if let Some(v) = &self.assigned {
q.push(("assigned", v.clone()));
}
if let Some(v) = self.test_mode {
q.push(("test_mode", v.to_string()));
}
if let Some(v) = &self.customer_id {
q.push(("customer_id", v.clone()));
}
if let Some(v) = self.limit {
q.push(("limit", v.to_string()));
}
if let Some(v) = self.offset {
q.push(("offset", v.to_string()));
}
q
}
}
#[derive(Debug, Clone, Default)]
pub struct BuyerConversationMessagesParams {
pub before: Option<String>,
pub limit: Option<i32>,
}
impl BuyerConversationMessagesParams {
pub fn new() -> Self {
Self::default()
}
#[must_use]
pub fn before(mut self, before: impl Into<String>) -> Self {
self.before = Some(before.into());
self
}
#[must_use]
pub fn limit(mut self, limit: i32) -> Self {
self.limit = Some(limit);
self
}
fn to_query(&self) -> Vec<(&'static str, String)> {
let mut q = Vec::new();
if let Some(v) = &self.before {
q.push(("before", v.clone()));
}
if let Some(v) = self.limit {
q.push(("limit", v.to_string()));
}
q
}
}
#[derive(Debug, Clone, Default, Serialize)]
pub struct BuyerConversationStartRequest {
pub customer_id: String,
pub profile_id: String,
#[serde(skip_serializing_if = "Option::is_none")]
pub test_mode: Option<bool>,
pub body: String,
pub client_message_id: String,
#[serde(skip_serializing_if = "Option::is_none")]
pub purchase: Option<String>,
#[serde(flatten, skip_serializing_if = "serde_json::Map::is_empty")]
pub extra: serde_json::Map<String, Value>,
}
impl BuyerConversationStartRequest {
pub fn new(
customer_id: impl Into<String>,
profile_id: impl Into<String>,
body: impl Into<String>,
client_message_id: impl Into<String>,
) -> Self {
Self {
customer_id: customer_id.into(),
profile_id: profile_id.into(),
body: body.into(),
client_message_id: client_message_id.into(),
..Default::default()
}
}
#[must_use]
pub fn test_mode(mut self, test_mode: bool) -> Self {
self.test_mode = Some(test_mode);
self
}
#[must_use]
pub fn purchase(mut self, purchase: impl Into<String>) -> Self {
self.purchase = Some(purchase.into());
self
}
}
const BUYER_CONVERSATION_START_REQUEST_NAMED: &[&str] = &[
"customer_id",
"profile_id",
"test_mode",
"body",
"client_message_id",
"purchase",
];
impl ValidateRequest for BuyerConversationStartRequest {
fn validate(&self) -> Result<()> {
check_extra(
&self.extra,
BUYER_CONVERSATION_START_REQUEST_NAMED,
"BuyerConversationStartRequest",
)
}
}
#[derive(Debug, Clone, Default, Serialize)]
pub struct BuyerConversationReplyRequest {
pub client_message_id: String,
#[serde(skip_serializing_if = "Option::is_none")]
pub body: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
pub purchase: Option<String>,
#[serde(skip_serializing_if = "Vec::is_empty")]
pub attachments: Vec<String>,
#[serde(flatten, skip_serializing_if = "serde_json::Map::is_empty")]
pub extra: serde_json::Map<String, Value>,
}
impl BuyerConversationReplyRequest {
pub fn new(client_message_id: impl Into<String>) -> Self {
Self {
client_message_id: client_message_id.into(),
..Default::default()
}
}
#[must_use]
pub fn body(mut self, body: impl Into<String>) -> Self {
self.body = Some(body.into());
self
}
#[must_use]
pub fn purchase(mut self, purchase: impl Into<String>) -> Self {
self.purchase = Some(purchase.into());
self
}
#[must_use]
pub fn attachments(mut self, attachments: Vec<String>) -> Self {
self.attachments = attachments;
self
}
}
const BUYER_CONVERSATION_REPLY_REQUEST_NAMED: &[&str] =
&["client_message_id", "body", "purchase", "attachments"];
impl ValidateRequest for BuyerConversationReplyRequest {
fn validate(&self) -> Result<()> {
check_extra(
&self.extra,
BUYER_CONVERSATION_REPLY_REQUEST_NAMED,
"BuyerConversationReplyRequest",
)
}
}
#[derive(Debug, Clone, Default, Serialize)]
pub struct BuyerConversationNoteRequest {
pub body: String,
pub client_note_id: String,
#[serde(flatten, skip_serializing_if = "serde_json::Map::is_empty")]
pub extra: serde_json::Map<String, Value>,
}
impl BuyerConversationNoteRequest {
pub fn new(body: impl Into<String>, client_note_id: impl Into<String>) -> Self {
Self {
body: body.into(),
client_note_id: client_note_id.into(),
extra: serde_json::Map::new(),
}
}
}
const BUYER_CONVERSATION_NOTE_REQUEST_NAMED: &[&str] = &["body", "client_note_id"];
impl ValidateRequest for BuyerConversationNoteRequest {
fn validate(&self) -> Result<()> {
check_extra(
&self.extra,
BUYER_CONVERSATION_NOTE_REQUEST_NAMED,
"BuyerConversationNoteRequest",
)
}
}
#[derive(Debug, Clone, Serialize)]
pub struct BuyerConversationAssignRequest {
pub user_id: Option<String>,
}
impl BuyerConversationAssignRequest {
pub fn user(user_id: impl Into<String>) -> Self {
Self {
user_id: Some(user_id.into()),
}
}
pub fn me() -> Self {
Self::user("me")
}
pub fn nobody() -> Self {
Self { user_id: None }
}
}
#[derive(Debug, Clone, Serialize)]
pub struct BuyerConversationStatusRequest {
pub status: String,
}
impl BuyerConversationStatusRequest {
pub fn new(status: impl Into<String>) -> Self {
Self {
status: status.into(),
}
}
pub fn closed() -> Self {
Self::new("closed")
}
pub fn open() -> Self {
Self::new("open")
}
}
#[cfg(test)]
mod tests {
use super::*;
use crate::core::error::DelopayError;
use crate::http::mock::{Step, client_with};
use serde_json::json;
const SUMMARY_JSON: &str = r#"{
"id": "conv_1", "profile_id": "pro_1", "customer_id": "cus_1",
"customer_name": "Jane Buyer", "customer_email": "jane@example.com",
"test_mode": false, "status": "open", "assigned_to_me": false,
"last_message_at": "2026-01-01T00:00:00Z", "last_message_by": "buyer",
"unread": true, "created_at": "2026-01-01T00:00:00Z", "surprise_field": 1
}"#;
fn detail_json() -> String {
format!(
r#"{{
"conversation": {SUMMARY_JSON},
"messages": [{{"id": "msg_1", "sender": "merchant", "sender_name": "Sam",
"sender_user_id": "usr_1", "body": "Hi", "attachments": [],
"created_at": "2026-01-01T00:00:00Z"}}],
"has_more": false,
"case_updates": [{{"source": "refund_request", "source_id": "rr_1",
"event": {{"at": "2026-01-01T00:00:00Z",
"kind": "opened", "actor": "buyer"}}}}],
"notes": [],
"attachment_rules": {{"enabled": true, "file_types": ["pdf"],
"max_file_megabytes": 10, "max_files": 5}},
"surprise_field": 2
}}"#
)
}
#[tokio::test]
async fn list_sends_every_filter_with_the_dashboard_token() {
let (client, mock) = client_with(vec![Step::ok(&format!(
r#"{{"data":[{SUMMARY_JSON}],"total_count":1,"surprise_field":3}}"#
))]);
let params = BuyerConversationListParams::new()
.profile_id("pro_1")
.status("open")
.assigned("me")
.test_mode(false)
.customer_id("cus_1")
.limit(20)
.offset(40);
let list = client
.with_jwt("jwt_1")
.buyer_conversations()
.list(Some(¶ms))
.await
.unwrap();
assert_eq!(list.total_count, 1);
assert_eq!(list.data[0].extra["surprise_field"], 1);
assert_eq!(list.extra["surprise_field"], 3);
let debug = format!("{list:?}");
assert!(!debug.contains("jane@example.com"), "{debug}");
assert!(!debug.contains("Jane Buyer"), "{debug}");
let seen = mock.seen.lock().unwrap();
assert_eq!(seen[0].method, "GET");
assert_eq!(
seen[0].url,
"https://api.test/buyer-conversations?profile_id=pro_1&status=open&assigned=me&test_mode=false&customer_id=cus_1&limit=20&offset=40"
);
assert_eq!(seen[0].header("authorization"), Some("Bearer jwt_1"));
assert_eq!(seen[0].header("api-key"), None);
}
#[tokio::test]
async fn start_posts_the_first_message() {
let (client, mock) = client_with(vec![Step::ok(&detail_json())]);
let params = BuyerConversationStartRequest::new("cus_1", "pro_1", "Hello", "msg_12345678")
.test_mode(true)
.purchase("pay_1");
let detail = client.buyer_conversations().start(¶ms).await.unwrap();
assert_eq!(detail.conversation.id, "conv_1");
assert_eq!(detail.case_updates[0].source, "refund_request");
assert_eq!(detail.extra["surprise_field"], 2);
let seen = mock.seen.lock().unwrap();
assert_eq!(seen[0].method, "POST");
assert_eq!(seen[0].url, "https://api.test/buyer-conversations");
assert_eq!(
seen[0].body_json(),
json!({
"customer_id": "cus_1",
"profile_id": "pro_1",
"test_mode": true,
"body": "Hello",
"client_message_id": "msg_12345678",
"purchase": "pay_1"
})
);
}
#[tokio::test]
async fn retrieve_encodes_the_id_and_pages_back() {
let (client, mock) = client_with(vec![Step::ok(&detail_json())]);
let params = BuyerConversationMessagesParams::new()
.before("msg_9")
.limit(50);
let detail = client
.buyer_conversations()
.retrieve("conv/1", Some(¶ms))
.await
.unwrap();
assert_eq!(detail.messages[0].sender_user_id.as_deref(), Some("usr_1"));
assert_eq!(detail.attachment_rules.max_file_megabytes, 10);
let seen = mock.seen.lock().unwrap();
assert_eq!(seen[0].method, "GET");
assert_eq!(
seen[0].url,
"https://api.test/buyer-conversations/conv%2F1?before=msg_9&limit=50"
);
}
#[tokio::test]
async fn reply_posts_the_answer() {
let (client, mock) = client_with(vec![Step::ok(
r#"{"id":"msg_2","sender":"merchant","sender_name":"Sam","body":"On its way",
"attachments":[{"id":"att_1","file_name":"label.pdf","file_type":"pdf",
"size_bytes":4}],"created_at":"2026-01-01T00:00:00Z","surprise_field":1}"#,
)]);
let params = BuyerConversationReplyRequest::new("msg_12345678")
.body("On its way")
.purchase("pay_1")
.attachments(vec!["att_1".to_string()]);
let message = client
.buyer_conversations()
.reply("conv_1", ¶ms)
.await
.unwrap();
assert_eq!(message.attachments[0].file_name, "label.pdf");
assert_eq!(message.extra["surprise_field"], 1);
let seen = mock.seen.lock().unwrap();
assert_eq!(seen[0].method, "POST");
assert_eq!(
seen[0].url,
"https://api.test/buyer-conversations/conv_1/messages"
);
assert_eq!(
seen[0].body_json(),
json!({
"client_message_id": "msg_12345678",
"body": "On its way",
"purchase": "pay_1",
"attachments": ["att_1"]
})
);
}
#[tokio::test]
async fn add_note_posts_the_note() {
let (client, mock) = client_with(vec![Step::ok(
r#"{"id":"note_1","author_user_id":"usr_1","author_name":"Sam Team",
"body":"Check stock","created_at":"2026-01-01T00:00:00Z","surprise_field":1}"#,
)]);
let note = client
.buyer_conversations()
.add_note(
"conv_1",
&BuyerConversationNoteRequest::new("Check stock", "note_12345678"),
)
.await
.unwrap();
assert_eq!(note.author_user_id, "usr_1");
assert_eq!(note.extra["surprise_field"], 1);
let seen = mock.seen.lock().unwrap();
assert_eq!(seen[0].method, "POST");
assert_eq!(
seen[0].url,
"https://api.test/buyer-conversations/conv_1/notes"
);
assert_eq!(
seen[0].body_json(),
json!({"body": "Check stock", "client_note_id": "note_12345678"})
);
}
#[tokio::test]
async fn upload_file_posts_multipart_to_the_files_path() {
let (client, mock) = client_with(vec![Step::ok(
r#"{"id":"att_1","file_name":"label.pdf","file_type":"pdf","size_bytes":4,
"surprise_field":1}"#,
)]);
let upload = BuyerFileUpload::new("upl_12345678", "label.pdf", "application/pdf", b"%PDF");
let out = client
.buyer_conversations()
.upload_file("conv/1", &upload)
.await
.unwrap();
assert_eq!(out.id, "att_1");
assert_eq!(out.extra["surprise_field"], 1);
let seen = mock.seen.lock().unwrap();
assert_eq!(seen[0].method, "POST");
assert_eq!(
seen[0].url,
"https://api.test/buyer-conversation-files/conv%2F1"
);
let body = String::from_utf8(seen[0].body.clone().unwrap()).unwrap();
assert!(body.contains("name=\"client_upload_id\"\r\n\r\nupl_12345678\r\n"));
assert!(body.contains("Content-Type: application/pdf\r\n\r\n%PDF"));
}
#[tokio::test]
async fn download_file_gets_the_bytes() {
let (client, mock) = client_with(vec![Step::ok("%PDF")]);
let bytes = client
.buyer_conversations()
.download_file("conv_1", "att/1")
.await
.unwrap();
assert_eq!(bytes, b"%PDF");
let seen = mock.seen.lock().unwrap();
assert_eq!(seen[0].method, "GET");
assert_eq!(
seen[0].url,
"https://api.test/buyer-conversation-files/conv_1/att%2F1"
);
assert_eq!(seen[0].header("accept"), Some("*/*"));
}
#[tokio::test]
async fn remove_file_deletes_the_file() {
let (client, mock) = client_with(vec![Step::ok(r#"{"deleted":true,"id":"x"}"#)]);
client
.buyer_conversations()
.remove_file("conv_1", "att_1")
.await
.unwrap();
let seen = mock.seen.lock().unwrap();
assert_eq!(seen[0].method, "DELETE");
assert_eq!(
seen[0].url,
"https://api.test/buyer-conversation-files/conv_1/att_1"
);
}
#[tokio::test]
async fn remove_file_accepts_an_empty_body() {
let (client, _mock) = client_with(vec![Step::ok("")]);
client
.buyer_conversations()
.remove_file("conv_1", "att_1")
.await
.unwrap();
}
#[tokio::test]
async fn mark_read_posts_with_no_body() {
let (client, mock) = client_with(vec![Step::ok(SUMMARY_JSON)]);
let summary = client
.buyer_conversations()
.mark_read("conv_1")
.await
.unwrap();
assert!(summary.unread);
let seen = mock.seen.lock().unwrap();
assert_eq!(seen[0].method, "POST");
assert_eq!(
seen[0].url,
"https://api.test/buyer-conversations/conv_1/read"
);
assert!(seen[0].body.is_none());
}
#[tokio::test]
async fn assign_sends_the_user_or_an_explicit_null() {
let (client, mock) = client_with(vec![Step::ok(SUMMARY_JSON), Step::ok(SUMMARY_JSON)]);
let conversations = client.buyer_conversations();
conversations
.assign("conv_1", &BuyerConversationAssignRequest::me())
.await
.unwrap();
conversations
.assign("conv_1", &BuyerConversationAssignRequest::nobody())
.await
.unwrap();
let seen = mock.seen.lock().unwrap();
assert_eq!(seen[0].method, "POST");
assert_eq!(
seen[0].url,
"https://api.test/buyer-conversations/conv_1/assign"
);
assert_eq!(seen[0].body_json(), json!({"user_id": "me"}));
assert_eq!(seen[1].body_json(), json!({"user_id": null}));
}
#[tokio::test]
async fn set_status_posts_the_status() {
let (client, mock) = client_with(vec![Step::ok(SUMMARY_JSON)]);
client
.buyer_conversations()
.set_status("conv_1", &BuyerConversationStatusRequest::closed())
.await
.unwrap();
let seen = mock.seen.lock().unwrap();
assert_eq!(seen[0].method, "POST");
assert_eq!(
seen[0].url,
"https://api.test/buyer-conversations/conv_1/status"
);
assert_eq!(seen[0].body_json(), json!({"status": "closed"}));
}
#[test]
fn start_validate_rejects_a_colliding_extra_key() {
let mut req = BuyerConversationStartRequest::new("cus_1", "pro_1", "Hi", "msg_12345678");
req.extra.insert("profile_id".to_string(), json!("pro_2"));
match req.validate().unwrap_err() {
DelopayError::InvalidRequest(msg) => assert!(msg.contains("profile_id")),
other => panic!("expected InvalidRequest, got {other:?}"),
}
}
fn assert_named_covers(value: Value, named: &[&str], const_name: &str) {
for key in value.as_object().expect("serializes to an object").keys() {
assert!(
named.contains(&key.as_str()),
"{const_name} is missing wire key `{key}`"
);
}
}
#[test]
fn buyer_conversation_start_request_named_fields_are_complete() {
let req = BuyerConversationStartRequest::new("cus_1", "pro_1", "Hi", "msg_12345678")
.test_mode(true)
.purchase("pay_1");
assert_named_covers(
serde_json::to_value(req).unwrap(),
BUYER_CONVERSATION_START_REQUEST_NAMED,
"BUYER_CONVERSATION_START_REQUEST_NAMED",
);
}
#[test]
fn buyer_conversation_reply_request_named_fields_are_complete() {
let req = BuyerConversationReplyRequest::new("msg_12345678")
.body("x")
.purchase("pay_1")
.attachments(vec!["att_1".to_string()]);
assert_named_covers(
serde_json::to_value(req).unwrap(),
BUYER_CONVERSATION_REPLY_REQUEST_NAMED,
"BUYER_CONVERSATION_REPLY_REQUEST_NAMED",
);
}
#[test]
fn buyer_conversation_note_request_named_fields_are_complete() {
let req = BuyerConversationNoteRequest::new("x", "note_12345678");
assert_named_covers(
serde_json::to_value(req).unwrap(),
BUYER_CONVERSATION_NOTE_REQUEST_NAMED,
"BUYER_CONVERSATION_NOTE_REQUEST_NAMED",
);
}
fn keyed_client(
ok: &str,
) -> (
crate::Delopay,
std::sync::Arc<crate::http::mock::MockTransport>,
) {
let (client, mock) = crate::http::mock::client_with_retries(
vec![
Step::status(503, r#"{"error":{"message":"down"}}"#),
Step::ok(ok),
],
2,
);
(client.with_idempotency_key("idem_client_wide"), mock)
}
fn assert_sent_once_without_key(mock: &crate::http::mock::MockTransport) {
assert_eq!(
mock.call_count(),
1,
"a 503 on this write must not be retried"
);
assert!(
!mock.seen.lock().unwrap()[0].had_idempotency_key(),
"the client-wide key must not be sent"
);
}
#[tokio::test]
async fn inbox_writes_ignore_the_client_wide_idempotency_key() {
let (client, mock) = keyed_client(SUMMARY_JSON);
let params = BuyerConversationReplyRequest::new("msg_12345678").body("Hi");
assert!(
client
.buyer_conversations()
.reply("conv_1", ¶ms)
.await
.is_err()
);
assert_sent_once_without_key(&mock);
let (client, mock) =
keyed_client(r#"{"id":"att_1","file_name":"a","file_type":"pdf","size_bytes":1}"#);
let upload = BuyerFileUpload::new("upl_12345678", "a.pdf", "application/pdf", b"%PDF");
assert!(
client
.buyer_conversations()
.upload_file("conv_1", &upload)
.await
.is_err()
);
assert_sent_once_without_key(&mock);
let (client, mock) = keyed_client("");
assert!(
client
.buyer_conversations()
.remove_file("conv_1", "att_1")
.await
.is_err()
);
assert_sent_once_without_key(&mock);
let (client, mock) = keyed_client(SUMMARY_JSON);
assert!(
client
.buyer_conversations()
.mark_read("conv_1")
.await
.is_err()
);
assert_sent_once_without_key(&mock);
}
}