-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.test.js
95 lines (78 loc) · 3.16 KB
/
index.test.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
"use strict";
jest.useFakeTimers();
const { createHomebridgeMock, miio } = require("./mocks");
jest.doMock("./miio", () => miio.createMock());
const registration = require("./index");
describe("XiaomiRoborockVacuum", () => {
test("Registers the accessory", () => {
const homebridge = createHomebridgeMock();
registration(homebridge);
expect(homebridge.registerAccessory).toBeCalled();
const XiaomiRoborockVacuum = homebridge.registerAccessory.mock.calls[0][2];
expect(XiaomiRoborockVacuum).toHaveProperty(["cleaningStatuses"]);
expect(XiaomiRoborockVacuum).toHaveProperty(["errors"]);
});
test("Fails if no IP provided", () => {
const homebridge = createHomebridgeMock();
registration(homebridge);
const XiaomiRoborockVacuum = homebridge.registerAccessory.mock.calls[0][2];
expect(() => new XiaomiRoborockVacuum(console, {})).toThrowError(
"You must provide an ip address of the vacuum cleaner."
);
});
test("Fails if no token provided", () => {
const homebridge = createHomebridgeMock();
registration(homebridge);
const XiaomiRoborockVacuum = homebridge.registerAccessory.mock.calls[0][2];
expect(
() => new XiaomiRoborockVacuum(console, { ip: "192.168.0.1" })
).toThrowError("You must provide a token of the vacuum cleaner.");
});
test("Fails if both `room` and `autoroom` are provided", () => {
const homebridge = createHomebridgeMock();
registration(homebridge);
const XiaomiRoborockVacuum = homebridge.registerAccessory.mock.calls[0][2];
expect(
() =>
new XiaomiRoborockVacuum(console, {
ip: "192.168.0.1",
token: "TOKEN",
rooms: [],
autoroom: true,
})
)
.toThrowError(`Both "autoroom" and "rooms" config options can't be used at the same time.\n
Please, use "autoroom" to retrieve the "rooms" config and remove it when not needed.`);
});
describe("Client with minimum config", () => {
const homebridge = createHomebridgeMock();
registration(homebridge);
const XiaomiRoborockVacuum = homebridge.registerAccessory.mock.calls[0][2];
const client = new XiaomiRoborockVacuum(console, {
ip: "192.168.0.1",
token: "TOKEN",
});
test("the miio library has been called", () => {
expect(miio.device.matches).toHaveBeenCalledTimes(1);
expect(miio.device.destroy).toHaveBeenCalledTimes(1);
});
test("succeeds in reconnecting", async () => {
miio.device.matches.mockReturnValueOnce(true);
await client.connect();
expect(miio.device.matches).toHaveBeenCalledTimes(2);
expect(miio.device.on).toHaveBeenCalledTimes(2);
expect(miio.device.destroy).toHaveBeenCalledTimes(1);
});
test("it has the basic services", () => {
const initialisedServices = client.getServices();
expect(initialisedServices).toHaveLength(7);
expect(
initialisedServices.map((svc) => `${svc.name}-${svc.type}`)
).toMatchSnapshot();
expect(Object.keys(client.services)).toMatchSnapshot();
});
xdescribe("AccessoryInformation", () => {
const model = client.services.info.getCharacteristic.mock.calls[1];
});
});
});