use schemars::JsonSchema;
use serde::{Deserialize, Serialize};
use uuid::Uuid;
use crate::capabilities::ChannelCapabilities;
#[derive(Debug, Clone, Serialize, Deserialize, JsonSchema)]
pub struct ChannelHandshake {
pub channel_type: String,
pub channel_version: String,
pub capabilities: ChannelCapabilities,
pub auth_token: String,
}
#[derive(Debug, Clone, Serialize, Deserialize, JsonSchema)]
pub struct ChannelHandshakeResponse {
pub accepted: bool,
pub channel_id: Option<Uuid>,
pub error: Option<String>,
}
#[cfg(test)]
mod tests {
use super::*;
use crate::capabilities::ChannelCapabilities;
#[test]
fn handshake_serde_roundtrip() {
let hs = ChannelHandshake {
channel_type: "discord".to_string(),
channel_version: "1.0.0".to_string(),
capabilities: ChannelCapabilities::RICH_TEXT | ChannelCapabilities::EMBEDS,
auth_token: "secret-token".to_string(),
};
let json = serde_json::to_string(&hs).unwrap();
let deserialized: ChannelHandshake = serde_json::from_str(&json).unwrap();
assert_eq!(deserialized.channel_type, "discord");
assert!(
deserialized
.capabilities
.contains(ChannelCapabilities::RICH_TEXT)
);
}
#[test]
fn handshake_response_serde_roundtrip() {
let resp = ChannelHandshakeResponse {
accepted: true,
channel_id: Some(Uuid::new_v4()),
error: None,
};
let json = serde_json::to_string(&resp).unwrap();
let deserialized: ChannelHandshakeResponse = serde_json::from_str(&json).unwrap();
assert!(deserialized.accepted);
assert!(deserialized.channel_id.is_some());
}
}