Improved google_home tests
This commit is contained in:
parent
6b2b450092
commit
1c7aa7b764
|
@ -24,12 +24,14 @@ pub struct Device {
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
|
use serde_json::json;
|
||||||
|
|
||||||
use super::*;
|
use super::*;
|
||||||
use crate::request::{Intent, Request};
|
use crate::request::{Intent, Request};
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn deserialize_set_fan_speed() {
|
fn deserialize_set_fan_speed() {
|
||||||
let json = r#"{
|
let req = json!({
|
||||||
"requestId": "ff36a3cc-ec34-11e6-b1a0-64510650abcf",
|
"requestId": "ff36a3cc-ec34-11e6-b1a0-64510650abcf",
|
||||||
"inputs": [
|
"inputs": [
|
||||||
{
|
{
|
||||||
|
@ -51,9 +53,9 @@ mod tests {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
}"#;
|
});
|
||||||
|
|
||||||
let req: Request = serde_json::from_str(json).unwrap();
|
let req: Request = serde_json::from_value(req).unwrap();
|
||||||
|
|
||||||
assert_eq!(req.inputs.len(), 1);
|
assert_eq!(req.inputs.len(), 1);
|
||||||
match &req.inputs[0] {
|
match &req.inputs[0] {
|
||||||
|
@ -72,7 +74,7 @@ mod tests {
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn deserialize() {
|
fn deserialize() {
|
||||||
let json = r#"{
|
let req = json!({
|
||||||
"requestId": "ff36a3cc-ec34-11e6-b1a0-64510650abcf",
|
"requestId": "ff36a3cc-ec34-11e6-b1a0-64510650abcf",
|
||||||
"inputs": [
|
"inputs": [
|
||||||
{
|
{
|
||||||
|
@ -111,9 +113,9 @@ mod tests {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
}"#;
|
});
|
||||||
|
|
||||||
let req: Request = serde_json::from_str(json).unwrap();
|
let req: Request = serde_json::from_value(req).unwrap();
|
||||||
|
|
||||||
println!("{:?}", req);
|
println!("{:?}", req);
|
||||||
|
|
||||||
|
|
|
@ -15,11 +15,13 @@ pub struct Device {
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
|
use serde_json::json;
|
||||||
|
|
||||||
use crate::request::{Intent, Request};
|
use crate::request::{Intent, Request};
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn deserialize() {
|
fn deserialize() {
|
||||||
let json = r#"{
|
let req = json!({
|
||||||
"requestId": "ff36a3cc-ec34-11e6-b1a0-64510650abcf",
|
"requestId": "ff36a3cc-ec34-11e6-b1a0-64510650abcf",
|
||||||
"inputs": [
|
"inputs": [
|
||||||
{
|
{
|
||||||
|
@ -46,9 +48,9 @@ mod tests {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
}"#;
|
});
|
||||||
|
|
||||||
let req: Request = serde_json::from_str(json).unwrap();
|
let req: Request = serde_json::from_value(req).unwrap();
|
||||||
|
|
||||||
println!("{:?}", req);
|
println!("{:?}", req);
|
||||||
|
|
||||||
|
|
|
@ -1,19 +1,21 @@
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
|
use serde_json::json;
|
||||||
|
|
||||||
use crate::request::{Intent, Request};
|
use crate::request::{Intent, Request};
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn deserialize() {
|
fn deserialize() {
|
||||||
let json = r#"{
|
let req = json!({
|
||||||
"requestId": "ff36a3cc-ec34-11e6-b1a0-64510650abcf",
|
"requestId": "ff36a3cc-ec34-11e6-b1a0-64510650abcf",
|
||||||
"inputs": [
|
"inputs": [
|
||||||
{
|
{
|
||||||
"intent": "action.devices.SYNC"
|
"intent": "action.devices.SYNC"
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
}"#;
|
});
|
||||||
|
|
||||||
let req: Request = serde_json::from_str(json).unwrap();
|
let req: Request = serde_json::from_value(req).unwrap();
|
||||||
|
|
||||||
println!("{:?}", req);
|
println!("{:?}", req);
|
||||||
|
|
||||||
|
|
|
@ -117,10 +117,28 @@ mod tests {
|
||||||
ResponsePayload::Execute(execute_resp),
|
ResponsePayload::Execute(execute_resp),
|
||||||
);
|
);
|
||||||
|
|
||||||
let json = serde_json::to_string(&resp).unwrap();
|
let resp = serde_json::to_value(resp).unwrap();
|
||||||
|
|
||||||
println!("{}", json);
|
let resp_expected = json!({
|
||||||
|
"payload": {
|
||||||
|
"commands": [
|
||||||
|
{
|
||||||
|
"states": {
|
||||||
|
"on": true,
|
||||||
|
"online": true
|
||||||
|
},
|
||||||
|
"ids": ["123"],
|
||||||
|
"status": "SUCCESS"
|
||||||
|
}, {
|
||||||
|
"errorCode": "deviceNotFound",
|
||||||
|
"ids": ["456"],
|
||||||
|
"status":"ERROR"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"requestId": "ff36a3cc-ec34-11e6-b1a0-64510650abcf"
|
||||||
|
});
|
||||||
|
|
||||||
// TODO: Add a known correct output to test against
|
assert_eq!(resp, resp_expected);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -113,10 +113,26 @@ mod tests {
|
||||||
ResponsePayload::Query(query_resp),
|
ResponsePayload::Query(query_resp),
|
||||||
);
|
);
|
||||||
|
|
||||||
let json = serde_json::to_string(&resp).unwrap();
|
let resp = serde_json::to_value(resp).unwrap();
|
||||||
|
|
||||||
println!("{}", json);
|
let resp_expected = json!({
|
||||||
|
"requestId": "ff36a3cc-ec34-11e6-b1a0-64510650abcf",
|
||||||
// TODO: Add a known correct output to test against
|
"payload": {
|
||||||
|
"devices": {
|
||||||
|
"123": {
|
||||||
|
"online": true,
|
||||||
|
"status": "SUCCESS",
|
||||||
|
"on": true
|
||||||
|
},
|
||||||
|
"456": {
|
||||||
|
"online": true,
|
||||||
|
"status": "SUCCESS",
|
||||||
|
"on":true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
assert_eq!(resp, resp_expected);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -46,6 +46,7 @@ pub struct Device {
|
||||||
pub room_hint: Option<String>,
|
pub room_hint: Option<String>,
|
||||||
#[serde(skip_serializing_if = "Option::is_none")]
|
#[serde(skip_serializing_if = "Option::is_none")]
|
||||||
pub device_info: Option<device::Info>,
|
pub device_info: Option<device::Info>,
|
||||||
|
#[serde(skip_serializing_if = "serde_json::Value::is_null")]
|
||||||
pub attributes: serde_json::Value,
|
pub attributes: serde_json::Value,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -67,6 +68,8 @@ impl Device {
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
|
use serde_json::json;
|
||||||
|
|
||||||
use super::*;
|
use super::*;
|
||||||
use crate::response::{Response, ResponsePayload};
|
use crate::response::{Response, ResponsePayload};
|
||||||
use crate::traits::Trait;
|
use crate::traits::Trait;
|
||||||
|
@ -96,10 +99,35 @@ mod tests {
|
||||||
ResponsePayload::Sync(sync_resp),
|
ResponsePayload::Sync(sync_resp),
|
||||||
);
|
);
|
||||||
|
|
||||||
let json = serde_json::to_string(&resp).unwrap();
|
let resp = serde_json::to_value(resp).unwrap();
|
||||||
|
|
||||||
println!("{}", json);
|
let resp_expected = json!({
|
||||||
|
"requestId": "ff36a3cc-ec34-11e6-b1a0-64510650abcf",
|
||||||
// assert_eq!(json, r#"{"requestId":"ff36a3cc-ec34-11e6-b1a0-64510650abcf","payload":{"agentUserId":"1836.15267389","devices":[{"id":"123","type":"action.devices.types.KETTLE","traits":["action.devices.traits.OnOff"],"name":{"defaultNames":["My Outlet 1234"],"name":"Night light","nicknames":["wall plug"]},"willReportState":false,"roomHint":"kitchen","deviceInfo":{"manufacturer":"lights-out-inc","model":"hs1234","hwVersion":"3.2","swVersion":"11.4"}}]}}"#)
|
"payload": {
|
||||||
|
"agentUserId": "1836.15267389",
|
||||||
|
"devices": [
|
||||||
|
{
|
||||||
|
"id": "123",
|
||||||
|
"type": "action.devices.types.KETTLE",
|
||||||
|
"traits": ["action.devices.traits.OnOff"],
|
||||||
|
"name": {
|
||||||
|
"defaultNames": ["My Outlet 1234"],
|
||||||
|
"name": "Night light",
|
||||||
|
"nicknames": ["wall plug"]
|
||||||
|
},
|
||||||
|
"willReportState": false,
|
||||||
|
"roomHint": "kitchen",
|
||||||
|
"deviceInfo": {
|
||||||
|
"manufacturer": "lights-out-inc",
|
||||||
|
"model": "hs1234",
|
||||||
|
"hwVersion": "3.2",
|
||||||
|
"swVersion": "11.4"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
assert_eq!(resp, resp_expected);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user