UNPKG

1.17 kBJavaScriptView Raw
1
2// var d = require("debug")("raptorjs:test:models")
3
4const models = require("../index").models
5var assert = require("chai").assert
6
7describe("Models", function () {
8
9 it("should deserialize / serialize a device", function () {
10
11 const json = require("./data/device")
12 const dev = new models.Device(json)
13
14 assert.equal(dev.name, json.name)
15
16 assert.equal(
17 dev.getStream("temperature").getChannel("color").type,
18 json.streams["temperature"].channels["color"]
19 )
20 assert.equal(
21 dev.getAction("makePhoto").status,
22 json.actions[1].status
23 )
24
25 const json2 = dev.toJSON()
26
27 assert.equal(
28 json2.streams.temperature.channels.degree.type,
29 json.streams.temperature.channels.degree.type
30 )
31 assert.equal(
32 json2.streams.test.channels.text.type,
33 json.streams.test.text
34 )
35 assert.equal(
36 json2.streams.description,
37 json.streams.description
38 )
39
40 assert.equal(
41 json2.actions.makePhoto.status,
42 json.actions[1].status
43 )
44
45 })
46
47})