use serde_json::{json, Value};
use crate::error::ImError;
use crate::outbound::registry::{require_str, OutboundCommand, OutboundRegistration};
struct TemplateReceivedCommand;
impl OutboundCommand for TemplateReceivedCommand {
fn name(&self) -> &'static str {
"im_template_received"
}
fn build(&self, args: &Value) -> Result<(&'static str, Value), ImError> {
let post_id = require_str(args, "post_id", self.name())?;
Ok(("post/templateReceived", json!({ "postId": post_id })))
}
}
static TEMPLATE_RECEIVED: TemplateReceivedCommand = TemplateReceivedCommand;
inventory::submit! {
OutboundRegistration {
name: "im_template_received",
command: &TEMPLATE_RECEIVED,
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn normalized_public_payload_builds_go_wire_body() {
let normalized = crate::client_api::normalize_command_payload(
"im_template_received",
br#"{"postId":"post-1"}"#,
)
.expect("normalize public payload");
let args: Value = serde_json::from_slice(&normalized).expect("decode normalized payload");
let (path, body) = TEMPLATE_RECEIVED
.build(&args)
.expect("build outbound request");
assert_eq!(path, "post/templateReceived");
assert_eq!(body, json!({ "postId": "post-1" }));
}
}