@digital-alchemy/hass 24.9.3 → 24.9.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +3 -0
- package/dist/dynamic.d.ts +1 -1
- package/dist/dynamic.js +7 -2
- package/dist/dynamic.js.map +1 -1
- package/dist/extensions/area.extension.d.ts +2 -12
- package/dist/extensions/area.extension.js +20 -26
- package/dist/extensions/area.extension.js.map +1 -1
- package/dist/extensions/backup.extension.d.ts +2 -7
- package/dist/extensions/backup.extension.js +5 -8
- package/dist/extensions/backup.extension.js.map +1 -1
- package/dist/extensions/call-proxy.extension.d.ts +1 -1
- package/dist/extensions/call-proxy.extension.js +3 -22
- package/dist/extensions/call-proxy.extension.js.map +1 -1
- package/dist/extensions/config.extension.d.ts +2 -6
- package/dist/extensions/config.extension.js +21 -25
- package/dist/extensions/config.extension.js.map +1 -1
- package/dist/extensions/conversation.extension.d.ts +2 -6
- package/dist/extensions/conversation.extension.js +5 -8
- package/dist/extensions/conversation.extension.js.map +1 -1
- package/dist/extensions/device.extension.d.ts +2 -5
- package/dist/extensions/device.extension.js +16 -22
- package/dist/extensions/device.extension.js.map +1 -1
- package/dist/extensions/entity.extension.d.ts +2 -61
- package/dist/extensions/entity.extension.js +42 -83
- package/dist/extensions/entity.extension.js.map +1 -1
- package/dist/extensions/events.extension.d.ts +3 -11
- package/dist/extensions/events.extension.js +8 -11
- package/dist/extensions/events.extension.js.map +1 -1
- package/dist/extensions/fetch-api.extension.d.ts +12 -4
- package/dist/extensions/fetch-api.extension.js +23 -35
- package/dist/extensions/fetch-api.extension.js.map +1 -1
- package/dist/extensions/floor.extension.d.ts +2 -9
- package/dist/extensions/floor.extension.js +17 -23
- package/dist/extensions/floor.extension.js.map +1 -1
- package/dist/extensions/id-by.extension.js +15 -20
- package/dist/extensions/id-by.extension.js.map +1 -1
- package/dist/extensions/index.d.ts +1 -0
- package/dist/extensions/index.js +16 -18
- package/dist/extensions/index.js.map +1 -1
- package/dist/extensions/internal.extension.d.ts +18 -0
- package/dist/extensions/internal.extension.js +102 -0
- package/dist/extensions/internal.extension.js.map +1 -0
- package/dist/extensions/label.extension.d.ts +2 -9
- package/dist/extensions/label.extension.js +17 -23
- package/dist/extensions/label.extension.js.map +1 -1
- package/dist/extensions/reference.extension.d.ts +2 -12
- package/dist/extensions/reference.extension.js +19 -25
- package/dist/extensions/reference.extension.js.map +1 -1
- package/dist/extensions/registry.extension.d.ts +2 -7
- package/dist/extensions/registry.extension.js +1 -4
- package/dist/extensions/registry.extension.js.map +1 -1
- package/dist/extensions/websocket-api.extension.d.ts +3 -78
- package/dist/extensions/websocket-api.extension.js +82 -165
- package/dist/extensions/websocket-api.extension.js.map +1 -1
- package/dist/extensions/zone.extension.d.ts +2 -7
- package/dist/extensions/zone.extension.js +15 -21
- package/dist/extensions/zone.extension.js.map +1 -1
- package/dist/hass.module.d.ts +47 -36
- package/dist/hass.module.js +70 -70
- package/dist/hass.module.js.map +1 -1
- package/dist/helpers/backup.helper.js +1 -2
- package/dist/helpers/constants.helper.js +15 -18
- package/dist/helpers/constants.helper.js.map +1 -1
- package/dist/helpers/device.helper.js +2 -5
- package/dist/helpers/device.helper.js.map +1 -1
- package/dist/helpers/entity-state.helper.d.ts +3 -8
- package/dist/helpers/entity-state.helper.js +1 -8
- package/dist/helpers/entity-state.helper.js.map +1 -1
- package/dist/helpers/features.helper.js +79 -85
- package/dist/helpers/features.helper.js.map +1 -1
- package/dist/helpers/fetch/calendar.js +1 -2
- package/dist/helpers/fetch/configuration.js +2 -5
- package/dist/helpers/fetch/configuration.js.map +1 -1
- package/dist/helpers/fetch/index.js +5 -8
- package/dist/helpers/fetch/index.js.map +1 -1
- package/dist/helpers/fetch/server-log.js +1 -2
- package/dist/helpers/fetch/server-log.js.map +1 -1
- package/dist/helpers/fetch/service-list.js +1 -2
- package/dist/helpers/fetch/weather-forecasts.js +1 -2
- package/dist/helpers/fetch/weather-forecasts.js.map +1 -1
- package/dist/helpers/fetch.helper.d.ts +162 -0
- package/dist/helpers/fetch.helper.js +161 -0
- package/dist/helpers/fetch.helper.js.map +1 -0
- package/dist/helpers/id-by.helper.js +1 -2
- package/dist/helpers/index.d.ts +2 -1
- package/dist/helpers/index.js +13 -15
- package/dist/helpers/index.js.map +1 -1
- package/dist/helpers/interfaces.helper.d.ts +228 -0
- package/dist/helpers/interfaces.helper.js +10 -0
- package/dist/helpers/interfaces.helper.js.map +1 -0
- package/dist/helpers/manifest.helper.d.ts +0 -1
- package/dist/helpers/manifest.helper.js +0 -1
- package/dist/helpers/notify.helper.d.ts +13 -5
- package/dist/helpers/notify.helper.js +1 -2
- package/dist/helpers/registry.js +7 -10
- package/dist/helpers/registry.js.map +1 -1
- package/dist/helpers/utility.helper.d.ts +6 -1
- package/dist/helpers/utility.helper.js +9 -13
- package/dist/helpers/utility.helper.js.map +1 -1
- package/dist/helpers/websocket.helper.d.ts +1 -2
- package/dist/helpers/websocket.helper.js +1 -2
- package/dist/index.js +5 -8
- package/dist/index.js.map +1 -1
- package/dist/mock_assistant/extensions/area.extension.d.ts +8 -0
- package/dist/mock_assistant/extensions/area.extension.js +51 -0
- package/dist/mock_assistant/extensions/area.extension.js.map +1 -0
- package/dist/mock_assistant/extensions/config.extension.d.ts +14 -0
- package/dist/mock_assistant/extensions/config.extension.js +29 -0
- package/dist/mock_assistant/extensions/config.extension.js.map +1 -0
- package/dist/mock_assistant/extensions/device.extension.d.ts +8 -0
- package/dist/mock_assistant/extensions/device.extension.js +33 -0
- package/dist/mock_assistant/extensions/device.extension.js.map +1 -0
- package/dist/mock_assistant/extensions/entity-registry.extension.d.ts +13 -0
- package/dist/mock_assistant/extensions/entity-registry.extension.js +28 -0
- package/dist/mock_assistant/extensions/entity-registry.extension.js.map +1 -0
- package/dist/mock_assistant/extensions/entity.extension.d.ts +30 -0
- package/dist/mock_assistant/extensions/entity.extension.js +77 -0
- package/dist/mock_assistant/extensions/entity.extension.js.map +1 -0
- package/dist/mock_assistant/extensions/events.extension.d.ts +1 -1
- package/dist/mock_assistant/extensions/events.extension.js +3 -6
- package/dist/mock_assistant/extensions/events.extension.js.map +1 -1
- package/dist/mock_assistant/extensions/fetch.extension.d.ts +1 -0
- package/dist/mock_assistant/extensions/fetch.extension.js +4 -0
- package/dist/mock_assistant/extensions/fetch.extension.js.map +1 -0
- package/dist/mock_assistant/extensions/fixtures.extension.d.ts +1 -1
- package/dist/mock_assistant/extensions/fixtures.extension.js +29 -33
- package/dist/mock_assistant/extensions/fixtures.extension.js.map +1 -1
- package/dist/mock_assistant/extensions/floor.extension.d.ts +8 -0
- package/dist/mock_assistant/extensions/floor.extension.js +51 -0
- package/dist/mock_assistant/extensions/floor.extension.js.map +1 -0
- package/dist/mock_assistant/extensions/index.d.ts +10 -0
- package/dist/mock_assistant/extensions/index.js +12 -5
- package/dist/mock_assistant/extensions/index.js.map +1 -1
- package/dist/mock_assistant/extensions/label.extension.d.ts +8 -0
- package/dist/mock_assistant/extensions/label.extension.js +51 -0
- package/dist/mock_assistant/extensions/label.extension.js.map +1 -0
- package/dist/mock_assistant/extensions/services.extension.d.ts +12 -0
- package/dist/mock_assistant/extensions/services.extension.js +20 -0
- package/dist/mock_assistant/extensions/services.extension.js.map +1 -0
- package/dist/mock_assistant/extensions/websocket-api.extension.d.ts +15 -0
- package/dist/mock_assistant/extensions/websocket-api.extension.js +68 -0
- package/dist/mock_assistant/extensions/websocket-api.extension.js.map +1 -0
- package/dist/mock_assistant/extensions/zone.extension.d.ts +8 -0
- package/dist/mock_assistant/extensions/zone.extension.js +51 -0
- package/dist/mock_assistant/extensions/zone.extension.js.map +1 -0
- package/dist/mock_assistant/helpers/fixtures.js +1 -2
- package/dist/mock_assistant/helpers/index.d.ts +0 -1
- package/dist/mock_assistant/helpers/index.js +1 -5
- package/dist/mock_assistant/helpers/index.js.map +1 -1
- package/dist/mock_assistant/index.js +3 -6
- package/dist/mock_assistant/index.js.map +1 -1
- package/dist/mock_assistant/main.js +11 -15
- package/dist/mock_assistant/main.js.map +1 -1
- package/dist/mock_assistant/mock-assistant.module.d.ts +156 -3
- package/dist/mock_assistant/mock-assistant.module.js +56 -11
- package/dist/mock_assistant/mock-assistant.module.js.map +1 -1
- package/dist/quickboot.module.js +5 -8
- package/dist/quickboot.module.js.map +1 -1
- package/dist/testing/area.spec.js +106 -194
- package/dist/testing/area.spec.js.map +1 -1
- package/dist/testing/backup.spec.js +97 -139
- package/dist/testing/backup.spec.js.map +1 -1
- package/dist/testing/config.spec.js +79 -153
- package/dist/testing/config.spec.js.map +1 -1
- package/dist/testing/device.spec.js +35 -69
- package/dist/testing/device.spec.js.map +1 -1
- package/dist/testing/entity.spec.js +94 -149
- package/dist/testing/entity.spec.js.map +1 -1
- package/dist/testing/events.spec.js +33 -57
- package/dist/testing/events.spec.js.map +1 -1
- package/dist/testing/fetch-api.spec.js +242 -427
- package/dist/testing/fetch-api.spec.js.map +1 -1
- package/dist/testing/fixtures.spec.d.ts +1 -0
- package/dist/testing/fixtures.spec.js +150 -0
- package/dist/testing/fixtures.spec.js.map +1 -0
- package/dist/testing/floor.spec.js +106 -194
- package/dist/testing/floor.spec.js.map +1 -1
- package/dist/testing/id-by.spec.js +68 -107
- package/dist/testing/id-by.spec.js.map +1 -1
- package/dist/testing/label.spec.js +106 -194
- package/dist/testing/label.spec.js.map +1 -1
- package/dist/testing/ref-by.spec.js +155 -219
- package/dist/testing/ref-by.spec.js.map +1 -1
- package/dist/testing/websocket.spec.d.ts +1 -8
- package/dist/testing/websocket.spec.js +35 -50
- package/dist/testing/websocket.spec.js.map +1 -1
- package/dist/testing/workflow.spec.js +82 -81
- package/dist/testing/workflow.spec.js.map +1 -1
- package/dist/testing/zone.spec.js +61 -113
- package/dist/testing/zone.spec.js.map +1 -1
- package/package.json +62 -44
- package/scripts/mock-assistant.sh +5 -0
- package/scripts/run-e2e.sh +7 -0
- package/scripts/test.sh +2 -0
- package/src/dynamic.ts +4254 -0
- package/src/extensions/area.extension.ts +118 -0
- package/src/extensions/backup.extension.ts +63 -0
- package/src/extensions/call-proxy.extension.ts +113 -0
- package/src/extensions/config.extension.ts +119 -0
- package/src/extensions/conversation.extension.ts +46 -0
- package/src/extensions/device.extension.ts +56 -0
- package/src/extensions/entity.extension.ts +344 -0
- package/src/extensions/events.extension.ts +25 -0
- package/src/extensions/fetch-api.extension.ts +269 -0
- package/src/extensions/floor.extension.ts +76 -0
- package/src/extensions/id-by.extension.ts +157 -0
- package/src/extensions/index.ts +16 -0
- package/src/extensions/internal.extension.ts +145 -0
- package/src/extensions/label.extension.ts +83 -0
- package/src/extensions/reference.extension.ts +330 -0
- package/src/extensions/registry.extension.ts +44 -0
- package/src/extensions/websocket-api.extension.ts +554 -0
- package/src/extensions/zone.extension.ts +69 -0
- package/src/hass.module.ts +217 -0
- package/src/helpers/backup.helper.ts +11 -0
- package/src/helpers/constants.helper.ts +30 -0
- package/src/helpers/device.helper.ts +25 -0
- package/src/helpers/entity-state.helper.ts +171 -0
- package/src/helpers/features.helper.ts +580 -0
- package/src/helpers/fetch/calendar.ts +54 -0
- package/src/helpers/fetch/configuration.ts +75 -0
- package/src/helpers/fetch/index.ts +5 -0
- package/src/helpers/fetch/server-log.ts +28 -0
- package/src/helpers/fetch/service-list.ts +64 -0
- package/src/helpers/fetch/weather-forecasts.ts +86 -0
- package/src/helpers/fetch.helper.ts +328 -0
- package/src/helpers/id-by.helper.ts +53 -0
- package/src/helpers/index.ts +13 -0
- package/src/helpers/interfaces.helper.ts +340 -0
- package/src/helpers/manifest.helper.ts +0 -0
- package/src/helpers/notify.helper.ts +302 -0
- package/src/helpers/registry.ts +281 -0
- package/src/helpers/utility.helper.ts +147 -0
- package/src/helpers/websocket.helper.ts +117 -0
- package/src/index.ts +5 -0
- package/src/mock_assistant/extensions/area.extension.ts +62 -0
- package/src/mock_assistant/extensions/config.extension.ts +33 -0
- package/src/mock_assistant/extensions/device.extension.ts +44 -0
- package/src/mock_assistant/extensions/entity-registry.extension.ts +41 -0
- package/src/mock_assistant/extensions/entity.extension.ts +114 -0
- package/src/mock_assistant/extensions/events.extension.ts +37 -0
- package/src/mock_assistant/extensions/fetch.extension.ts +3 -0
- package/src/mock_assistant/extensions/fixtures.extension.ts +79 -0
- package/src/mock_assistant/extensions/floor.extension.ts +64 -0
- package/src/mock_assistant/extensions/index.ts +12 -0
- package/src/mock_assistant/extensions/label.extension.ts +64 -0
- package/src/mock_assistant/extensions/services.extension.ts +25 -0
- package/src/mock_assistant/extensions/websocket-api.extension.ts +84 -0
- package/src/mock_assistant/extensions/zone.extension.ts +65 -0
- package/src/mock_assistant/helpers/fixtures.ts +22 -0
- package/src/mock_assistant/helpers/index.ts +1 -0
- package/src/mock_assistant/index.ts +3 -0
- package/src/mock_assistant/main.ts +46 -0
- package/src/mock_assistant/mock-assistant.module.ts +90 -0
- package/src/quickboot.module.ts +23 -0
- package/src/testing/area.spec.ts +189 -0
- package/src/testing/backup.spec.ts +157 -0
- package/src/testing/config.spec.ts +188 -0
- package/src/testing/device.spec.ts +89 -0
- package/src/testing/entity.spec.ts +171 -0
- package/src/testing/events.spec.ts +78 -0
- package/src/testing/fetch-api.spec.ts +410 -0
- package/src/testing/fixtures.spec.ts +158 -0
- package/src/testing/floor.spec.ts +186 -0
- package/src/testing/id-by.spec.ts +140 -0
- package/src/testing/label.spec.ts +186 -0
- package/src/testing/ref-by.spec.ts +300 -0
- package/src/testing/websocket.spec.ts +63 -0
- package/src/testing/workflow.spec.ts +195 -0
- package/src/testing/zone.spec.ts +109 -0
- package/dist/helpers/metrics.helper.d.ts +0 -29
- package/dist/helpers/metrics.helper.js +0 -62
- package/dist/helpers/metrics.helper.js.map +0 -1
- package/dist/mock_assistant/helpers/utils.d.ts +0 -4
- package/dist/mock_assistant/helpers/utils.js +0 -57
- package/dist/mock_assistant/helpers/utils.js.map +0 -1
|
@@ -1,207 +1,139 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
const tslib_1 = require("tslib");
|
|
4
|
-
const dayjs_1 = tslib_1.__importDefault(require("dayjs"));
|
|
5
|
-
const utils_1 = require("../mock_assistant/helpers/utils");
|
|
1
|
+
import dayjs from "dayjs";
|
|
2
|
+
import { hassTestRunner } from "../mock_assistant";
|
|
6
3
|
describe("FetchAPI", () => {
|
|
7
|
-
let application;
|
|
8
4
|
const BASE_URL = "http://homeassistant.some.domain:9123";
|
|
9
5
|
const TOKEN =
|
|
6
|
+
// TODO: Replace hard coded token w/ faker when avail
|
|
7
|
+
// https://github.com/faker-js/faker/pull/2936
|
|
10
8
|
// eslint-disable-next-line @cspell/spellchecker
|
|
11
9
|
"eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ2aWRlbyI6Imh0dHBzOi8vd3d3LnlvdXR1YmUuY29tL3dhdGNoP3Y9ZFF3NHc5V2dYY1EifQ.gPIttZEaLZgov3VZziu3LovcgtDbj8H0-XfBg4f08Y0";
|
|
10
|
+
hassTestRunner.configure({
|
|
11
|
+
hass: { BASE_URL, TOKEN },
|
|
12
|
+
});
|
|
12
13
|
// values are hard coded into tests, update carefully
|
|
13
|
-
const start = (
|
|
14
|
+
const start = dayjs("2024-01-01 00:00:00:00");
|
|
14
15
|
const end = start.add(1, "day");
|
|
15
16
|
afterEach(async () => {
|
|
16
|
-
|
|
17
|
-
await application.teardown();
|
|
18
|
-
application = undefined;
|
|
19
|
-
}
|
|
17
|
+
await hassTestRunner.teardown();
|
|
20
18
|
jest.restoreAllMocks();
|
|
21
19
|
});
|
|
22
20
|
describe("Meta", () => {
|
|
23
21
|
it("Should send the correct headers", async () => {
|
|
24
22
|
expect.assertions(1);
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
const spy = jest
|
|
28
|
-
.spyOn(global, "fetch")
|
|
29
|
-
.mockImplementation(async () => {
|
|
23
|
+
await hassTestRunner.run(({ lifecycle, hass }) => {
|
|
24
|
+
lifecycle.onReady(async () => {
|
|
25
|
+
const spy = jest.spyOn(global, "fetch").mockImplementation(async () => {
|
|
30
26
|
return {
|
|
31
27
|
text: () => "[]",
|
|
32
28
|
};
|
|
33
29
|
});
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
});
|
|
45
|
-
},
|
|
30
|
+
// Calling the base level fetch provided by service
|
|
31
|
+
// The same call is wrapped internally to power everything else
|
|
32
|
+
await hass.fetch.fetch({ url: "/api/" });
|
|
33
|
+
expect(spy).toHaveBeenCalledWith(`${BASE_URL}/api/`, expect.objectContaining({
|
|
34
|
+
headers: {
|
|
35
|
+
Authorization: "Bearer " + TOKEN,
|
|
36
|
+
},
|
|
37
|
+
method: "get",
|
|
38
|
+
}));
|
|
39
|
+
});
|
|
46
40
|
});
|
|
47
|
-
await application.bootstrap((0, utils_1.SILENT_BOOT)({
|
|
48
|
-
hass: {
|
|
49
|
-
AUTO_CONNECT_SOCKET: false,
|
|
50
|
-
AUTO_SCAN_CALL_PROXY: false,
|
|
51
|
-
BASE_URL,
|
|
52
|
-
TOKEN,
|
|
53
|
-
},
|
|
54
|
-
}));
|
|
55
41
|
});
|
|
56
42
|
});
|
|
57
43
|
describe("API Operations", () => {
|
|
58
44
|
it("should format calendarSearch properly", async () => {
|
|
59
45
|
expect.assertions(1);
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
method: "get",
|
|
77
|
-
}));
|
|
78
|
-
});
|
|
79
|
-
},
|
|
46
|
+
await hassTestRunner.run(({ lifecycle, hass }) => {
|
|
47
|
+
const spy = jest.spyOn(global, "fetch").mockImplementation(async () => {
|
|
48
|
+
return {
|
|
49
|
+
text: () => "[]",
|
|
50
|
+
};
|
|
51
|
+
});
|
|
52
|
+
lifecycle.onReady(async () => {
|
|
53
|
+
await hass.fetch.calendarSearch({
|
|
54
|
+
calendar: "calendar.united_states_tx",
|
|
55
|
+
end,
|
|
56
|
+
start,
|
|
57
|
+
});
|
|
58
|
+
expect(spy).toHaveBeenCalledWith(`${BASE_URL}/api/calendars/calendar.united_states_tx?end=${encodeURIComponent(end.toISOString())}&start=${encodeURIComponent(start.toISOString())}`, expect.objectContaining({
|
|
59
|
+
method: "get",
|
|
60
|
+
}));
|
|
61
|
+
});
|
|
80
62
|
});
|
|
81
|
-
await application.bootstrap((0, utils_1.SILENT_BOOT)({
|
|
82
|
-
hass: {
|
|
83
|
-
AUTO_CONNECT_SOCKET: false,
|
|
84
|
-
AUTO_SCAN_CALL_PROXY: false,
|
|
85
|
-
BASE_URL,
|
|
86
|
-
TOKEN,
|
|
87
|
-
},
|
|
88
|
-
}));
|
|
89
63
|
});
|
|
90
64
|
it("should format callService properly", async () => {
|
|
91
65
|
expect.assertions(1);
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
66
|
+
await hassTestRunner.run(({ lifecycle, hass }) => {
|
|
67
|
+
const spy = jest.spyOn(global, "fetch").mockImplementation(async () => {
|
|
68
|
+
return {
|
|
69
|
+
text: () => "{}",
|
|
70
|
+
};
|
|
71
|
+
});
|
|
72
|
+
lifecycle.onReady(async () => {
|
|
73
|
+
await hass.fetch.callService("switch.toggle", {
|
|
74
|
+
entity_id: "switch.porch_light",
|
|
75
|
+
});
|
|
76
|
+
expect(spy).toHaveBeenCalledWith(`${BASE_URL}/api/services/switch/toggle`, expect.objectContaining({
|
|
77
|
+
body: JSON.stringify({
|
|
103
78
|
entity_id: "switch.porch_light",
|
|
104
|
-
})
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
}),
|
|
109
|
-
method: "post",
|
|
110
|
-
}));
|
|
111
|
-
});
|
|
112
|
-
},
|
|
79
|
+
}),
|
|
80
|
+
method: "post",
|
|
81
|
+
}));
|
|
82
|
+
});
|
|
113
83
|
});
|
|
114
|
-
await application.bootstrap((0, utils_1.SILENT_BOOT)({
|
|
115
|
-
hass: {
|
|
116
|
-
AUTO_CONNECT_SOCKET: false,
|
|
117
|
-
AUTO_SCAN_CALL_PROXY: false,
|
|
118
|
-
BASE_URL,
|
|
119
|
-
TOKEN,
|
|
120
|
-
},
|
|
121
|
-
}));
|
|
122
84
|
});
|
|
123
85
|
it("should format checkConfig properly", async () => {
|
|
124
86
|
expect.assertions(1);
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
}
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
method: "post",
|
|
138
|
-
}));
|
|
139
|
-
});
|
|
140
|
-
},
|
|
87
|
+
await hassTestRunner.run(({ lifecycle, hass }) => {
|
|
88
|
+
const spy = jest.spyOn(global, "fetch").mockImplementation(async () => {
|
|
89
|
+
return {
|
|
90
|
+
text: () => "{}",
|
|
91
|
+
};
|
|
92
|
+
});
|
|
93
|
+
lifecycle.onReady(async () => {
|
|
94
|
+
await hass.fetch.checkConfig();
|
|
95
|
+
expect(spy).toHaveBeenCalledWith(`${BASE_URL}/api/config/core/check_config`, expect.objectContaining({
|
|
96
|
+
method: "post",
|
|
97
|
+
}));
|
|
98
|
+
});
|
|
141
99
|
});
|
|
142
|
-
await application.bootstrap((0, utils_1.SILENT_BOOT)({
|
|
143
|
-
hass: {
|
|
144
|
-
AUTO_CONNECT_SOCKET: false,
|
|
145
|
-
AUTO_SCAN_CALL_PROXY: false,
|
|
146
|
-
BASE_URL,
|
|
147
|
-
TOKEN,
|
|
148
|
-
},
|
|
149
|
-
}));
|
|
150
100
|
});
|
|
151
|
-
// TODO:
|
|
152
|
-
|
|
101
|
+
// TODO: this results in an open handle
|
|
102
|
+
// not sure why
|
|
103
|
+
xit("exits for low version at boot", async () => {
|
|
153
104
|
expect.assertions(2);
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
.spyOn(hass.fetch, "getConfig")
|
|
160
|
-
.mockImplementation(async () => ({ version: "2024.1.0" }));
|
|
161
|
-
exitSpy = jest.spyOn(process, "exit").mockImplementation(() => {
|
|
162
|
-
throw new Error("EXPECTED TESTING ERROR");
|
|
163
|
-
});
|
|
164
|
-
},
|
|
165
|
-
});
|
|
105
|
+
const exitSpy = jest.spyOn(process, "exit");
|
|
106
|
+
// .mockImplementation(() => {
|
|
107
|
+
// throw new Error("EXPECTED TESTING ERROR");
|
|
108
|
+
// });
|
|
109
|
+
jest.spyOn(console, "error").mockImplementation(() => undefined);
|
|
166
110
|
try {
|
|
167
|
-
await
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
TOKEN,
|
|
173
|
-
},
|
|
174
|
-
}));
|
|
111
|
+
await hassTestRunner.run(({ lifecycle, mock_assistant }) => {
|
|
112
|
+
lifecycle.onPreInit(() => {
|
|
113
|
+
mock_assistant.config.loadFixtures({ version: "2024.1.0" });
|
|
114
|
+
}, -1000);
|
|
115
|
+
});
|
|
175
116
|
}
|
|
176
|
-
|
|
177
|
-
expect(
|
|
178
|
-
expect(exitSpy).toHaveBeenCalled();
|
|
117
|
+
catch (error) {
|
|
118
|
+
expect(error).toBeDefined();
|
|
179
119
|
}
|
|
120
|
+
await hassTestRunner.teardown();
|
|
121
|
+
expect(exitSpy).toHaveBeenCalled();
|
|
180
122
|
});
|
|
181
123
|
// TODO: Need a way to make this pass without breaking all other tests
|
|
182
124
|
it.skip("passes for valid version", async () => {
|
|
183
125
|
expect.assertions(2);
|
|
184
126
|
let mock;
|
|
185
127
|
let exitSpy;
|
|
186
|
-
|
|
187
|
-
|
|
128
|
+
try {
|
|
129
|
+
await hassTestRunner.run(({ hass }) => {
|
|
188
130
|
mock = jest
|
|
189
131
|
.spyOn(hass.fetch, "getConfig")
|
|
190
132
|
.mockImplementation(async () => ({ version: "2024.4.1" }));
|
|
191
133
|
exitSpy = jest.spyOn(process, "exit").mockImplementation(() => {
|
|
192
134
|
throw new Error("EXPECTED TESTING ERROR");
|
|
193
135
|
});
|
|
194
|
-
}
|
|
195
|
-
});
|
|
196
|
-
try {
|
|
197
|
-
await application.bootstrap((0, utils_1.SILENT_BOOT)({
|
|
198
|
-
hass: {
|
|
199
|
-
AUTO_CONNECT_SOCKET: false,
|
|
200
|
-
AUTO_SCAN_CALL_PROXY: false,
|
|
201
|
-
BASE_URL,
|
|
202
|
-
TOKEN,
|
|
203
|
-
},
|
|
204
|
-
}));
|
|
136
|
+
});
|
|
205
137
|
}
|
|
206
138
|
finally {
|
|
207
139
|
expect(mock).toHaveBeenCalled();
|
|
@@ -210,326 +142,209 @@ describe("FetchAPI", () => {
|
|
|
210
142
|
});
|
|
211
143
|
it("should format fetchEntityCustomizations properly", async () => {
|
|
212
144
|
expect.assertions(1);
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
}
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
method: "get",
|
|
226
|
-
}));
|
|
227
|
-
});
|
|
228
|
-
},
|
|
145
|
+
await hassTestRunner.run(({ lifecycle, hass }) => {
|
|
146
|
+
const spy = jest.spyOn(global, "fetch").mockImplementation(async () => {
|
|
147
|
+
return {
|
|
148
|
+
text: () => "{}",
|
|
149
|
+
};
|
|
150
|
+
});
|
|
151
|
+
lifecycle.onReady(async () => {
|
|
152
|
+
await hass.fetch.fetchEntityCustomizations("switch.porch_light");
|
|
153
|
+
expect(spy).toHaveBeenCalledWith(`${BASE_URL}/api/config/customize/config/switch.porch_light`, expect.objectContaining({
|
|
154
|
+
method: "get",
|
|
155
|
+
}));
|
|
156
|
+
});
|
|
229
157
|
});
|
|
230
|
-
await application.bootstrap((0, utils_1.SILENT_BOOT)({
|
|
231
|
-
hass: {
|
|
232
|
-
AUTO_CONNECT_SOCKET: false,
|
|
233
|
-
AUTO_SCAN_CALL_PROXY: false,
|
|
234
|
-
BASE_URL,
|
|
235
|
-
TOKEN,
|
|
236
|
-
},
|
|
237
|
-
}));
|
|
238
158
|
});
|
|
239
159
|
it("should format fetchEntityHistory properly", async () => {
|
|
240
160
|
expect.assertions(1);
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
})
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
method: "get",
|
|
254
|
-
}));
|
|
255
|
-
});
|
|
256
|
-
},
|
|
161
|
+
await hassTestRunner.run(({ lifecycle, hass }) => {
|
|
162
|
+
const spy = jest.spyOn(global, "fetch").mockImplementation(async () => {
|
|
163
|
+
return {
|
|
164
|
+
text: () => "{}",
|
|
165
|
+
};
|
|
166
|
+
});
|
|
167
|
+
lifecycle.onReady(async () => {
|
|
168
|
+
await hass.fetch.fetchEntityHistory("switch.porch_light", start, end);
|
|
169
|
+
expect(spy).toHaveBeenCalledWith(`${BASE_URL}/api/history/period/${encodeURIComponent(start.toISOString())}?end_time=${encodeURIComponent(end.toISOString())}&filter_entity_id=switch.porch_light`, expect.objectContaining({
|
|
170
|
+
method: "get",
|
|
171
|
+
}));
|
|
172
|
+
});
|
|
257
173
|
});
|
|
258
|
-
await application.bootstrap((0, utils_1.SILENT_BOOT)({
|
|
259
|
-
hass: {
|
|
260
|
-
AUTO_CONNECT_SOCKET: false,
|
|
261
|
-
AUTO_SCAN_CALL_PROXY: false,
|
|
262
|
-
BASE_URL,
|
|
263
|
-
TOKEN,
|
|
264
|
-
},
|
|
265
|
-
}));
|
|
266
174
|
});
|
|
267
175
|
it("should format fireEvent properly", async () => {
|
|
268
176
|
expect.assertions(1);
|
|
269
177
|
const body = { magic: true };
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
}
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
method: "post",
|
|
284
|
-
}));
|
|
285
|
-
});
|
|
286
|
-
},
|
|
178
|
+
await hassTestRunner.run(({ lifecycle, hass }) => {
|
|
179
|
+
const spy = jest.spyOn(global, "fetch").mockImplementation(async () => {
|
|
180
|
+
return {
|
|
181
|
+
text: () => "{}",
|
|
182
|
+
};
|
|
183
|
+
});
|
|
184
|
+
lifecycle.onReady(async () => {
|
|
185
|
+
await hass.fetch.fireEvent("testing_event", body);
|
|
186
|
+
expect(spy).toHaveBeenCalledWith(`${BASE_URL}/api/events/testing_event`, expect.objectContaining({
|
|
187
|
+
body: JSON.stringify(body),
|
|
188
|
+
method: "post",
|
|
189
|
+
}));
|
|
190
|
+
});
|
|
287
191
|
});
|
|
288
|
-
await application.bootstrap((0, utils_1.SILENT_BOOT)({
|
|
289
|
-
hass: {
|
|
290
|
-
AUTO_CONNECT_SOCKET: false,
|
|
291
|
-
AUTO_SCAN_CALL_PROXY: false,
|
|
292
|
-
BASE_URL,
|
|
293
|
-
TOKEN,
|
|
294
|
-
},
|
|
295
|
-
}));
|
|
296
192
|
});
|
|
297
193
|
it("should format getAllEntities properly", async () => {
|
|
298
194
|
expect.assertions(1);
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
};
|
|
307
|
-
});
|
|
308
|
-
lifecycle.onReady(async () => {
|
|
309
|
-
await hass.fetch.getAllEntities();
|
|
310
|
-
expect(spy).toHaveBeenCalledWith(`${BASE_URL}/api/states`, expect.objectContaining({
|
|
311
|
-
method: "get",
|
|
312
|
-
}));
|
|
313
|
-
});
|
|
314
|
-
},
|
|
195
|
+
await hassTestRunner.run(({ lifecycle, hass, mock_assistant }) => {
|
|
196
|
+
lifecycle.onReady(async () => {
|
|
197
|
+
mock_assistant.entity.monkeyReset();
|
|
198
|
+
const spy = jest.spyOn(hass.fetch, "fetch").mockImplementation(async () => []);
|
|
199
|
+
await hass.fetch.getAllEntities();
|
|
200
|
+
expect(spy).toHaveBeenCalledWith({ url: "/api/states" });
|
|
201
|
+
});
|
|
315
202
|
});
|
|
316
|
-
await application.bootstrap((0, utils_1.SILENT_BOOT)({
|
|
317
|
-
hass: {
|
|
318
|
-
AUTO_CONNECT_SOCKET: false,
|
|
319
|
-
AUTO_SCAN_CALL_PROXY: false,
|
|
320
|
-
BASE_URL,
|
|
321
|
-
TOKEN,
|
|
322
|
-
},
|
|
323
|
-
}));
|
|
324
|
-
});
|
|
325
|
-
it("should format getHassConfig properly", async () => {
|
|
326
|
-
expect.assertions(1);
|
|
327
|
-
application = (0, utils_1.CreateTestingApplication)({
|
|
328
|
-
Test({ lifecycle, hass }) {
|
|
329
|
-
const spy = jest
|
|
330
|
-
.spyOn(global, "fetch")
|
|
331
|
-
.mockImplementation(async () => {
|
|
332
|
-
return {
|
|
333
|
-
text: () => "{}",
|
|
334
|
-
};
|
|
335
|
-
});
|
|
336
|
-
lifecycle.onReady(async () => {
|
|
337
|
-
await hass.fetch.getConfig();
|
|
338
|
-
expect(spy).toHaveBeenCalledWith(`${BASE_URL}/api/config`, expect.objectContaining({
|
|
339
|
-
method: "get",
|
|
340
|
-
}));
|
|
341
|
-
});
|
|
342
|
-
},
|
|
343
|
-
});
|
|
344
|
-
await application.bootstrap((0, utils_1.SILENT_BOOT)({
|
|
345
|
-
hass: {
|
|
346
|
-
AUTO_CONNECT_SOCKET: false,
|
|
347
|
-
AUTO_SCAN_CALL_PROXY: false,
|
|
348
|
-
BASE_URL,
|
|
349
|
-
TOKEN,
|
|
350
|
-
},
|
|
351
|
-
}, false, false));
|
|
352
203
|
});
|
|
204
|
+
// it("should format getHassConfig properly", async () => {
|
|
205
|
+
// expect.assertions(1);
|
|
206
|
+
// application = CreateTestingApplication({
|
|
207
|
+
// Test({ lifecycle, hass }: TServiceParams) {
|
|
208
|
+
// const spy = jest.spyOn(global, "fetch").mockImplementation(async () => {
|
|
209
|
+
// return {
|
|
210
|
+
// text: () => "{}",
|
|
211
|
+
// } as unknown as Response;
|
|
212
|
+
// });
|
|
213
|
+
// lifecycle.onReady(async () => {
|
|
214
|
+
// await hass.fetch.getConfig();
|
|
215
|
+
// expect(spy).toHaveBeenCalledWith(
|
|
216
|
+
// `${BASE_URL}/api/config`,
|
|
217
|
+
// expect.objectContaining({
|
|
218
|
+
// method: "get",
|
|
219
|
+
// }),
|
|
220
|
+
// );
|
|
221
|
+
// });
|
|
222
|
+
// },
|
|
223
|
+
// });
|
|
224
|
+
// await application.bootstrap(
|
|
225
|
+
// SILENT_BOOT(
|
|
226
|
+
// {
|
|
227
|
+
// hass: {
|
|
228
|
+
// AUTO_CONNECT_SOCKET: false,
|
|
229
|
+
// AUTO_SCAN_CALL_PROXY: false,
|
|
230
|
+
// BASE_URL,
|
|
231
|
+
// TOKEN,
|
|
232
|
+
// },
|
|
233
|
+
// },
|
|
234
|
+
// false,
|
|
235
|
+
// false,
|
|
236
|
+
// ),
|
|
237
|
+
// );
|
|
238
|
+
// });
|
|
353
239
|
it("should format getLogs properly", async () => {
|
|
354
240
|
expect.assertions(1);
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
}
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
method: "get",
|
|
368
|
-
}));
|
|
369
|
-
});
|
|
370
|
-
},
|
|
241
|
+
await hassTestRunner.run(({ lifecycle, hass }) => {
|
|
242
|
+
const spy = jest.spyOn(global, "fetch").mockImplementation(async () => {
|
|
243
|
+
return {
|
|
244
|
+
text: () => "[]",
|
|
245
|
+
};
|
|
246
|
+
});
|
|
247
|
+
lifecycle.onReady(async () => {
|
|
248
|
+
await hass.fetch.getLogs();
|
|
249
|
+
expect(spy).toHaveBeenCalledWith(`${BASE_URL}/api/error/all`, expect.objectContaining({
|
|
250
|
+
method: "get",
|
|
251
|
+
}));
|
|
252
|
+
});
|
|
371
253
|
});
|
|
372
|
-
await application.bootstrap((0, utils_1.SILENT_BOOT)({
|
|
373
|
-
hass: {
|
|
374
|
-
AUTO_CONNECT_SOCKET: false,
|
|
375
|
-
AUTO_SCAN_CALL_PROXY: false,
|
|
376
|
-
BASE_URL,
|
|
377
|
-
TOKEN,
|
|
378
|
-
},
|
|
379
|
-
}));
|
|
380
254
|
});
|
|
381
255
|
it("should format getRawLogs properly", async () => {
|
|
382
256
|
expect.assertions(1);
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
}
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
method: "get",
|
|
396
|
-
}));
|
|
397
|
-
});
|
|
398
|
-
},
|
|
257
|
+
await hassTestRunner.run(({ lifecycle, hass }) => {
|
|
258
|
+
const spy = jest.spyOn(global, "fetch").mockImplementation(async () => {
|
|
259
|
+
return {
|
|
260
|
+
text: () => "{}",
|
|
261
|
+
};
|
|
262
|
+
});
|
|
263
|
+
lifecycle.onReady(async () => {
|
|
264
|
+
await hass.fetch.getRawLogs();
|
|
265
|
+
expect(spy).toHaveBeenCalledWith(`${BASE_URL}/api/error_log`, expect.objectContaining({
|
|
266
|
+
method: "get",
|
|
267
|
+
}));
|
|
268
|
+
});
|
|
399
269
|
});
|
|
400
|
-
await application.bootstrap((0, utils_1.SILENT_BOOT)({
|
|
401
|
-
hass: {
|
|
402
|
-
AUTO_CONNECT_SOCKET: false,
|
|
403
|
-
AUTO_SCAN_CALL_PROXY: false,
|
|
404
|
-
BASE_URL,
|
|
405
|
-
TOKEN,
|
|
406
|
-
},
|
|
407
|
-
}));
|
|
408
270
|
});
|
|
409
271
|
it("should format listServices properly", async () => {
|
|
410
272
|
expect.assertions(1);
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
const spy = jest
|
|
414
|
-
.spyOn(global, "fetch")
|
|
415
|
-
.mockImplementation(async () => {
|
|
273
|
+
await hassTestRunner.run(({ lifecycle, hass, mock_assistant }) => {
|
|
274
|
+
lifecycle.onReady(async () => {
|
|
275
|
+
const spy = jest.spyOn(global, "fetch").mockImplementation(async () => {
|
|
416
276
|
return {
|
|
417
277
|
text: () => "{}",
|
|
418
278
|
};
|
|
419
279
|
});
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
},
|
|
280
|
+
mock_assistant.services.monkeyReset();
|
|
281
|
+
await hass.fetch.listServices();
|
|
282
|
+
expect(spy).toHaveBeenCalledWith(`${BASE_URL}/api/services`, expect.objectContaining({
|
|
283
|
+
method: "get",
|
|
284
|
+
}));
|
|
285
|
+
});
|
|
427
286
|
});
|
|
428
|
-
await application.bootstrap((0, utils_1.SILENT_BOOT)({
|
|
429
|
-
hass: {
|
|
430
|
-
AUTO_CONNECT_SOCKET: false,
|
|
431
|
-
AUTO_SCAN_CALL_PROXY: false,
|
|
432
|
-
BASE_URL,
|
|
433
|
-
TOKEN,
|
|
434
|
-
},
|
|
435
|
-
}));
|
|
436
287
|
});
|
|
437
288
|
it("should format updateEntity properly", async () => {
|
|
438
289
|
expect.assertions(1);
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
290
|
+
await hassTestRunner.run(({ lifecycle, hass }) => {
|
|
291
|
+
const spy = jest.spyOn(global, "fetch").mockImplementation(async () => {
|
|
292
|
+
return {
|
|
293
|
+
text: () => "{}",
|
|
294
|
+
};
|
|
295
|
+
});
|
|
296
|
+
lifecycle.onReady(async () => {
|
|
297
|
+
await hass.fetch.updateEntity("switch.porch_light", {
|
|
298
|
+
attributes: { something: "special" },
|
|
299
|
+
state: "off",
|
|
300
|
+
});
|
|
301
|
+
expect(spy).toHaveBeenCalledWith(`${BASE_URL}/api/states/switch.porch_light`, expect.objectContaining({
|
|
302
|
+
body: JSON.stringify({
|
|
303
|
+
// ! DO NOT CHANGE ORDER OF KEYS
|
|
304
|
+
// It changes the resulting JSON, breaking the test
|
|
450
305
|
attributes: { something: "special" },
|
|
451
306
|
state: "off",
|
|
452
|
-
})
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
// It changes the resulting JSON, breaking the test
|
|
457
|
-
attributes: { something: "special" },
|
|
458
|
-
state: "off",
|
|
459
|
-
}),
|
|
460
|
-
method: "post",
|
|
461
|
-
}));
|
|
462
|
-
});
|
|
463
|
-
},
|
|
307
|
+
}),
|
|
308
|
+
method: "post",
|
|
309
|
+
}));
|
|
310
|
+
});
|
|
464
311
|
});
|
|
465
|
-
await application.bootstrap((0, utils_1.SILENT_BOOT)({
|
|
466
|
-
hass: {
|
|
467
|
-
AUTO_CONNECT_SOCKET: false,
|
|
468
|
-
AUTO_SCAN_CALL_PROXY: false,
|
|
469
|
-
BASE_URL,
|
|
470
|
-
TOKEN,
|
|
471
|
-
},
|
|
472
|
-
}));
|
|
473
312
|
});
|
|
474
313
|
it("should format webhook properly", async () => {
|
|
475
314
|
expect.assertions(1);
|
|
476
315
|
const body = {
|
|
477
316
|
magic: true,
|
|
478
317
|
};
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
}
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
method: "post",
|
|
493
|
-
}));
|
|
494
|
-
});
|
|
495
|
-
},
|
|
318
|
+
await hassTestRunner.run(({ lifecycle, hass }) => {
|
|
319
|
+
const spy = jest.spyOn(global, "fetch").mockImplementation(async () => {
|
|
320
|
+
return {
|
|
321
|
+
text: () => "{}",
|
|
322
|
+
};
|
|
323
|
+
});
|
|
324
|
+
lifecycle.onReady(async () => {
|
|
325
|
+
await hass.fetch.webhook("magic_webhook", body);
|
|
326
|
+
expect(spy).toHaveBeenCalledWith(`${BASE_URL}/api/webhook/magic_webhook`, expect.objectContaining({
|
|
327
|
+
body: JSON.stringify(body),
|
|
328
|
+
method: "post",
|
|
329
|
+
}));
|
|
330
|
+
});
|
|
496
331
|
});
|
|
497
|
-
await application.bootstrap((0, utils_1.SILENT_BOOT)({
|
|
498
|
-
hass: {
|
|
499
|
-
AUTO_CONNECT_SOCKET: false,
|
|
500
|
-
AUTO_SCAN_CALL_PROXY: false,
|
|
501
|
-
BASE_URL,
|
|
502
|
-
TOKEN,
|
|
503
|
-
},
|
|
504
|
-
}));
|
|
505
332
|
});
|
|
506
333
|
it("should format checkCredentials properly", async () => {
|
|
507
334
|
expect.assertions(1);
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
}
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
method: "get",
|
|
521
|
-
}));
|
|
522
|
-
});
|
|
523
|
-
},
|
|
335
|
+
await hassTestRunner.run(({ lifecycle, hass }) => {
|
|
336
|
+
const spy = jest.spyOn(global, "fetch").mockImplementation(async () => {
|
|
337
|
+
return {
|
|
338
|
+
text: () => "{}",
|
|
339
|
+
};
|
|
340
|
+
});
|
|
341
|
+
lifecycle.onReady(async () => {
|
|
342
|
+
await hass.fetch.checkCredentials();
|
|
343
|
+
expect(spy).toHaveBeenCalledWith(`${BASE_URL}/api/`, expect.objectContaining({
|
|
344
|
+
method: "get",
|
|
345
|
+
}));
|
|
346
|
+
});
|
|
524
347
|
});
|
|
525
|
-
await application.bootstrap((0, utils_1.SILENT_BOOT)({
|
|
526
|
-
hass: {
|
|
527
|
-
AUTO_CONNECT_SOCKET: false,
|
|
528
|
-
AUTO_SCAN_CALL_PROXY: false,
|
|
529
|
-
BASE_URL,
|
|
530
|
-
TOKEN,
|
|
531
|
-
},
|
|
532
|
-
}));
|
|
533
348
|
});
|
|
534
349
|
});
|
|
535
350
|
});
|