use serde::{Deserialize, Serialize};
use serde_json::Value;
#[derive(Debug, Clone, Default, Serialize, Deserialize)]
pub struct BulkRawSpec {
pub operations: Vec<Value>,
}
pub(crate) fn render_bulk_first(spec: &BulkRawSpec) -> Value {
spec.operations
.first()
.cloned()
.unwrap_or_else(|| Value::Null)
}
#[cfg(test)]
mod tests {
use super::*;
use crate::core::writer::operation::Operation;
#[test]
fn bulk_action_name_and_auth_requirement() {
let op = Operation::BulkRaw(BulkRawSpec {
operations: vec![serde_json::json!({"type": "to-do", "attributes": {"title": "x"}})],
});
assert_eq!(op.action_name(), "bulk_json");
assert!(op.requires_auth_token());
}
#[test]
fn bulk_render_returns_first_element() {
let op = Operation::BulkRaw(BulkRawSpec {
operations: vec![
serde_json::json!({"type": "to-do", "attributes": {"title": "A"}}),
serde_json::json!({"type": "to-do", "attributes": {"title": "B"}}),
],
});
let v = op.render_json();
assert_eq!(v["attributes"]["title"], "A");
}
}