framesmith 0.1.0

A Rust library for controlling Samsung Frame TVs over the local network
Documentation
use crate::protocol::art_response::{
    ArtResponse, ConnInfoResponse, ContentListItem, FilterItem, MatteTypeItem,
};

#[test]
fn deserialize_content_list_response() {
    let json = r#"{
        "id": "test-uuid",
        "request_id": "test-uuid",
        "event": "content_list",
        "content_list": "[{\"content_id\":\"MY-F0001\",\"category_id\":\"MY-C0002\",\"width\":3840,\"height\":2160}]"
    }"#;
    let resp: ArtResponse = serde_json::from_str(json).unwrap();
    assert_eq!(resp.id.as_deref(), Some("test-uuid"));
    assert_eq!(resp.event.as_deref(), Some("content_list"));

    let items: Vec<ContentListItem> =
        serde_json::from_str(resp.content_list.as_ref().unwrap()).unwrap();
    assert_eq!(items.len(), 1);
    assert_eq!(items[0].content_id, "MY-F0001");
    assert_eq!(items[0].width, Some(3840));
}

#[test]
fn deserialize_conn_info_response() {
    let json = r#"{
        "id": "test-uuid",
        "conn_info": "{\"ip\":\"192.168.1.100\",\"port\":8001,\"key\":\"abc123\",\"secured\":false}"
    }"#;
    let resp: ArtResponse = serde_json::from_str(json).unwrap();
    let conn: ConnInfoResponse = serde_json::from_str(resp.conn_info.as_ref().unwrap()).unwrap();
    assert_eq!(conn.ip, "192.168.1.100");
    assert_eq!(conn.port, 8001);
    assert_eq!(conn.key.as_deref(), Some("abc123"));
    assert_eq!(conn.secured, Some(false));
}

#[test]
fn deserialize_matte_list_response() {
    let json = r#"{
        "matte_type_list": "[{\"matte_id\":\"shadowbox_polar\",\"matte_type\":\"shadowbox\"}]"
    }"#;
    let resp: ArtResponse = serde_json::from_str(json).unwrap();
    let mattes: Vec<MatteTypeItem> =
        serde_json::from_str(resp.matte_type_list.as_ref().unwrap()).unwrap();
    assert_eq!(mattes[0].matte_id, "shadowbox_polar");
}

#[test]
fn deserialize_filter_list_response() {
    let json = r#"{
        "filter_list": "[{\"filter_id\":\"ink\",\"filter_name\":\"Ink Wash\"}]"
    }"#;
    let resp: ArtResponse = serde_json::from_str(json).unwrap();
    let filters: Vec<FilterItem> =
        serde_json::from_str(resp.filter_list.as_ref().unwrap()).unwrap();
    assert_eq!(filters[0].filter_id, "ink");
    assert_eq!(filters[0].filter_name.as_deref(), Some("Ink Wash"));
}

#[test]
fn deserialize_artmode_status_response() {
    let json = r#"{
        "event": "artmode_status",
        "value": "on"
    }"#;
    let resp: ArtResponse = serde_json::from_str(json).unwrap();
    assert_eq!(resp.value.as_deref(), Some("on"));
}

#[test]
fn deserialize_error_response() {
    let json = r#"{
        "event": "error",
        "error_code": 400
    }"#;
    let resp: ArtResponse = serde_json::from_str(json).unwrap();
    assert_eq!(resp.error_code.as_ref().unwrap().as_u64(), Some(400));
}

#[test]
fn deserialize_empty_fields_are_none() {
    let json = "{}";
    let resp: ArtResponse = serde_json::from_str(json).unwrap();
    assert!(resp.id.is_none());
    assert!(resp.event.is_none());
    assert!(resp.content_list.is_none());
    assert!(resp.conn_info.is_none());
}