Improved google_home tests
This commit is contained in:
parent
758500a071
commit
01dfc6b81e
|
@ -24,36 +24,38 @@ pub struct Device {
|
|||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use serde_json::json;
|
||||
|
||||
use super::*;
|
||||
use crate::request::{Intent, Request};
|
||||
|
||||
#[test]
|
||||
fn deserialize_set_fan_speed() {
|
||||
let json = r#"{
|
||||
"requestId": "ff36a3cc-ec34-11e6-b1a0-64510650abcf",
|
||||
"inputs": [
|
||||
{
|
||||
"intent": "action.devices.EXECUTE",
|
||||
"payload": {
|
||||
"commands": [
|
||||
{
|
||||
"devices": [],
|
||||
"execution": [
|
||||
{
|
||||
"command": "action.devices.commands.SetFanSpeed",
|
||||
"params": {
|
||||
"fanSpeed": "Test"
|
||||
}
|
||||
let req = json!({
|
||||
"requestId": "ff36a3cc-ec34-11e6-b1a0-64510650abcf",
|
||||
"inputs": [
|
||||
{
|
||||
"intent": "action.devices.EXECUTE",
|
||||
"payload": {
|
||||
"commands": [
|
||||
{
|
||||
"devices": [],
|
||||
"execution": [
|
||||
{
|
||||
"command": "action.devices.commands.SetFanSpeed",
|
||||
"params": {
|
||||
"fanSpeed": "Test"
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
]
|
||||
}"#;
|
||||
}
|
||||
]
|
||||
});
|
||||
|
||||
let req: Request = serde_json::from_str(json).unwrap();
|
||||
let req: Request = serde_json::from_value(req).unwrap();
|
||||
|
||||
assert_eq!(req.inputs.len(), 1);
|
||||
match &req.inputs[0] {
|
||||
|
@ -72,48 +74,48 @@ mod tests {
|
|||
|
||||
#[test]
|
||||
fn deserialize() {
|
||||
let json = r#"{
|
||||
"requestId": "ff36a3cc-ec34-11e6-b1a0-64510650abcf",
|
||||
"inputs": [
|
||||
{
|
||||
"intent": "action.devices.EXECUTE",
|
||||
"payload": {
|
||||
"commands": [
|
||||
{
|
||||
"devices": [
|
||||
{
|
||||
"id": "123",
|
||||
"customData": {
|
||||
"fooValue": 74,
|
||||
"barValue": true,
|
||||
"bazValue": "sheepdip"
|
||||
}
|
||||
},
|
||||
{
|
||||
"id": "456",
|
||||
"customData": {
|
||||
"fooValue": 36,
|
||||
"barValue": false,
|
||||
"bazValue": "moarsheep"
|
||||
}
|
||||
let req = json!({
|
||||
"requestId": "ff36a3cc-ec34-11e6-b1a0-64510650abcf",
|
||||
"inputs": [
|
||||
{
|
||||
"intent": "action.devices.EXECUTE",
|
||||
"payload": {
|
||||
"commands": [
|
||||
{
|
||||
"devices": [
|
||||
{
|
||||
"id": "123",
|
||||
"customData": {
|
||||
"fooValue": 74,
|
||||
"barValue": true,
|
||||
"bazValue": "sheepdip"
|
||||
}
|
||||
},
|
||||
{
|
||||
"id": "456",
|
||||
"customData": {
|
||||
"fooValue": 36,
|
||||
"barValue": false,
|
||||
"bazValue": "moarsheep"
|
||||
}
|
||||
}
|
||||
],
|
||||
"execution": [
|
||||
{
|
||||
"command": "action.devices.commands.OnOff",
|
||||
"params": {
|
||||
"on": true
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
],
|
||||
"execution": [
|
||||
{
|
||||
"command": "action.devices.commands.OnOff",
|
||||
"params": {
|
||||
"on": true
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
]
|
||||
}"#;
|
||||
}
|
||||
]
|
||||
});
|
||||
|
||||
let req: Request = serde_json::from_str(json).unwrap();
|
||||
let req: Request = serde_json::from_value(req).unwrap();
|
||||
|
||||
println!("{:?}", req);
|
||||
|
||||
|
|
|
@ -15,40 +15,42 @@ pub struct Device {
|
|||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use serde_json::json;
|
||||
|
||||
use crate::request::{Intent, Request};
|
||||
|
||||
#[test]
|
||||
fn deserialize() {
|
||||
let json = r#"{
|
||||
"requestId": "ff36a3cc-ec34-11e6-b1a0-64510650abcf",
|
||||
"inputs": [
|
||||
{
|
||||
"intent": "action.devices.QUERY",
|
||||
"payload": {
|
||||
"devices": [
|
||||
{
|
||||
"id": "123",
|
||||
"customData": {
|
||||
"fooValue": 74,
|
||||
"barValue": true,
|
||||
"bazValue": "foo"
|
||||
let req = json!({
|
||||
"requestId": "ff36a3cc-ec34-11e6-b1a0-64510650abcf",
|
||||
"inputs": [
|
||||
{
|
||||
"intent": "action.devices.QUERY",
|
||||
"payload": {
|
||||
"devices": [
|
||||
{
|
||||
"id": "123",
|
||||
"customData": {
|
||||
"fooValue": 74,
|
||||
"barValue": true,
|
||||
"bazValue": "foo"
|
||||
}
|
||||
},
|
||||
{
|
||||
"id": "456",
|
||||
"customData": {
|
||||
"fooValue": 12,
|
||||
"barValue": false,
|
||||
"bazValue": "bar"
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
"id": "456",
|
||||
"customData": {
|
||||
"fooValue": 12,
|
||||
"barValue": false,
|
||||
"bazValue": "bar"
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
]
|
||||
}"#;
|
||||
]
|
||||
});
|
||||
|
||||
let req: Request = serde_json::from_str(json).unwrap();
|
||||
let req: Request = serde_json::from_value(req).unwrap();
|
||||
|
||||
println!("{:?}", req);
|
||||
|
||||
|
|
|
@ -1,19 +1,21 @@
|
|||
#[cfg(test)]
|
||||
mod tests {
|
||||
use serde_json::json;
|
||||
|
||||
use crate::request::{Intent, Request};
|
||||
|
||||
#[test]
|
||||
fn deserialize() {
|
||||
let json = r#"{
|
||||
"requestId": "ff36a3cc-ec34-11e6-b1a0-64510650abcf",
|
||||
"inputs": [
|
||||
{
|
||||
"intent": "action.devices.SYNC"
|
||||
}
|
||||
]
|
||||
}"#;
|
||||
let req = json!({
|
||||
"requestId": "ff36a3cc-ec34-11e6-b1a0-64510650abcf",
|
||||
"inputs": [
|
||||
{
|
||||
"intent": "action.devices.SYNC"
|
||||
}
|
||||
]
|
||||
});
|
||||
|
||||
let req: Request = serde_json::from_str(json).unwrap();
|
||||
let req: Request = serde_json::from_value(req).unwrap();
|
||||
|
||||
println!("{:?}", req);
|
||||
|
||||
|
|
|
@ -117,10 +117,28 @@ mod tests {
|
|||
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),
|
||||
);
|
||||
|
||||
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",
|
||||
"payload": {
|
||||
"devices": {
|
||||
"123": {
|
||||
"online": true,
|
||||
"status": "SUCCESS",
|
||||
"on": true
|
||||
},
|
||||
"456": {
|
||||
"online": true,
|
||||
"status": "SUCCESS",
|
||||
"on":true
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
// TODO: Add a known correct output to test against
|
||||
assert_eq!(resp, resp_expected);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -46,6 +46,7 @@ pub struct Device {
|
|||
pub room_hint: Option<String>,
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub device_info: Option<device::Info>,
|
||||
#[serde(skip_serializing_if = "serde_json::Value::is_null")]
|
||||
pub attributes: serde_json::Value,
|
||||
}
|
||||
|
||||
|
@ -67,6 +68,8 @@ impl Device {
|
|||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use serde_json::json;
|
||||
|
||||
use super::*;
|
||||
use crate::response::{Response, ResponsePayload};
|
||||
use crate::traits::Trait;
|
||||
|
@ -96,10 +99,35 @@ mod tests {
|
|||
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",
|
||||
"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!(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"}}]}}"#)
|
||||
assert_eq!(resp, resp_expected);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user