batch_mode_batch_schema/
batch_error_response_body.rs1crate::ix!();
3
4#[derive(Builder,Getters,Clone,Debug,Serialize,Deserialize)]
5#[builder(setter(into))]
6#[getset(get="pub")]
7pub struct BatchErrorResponseBody {
8 error: BatchErrorDetails,
9}
10
11impl BatchErrorResponseBody {
12
13 pub fn mock(custom_id: &str) -> Self {
14 BatchErrorResponseBody {
15 error: BatchErrorDetails::mock(custom_id),
16 }
17 }
18}
19
20#[cfg(test)]
21mod batch_error_response_body_tests {
22 use super::*;
23 use serde_json::json;
24
25 #[test]
26 fn test_error_body_deserialization() {
27 let json_data = json!({
28 "error": {
29 "message": "Invalid API key",
30 "type": "authentication_error",
31 "param": null,
32 "code": "invalid_api_key"
33 }
34 });
35
36 let body: BatchErrorResponseBody = serde_json::from_value(json_data).unwrap();
37 pretty_assert_eq!(body.error().message(), "Invalid API key");
38 pretty_assert_eq!(body.error().error_type(), "authentication_error");
39 pretty_assert_eq!(*body.error().code(), Some("invalid_api_key".to_string()));
40 }
41
42 #[test]
43 fn test_error_body_missing_fields() {
44 let json_data = json!({
45 "error": {
46 "message": "An error occurred"
47 }
49 });
50
51 let result: Result<BatchErrorResponseBody, _> = serde_json::from_value(json_data);
52 assert!(result.is_err(), "Deserialization should fail if required fields are missing");
53 }
54}