@kohost/api-client 1.0.0-alpha.2 → 1.0.0-alpha.4

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.
Files changed (115) hide show
  1. package/.eslintrc.js +10 -0
  2. package/bitbucket-pipelines.yml +39 -0
  3. package/commands/Command.js +38 -0
  4. package/commands/DiscoverUsersCommand.js +21 -0
  5. package/commands/SetAlarmCommand.js +21 -0
  6. package/commands/SetCourtesyCommand.js +21 -0
  7. package/commands/SetDimmerCommand.js +21 -0
  8. package/commands/SetLockCommand.js +21 -0
  9. package/commands/SetSceneControllerCommand.js +21 -0
  10. package/commands/SetSwitchCommand.js +21 -0
  11. package/commands/SetThermostatCommand.js +21 -0
  12. package/commands/SetWindowCoveringCommand.js +21 -0
  13. package/commands/VerifyDocumentCommand.js +24 -0
  14. package/commands/index.js +25 -0
  15. package/defs/deviceTypes.js +15 -0
  16. package/defs/formalDeviceTypes.js +6 -0
  17. package/defs/http.js +7 -0
  18. package/defs/index.js +11 -0
  19. package/errors/AppError.js +8 -0
  20. package/errors/AuthenticationError.js +9 -0
  21. package/errors/AuthorizationError.js +9 -0
  22. package/errors/DeviceCommError.js +9 -0
  23. package/errors/LoginError.js +9 -0
  24. package/errors/NotFoundError.js +9 -0
  25. package/errors/RequestError.js +9 -0
  26. package/errors/SystemCommError.js +9 -0
  27. package/errors/TokenExpiredError.js +9 -0
  28. package/errors/UnprocessableRequestError.js +9 -0
  29. package/errors/ValidationError.js +9 -0
  30. package/errors/index.js +15 -0
  31. package/events/Event.js +33 -0
  32. package/events/SystemCameraUpdatedEvent.js +17 -0
  33. package/events/SystemCourtesyUpdatedEvent.js +17 -0
  34. package/events/SystemDimmerUpdatedEvent.js +17 -0
  35. package/events/SystemLockUpdatedEvent.js +17 -0
  36. package/events/SystemReservationUpdatedEvent.js +17 -0
  37. package/events/SystemSceneControllerUpdatedEvent.js +17 -0
  38. package/events/SystemSourceUpdatedEvent.js +17 -0
  39. package/events/SystemSpaceUpdatedEvent.js +17 -0
  40. package/events/SystemSwitchUpdatedEvent.js +17 -0
  41. package/events/SystemThermostatUpdatedEvent.js +17 -0
  42. package/events/SystemUserUpdatedEvent.js +17 -0
  43. package/events/SystemWindowCoveringUpdatedEvent.js +17 -0
  44. package/events/index.js +28 -0
  45. package/http/handleResponseError.js +53 -0
  46. package/http/handleResponseSuccess.js +15 -0
  47. package/http/index.js +165 -0
  48. package/index.js +19 -2
  49. package/models/acl.js +29 -0
  50. package/models/admin/customer.js +28 -0
  51. package/models/admin/property.js +28 -0
  52. package/models/alarm.js +25 -3
  53. package/models/application.js +28 -0
  54. package/models/camera.js +29 -0
  55. package/models/courtesy.js +29 -3
  56. package/models/dimmer.js +45 -3
  57. package/models/discoveredDevice.js +30 -0
  58. package/models/gateway.js +33 -3
  59. package/models/index.js +38 -1
  60. package/models/integration.js +76 -0
  61. package/models/iotGateway.js +29 -0
  62. package/models/kohost.js +95 -0
  63. package/models/lock.js +29 -3
  64. package/models/mediaSource.js +29 -0
  65. package/models/motionSensor.js +29 -0
  66. package/models/reservation.js +36 -0
  67. package/models/room.js +185 -0
  68. package/models/scene.js +28 -0
  69. package/models/sceneController.js +24 -5
  70. package/models/space.js +99 -0
  71. package/models/switch.js +29 -3
  72. package/models/thermostat.js +71 -31
  73. package/models/ticket.js +91 -0
  74. package/models/user.js +58 -0
  75. package/models/windowCovering.js +44 -5
  76. package/package.json +30 -7
  77. package/prepare.js +4 -0
  78. package/schemas/acl.json +111 -0
  79. package/schemas/admin/customer.json +32 -0
  80. package/schemas/admin/property.json +174 -0
  81. package/schemas/alarm.json +5 -5
  82. package/schemas/application.json +24 -0
  83. package/schemas/camera.json +41 -0
  84. package/schemas/courtesy.json +5 -6
  85. package/schemas/definitions/common.json +21 -0
  86. package/schemas/definitions/device.json +21 -3
  87. package/schemas/dimmer.json +8 -5
  88. package/schemas/discoveredDevice.json +43 -0
  89. package/schemas/gateway.json +45 -13
  90. package/schemas/identification.json +35 -0
  91. package/schemas/integration.json +94 -0
  92. package/schemas/iotGateway.json +29 -0
  93. package/schemas/lock.json +8 -5
  94. package/schemas/mediaSource.json +151 -0
  95. package/schemas/motionSensor.json +26 -0
  96. package/schemas/payment.json +38 -0
  97. package/schemas/reservation.json +66 -0
  98. package/schemas/room.json +138 -0
  99. package/schemas/scene.json +118 -0
  100. package/schemas/sceneController.json +9 -9
  101. package/schemas/space.json +111 -0
  102. package/schemas/switch.json +8 -5
  103. package/schemas/thermostat.json +19 -10
  104. package/schemas/ticket.json +82 -0
  105. package/schemas/user.json +124 -0
  106. package/schemas/windowCovering.json +8 -5
  107. package/tests/unit/models/space.test.js +31 -0
  108. package/tests/unit/models/thermostat.test.js +146 -0
  109. package/tests/unit/models/user.test.js +28 -0
  110. package/useCases/http.json +1098 -0
  111. package/utils/getDeviceTypes.js +7 -0
  112. package/utils/getFormalDeviceType.js +5 -0
  113. package/utils/schema.js +28 -0
  114. package/vite.config.js +22 -0
  115. package/utils/compiler.js +0 -40
@@ -0,0 +1,111 @@
1
+ {
2
+ "$schema": "http://json-schema.org/draft-07/schema",
3
+ "$id": "https://api.kohost.app/schemas/v3/space.json",
4
+ "title": "Space",
5
+ "type": "object",
6
+ "properties": {
7
+ "id": {
8
+ "$ref": "https://api.kohost.app/schemas/v3/definitions/common.json#/definitions/id"
9
+ },
10
+ "name": {
11
+ "type": "string",
12
+ "minLength": 1
13
+ },
14
+ "type": {
15
+ "type": ["string"],
16
+ "enum": [
17
+ "classRoom",
18
+ "hotelRoom",
19
+ "office",
20
+ "building",
21
+ "commonArea",
22
+ "other"
23
+ ]
24
+ },
25
+ "rooms": {
26
+ "type": "array",
27
+ "items": {
28
+ "type": "string"
29
+ }
30
+ },
31
+ "subGroups": {
32
+ "type": "array",
33
+ "items": {
34
+ "type": "string"
35
+ }
36
+ },
37
+ "eco": {
38
+ "type": "object",
39
+ "additionalProperties": false,
40
+ "default": {
41
+ "active": false,
42
+ "allowed": false
43
+ },
44
+ "properties": {
45
+ "active": {
46
+ "type": "boolean",
47
+ "default": false
48
+ },
49
+ "activatedAt": {
50
+ "type": "string",
51
+ "format": "date-time"
52
+ },
53
+ "allowed": {
54
+ "type": "boolean",
55
+ "default": false
56
+ }
57
+ }
58
+ },
59
+ "features": {
60
+ "type": "array",
61
+ "items": {
62
+ "type": "string"
63
+ }
64
+ },
65
+ "maximumOccupancy": {
66
+ "type": "number",
67
+ "minimum": 1
68
+ },
69
+ "housekeepingStatus": {
70
+ "type": "string",
71
+ "enum": ["clean", "dirty", "inspected", "pickup"]
72
+ },
73
+ "serviceStatus": {
74
+ "type": "string",
75
+ "enum": ["inService", "outOfOrder", "outOfService"]
76
+ },
77
+ "systemData": {
78
+ "$ref": "https://api.kohost.app/schemas/v3/definitions/common.json#/definitions/systemData"
79
+ }
80
+ },
81
+ "if": {
82
+ "properties": { "type": { "const": "hotelRoom" } }
83
+ },
84
+ "then": {
85
+ "required": [
86
+ "name",
87
+ "type",
88
+ "features",
89
+ "maximumOccupancy",
90
+ "housekeepingStatus",
91
+ "serviceStatus"
92
+ ],
93
+ "properties": {
94
+ "features": {
95
+ "default": []
96
+ },
97
+ "maximumOccupancy": {
98
+ "default": 2
99
+ },
100
+ "housekeepingStatus": {
101
+ "default": "dirty"
102
+ },
103
+ "serviceStatus": {
104
+ "default": "inService"
105
+ }
106
+ }
107
+ },
108
+ "else": {
109
+ "required": ["name", "type"]
110
+ }
111
+ }
@@ -6,19 +6,22 @@
6
6
  "type": "object",
7
7
  "properties": {
8
8
  "id": {
9
- "$ref": "https://api.kohost.app/schemas/v3/device.json#/definitions/id"
9
+ "$ref": "https://api.kohost.app/schemas/v3/definitions/device.json#/definitions/id"
10
10
  },
11
11
  "type": {
12
- "$ref": "https://api.kohost.app/schemas/v3/device.json#/definitions/type"
12
+ "$ref": "https://api.kohost.app/schemas/v3/definitions/device.json#/definitions/type"
13
+ },
14
+ "subType": {
15
+ "$ref": "https://api.kohost.app/schemas/v3/definitions/device.json#/definitions/subType"
13
16
  },
14
17
  "systemData": {
15
- "$ref": "https://api.kohost.app/schemas/v3/device.json#/definitions/systemData"
18
+ "$ref": "https://api.kohost.app/schemas/v3/definitions/device.json#/definitions/systemData"
16
19
  },
17
20
  "supportedNotifications": {
18
- "$ref": "https://api.kohost.app/schemas/v3/device.json#/definitions/supportedNotifications"
21
+ "$ref": "https://api.kohost.app/schemas/v3/definitions/device.json#/definitions/supportedNotifications"
19
22
  },
20
23
  "notification": {
21
- "$ref": "https://api.kohost.app/schemas/v3/device.json#/definitions/notification"
24
+ "$ref": "https://api.kohost.app/schemas/v3/definitions/device.json#/definitions/notification"
22
25
  },
23
26
  "state": {
24
27
  "type": "string",
@@ -6,27 +6,35 @@
6
6
  "type": "object",
7
7
  "properties": {
8
8
  "id": {
9
- "$ref": "https://api.kohost.app/schemas/v3/device.json#/definitions/id"
9
+ "$ref": "https://api.kohost.app/schemas/v3/definitions/device.json#/definitions/id"
10
+ },
11
+ "name": {
12
+ "$ref": "https://api.kohost.app/schemas/v3/definitions/device.json#/definitions/name"
10
13
  },
11
14
  "type": {
12
- "$ref": "https://api.kohost.app/schemas/v3/device.json#/definitions/type"
15
+ "$ref": "https://api.kohost.app/schemas/v3/definitions/device.json#/definitions/type",
16
+ "default": "thermostat"
17
+ },
18
+ "subType": {
19
+ "$ref": "https://api.kohost.app/schemas/v3/definitions/device.json#/definitions/subType"
13
20
  },
14
21
  "systemData": {
15
- "$ref": "https://api.kohost.app/schemas/v3/device.json#/definitions/systemData"
22
+ "$ref": "https://api.kohost.app/schemas/v3/definitions/device.json#/definitions/systemData",
23
+ "default": {}
16
24
  },
17
25
  "supportedNotifications": {
18
- "$ref": "https://api.kohost.app/schemas/v3/device.json#/definitions/supportedNotifications"
26
+ "$ref": "https://api.kohost.app/schemas/v3/definitions/device.json#/definitions/supportedNotifications"
19
27
  },
20
28
  "notification": {
21
- "$ref": "https://api.kohost.app/schemas/v3/device.json#/definitions/notification"
29
+ "$ref": "https://api.kohost.app/schemas/v3/definitions/device.json#/definitions/notification"
22
30
  },
23
31
  "currentTemperature": {
24
32
  "type": "number",
25
33
  "minimum": 0,
26
- "maximum": 99
34
+ "maximum": 130
27
35
  },
28
36
  "currentHumidity": {
29
- "type": "number",
37
+ "type": ["number", "null"],
30
38
  "minimum": 0,
31
39
  "maximum": 99
32
40
  },
@@ -48,11 +56,12 @@
48
56
  },
49
57
  "temperatureScale": {
50
58
  "type": "string",
51
- "enum": ["celcius", "farenheit"]
59
+ "enum": ["celsius", "fahrenheit"],
60
+ "default": "fahrenheit"
52
61
  },
53
62
  "humidityScale": {
54
- "type": "string",
55
- "enum": ["absolute", "relative"]
63
+ "type": ["string", "null"],
64
+ "enum": ["absolute", "relative", null]
56
65
  },
57
66
  "supportedHvacModes": {
58
67
  "type": "array",
@@ -0,0 +1,82 @@
1
+ {
2
+ "$schema": "http://json-schema.org/draft-07/schema",
3
+ "$id": "https://api.kohost.app/schemas/v3/ticket.json",
4
+ "title": "Ticket",
5
+ "description": "A ticket is a request for help from a user.",
6
+ "type": "object",
7
+ "properties": {
8
+ "id": {
9
+ "$ref": "https://api.kohost.app/schemas/v3/definitions/common.json#/definitions/id"
10
+ },
11
+ "conversation": {
12
+ "type": "array",
13
+ "default": [],
14
+ "items": {
15
+ "type": "object",
16
+ "additionalProperties": false,
17
+ "properties": {
18
+ "id": {
19
+ "type": "string"
20
+ },
21
+ "user": {
22
+ "type": "string"
23
+ },
24
+ "timestamp": {
25
+ "$ref": "https://api.kohost.app/schemas/v3/definitions/common.json#/definitions/createdAt"
26
+ },
27
+ "body": {
28
+ "type": "string"
29
+ },
30
+ "readBy": {
31
+ "type": "array",
32
+ "default": [],
33
+ "items": {
34
+ "type": "string"
35
+ }
36
+ }
37
+ },
38
+ "required": ["user", "id", "timestamp", "body"]
39
+ }
40
+ },
41
+ "requester": {
42
+ "type": "string"
43
+ },
44
+ "assignedTo": {
45
+ "type": ["string", "null"]
46
+ },
47
+ "status": {
48
+ "type": "string",
49
+ "enum": ["open", "pending", "solved", "closed"],
50
+ "default": "open"
51
+ },
52
+ "tags": {
53
+ "type": "array",
54
+ "default": [],
55
+ "items": {
56
+ "type": "string"
57
+ }
58
+ },
59
+ "createdAt": {
60
+ "$ref": "https://api.kohost.app/schemas/v3/definitions/common.json#/definitions/createdAt"
61
+ },
62
+ "updatedAt": {
63
+ "$ref": "https://api.kohost.app/schemas/v3/definitions/common.json#/definitions/createdAt"
64
+ },
65
+ "solvedAt": {
66
+ "$ref": "https://api.kohost.app/schemas/v3/definitions/common.json#/definitions/createdAt"
67
+ },
68
+ "closedAt": {
69
+ "$ref": "https://api.kohost.app/schemas/v3/definitions/common.json#/definitions/createdAt"
70
+ }
71
+ },
72
+ "required": [
73
+ "id",
74
+ "conversation",
75
+ "requester",
76
+ "status",
77
+ "tags",
78
+ "createdAt",
79
+ "updatedAt"
80
+ ],
81
+ "additionalProperties": false
82
+ }
@@ -0,0 +1,124 @@
1
+ {
2
+ "$schema": "http://json-schema.org/draft-07/schema",
3
+ "$id": "https://api.kohost.app/schemas/v3/user.json",
4
+ "title": "User",
5
+ "type": "object",
6
+ "required": ["active", "lastName", "roles"],
7
+ "properties": {
8
+ "id": {
9
+ "$ref": "https://api.kohost.app/schemas/v3/definitions/common.json#/definitions/id"
10
+ },
11
+ "type": {
12
+ "type": "string",
13
+ "default": "user"
14
+ },
15
+ "active": {
16
+ "type": "boolean",
17
+ "default": true
18
+ },
19
+ "firstName": {
20
+ "type": "string"
21
+ },
22
+ "lastName": {
23
+ "type": "string"
24
+ },
25
+ "phone": {
26
+ "type": ["string", "null"],
27
+ "pattern": "^\\+?[0-9]{1,14}$"
28
+ },
29
+ "email": {
30
+ "type": ["string", "null"],
31
+ "format": "email"
32
+ },
33
+ "hashedPassword": {
34
+ "type": "string"
35
+ },
36
+ "photo": {
37
+ "type": "string"
38
+ },
39
+ "jobTitle": {
40
+ "type": "string"
41
+ },
42
+ "dob": {
43
+ "type": "string"
44
+ },
45
+ "gender": {
46
+ "type": "string"
47
+ },
48
+ "roles": {
49
+ "type": "array",
50
+ "items": {
51
+ "type": "string",
52
+ "enum": [
53
+ "Guest",
54
+ "Staff",
55
+ "Faculty",
56
+ "Student",
57
+ "Visitor",
58
+ "Manager",
59
+ "Administrator",
60
+ "SuperAdmin"
61
+ ]
62
+ }
63
+ },
64
+ "identifications": {
65
+ "type": "array",
66
+ "items": {
67
+ "$ref": "https://api.kohost.app/schemas/v3/identification.json"
68
+ }
69
+ },
70
+ "payments": {
71
+ "type": "array",
72
+ "items": {
73
+ "$ref": "https://api.kohost.app/schemas/v3/payment.json"
74
+ }
75
+ },
76
+ "preferences": {
77
+ "type": "object",
78
+ "additionalProperties": false,
79
+ "properties": {
80
+ "notifications": {
81
+ "type": "array",
82
+ "items": {
83
+ "type": "string"
84
+ },
85
+ "examples": [["roomControl", "marketing"]]
86
+ },
87
+ "location": {
88
+ "title": "The location Schema",
89
+ "type": "boolean",
90
+ "default": false,
91
+ "examples": [true]
92
+ }
93
+ }
94
+ },
95
+ "location": {
96
+ "type": "object",
97
+ "required": ["accuracy", "latitude", "longitude", "timestamp"],
98
+ "additionalProperties": false,
99
+ "properties": {
100
+ "accuracy": {
101
+ "type": ["number", "null"]
102
+ },
103
+ "latitude": {
104
+ "type": ["number", "null"]
105
+ },
106
+ "longitude": {
107
+ "type": ["number", "null"]
108
+ },
109
+ "timestamp": {
110
+ "type": ["number", "null"]
111
+ }
112
+ }
113
+ },
114
+ "createdAt": {
115
+ "$ref": "https://api.kohost.app/schemas/v3/definitions/common.json#/definitions/createdAt"
116
+ },
117
+ "updatedAt": {
118
+ "$ref": "https://api.kohost.app/schemas/v3/definitions/common.json#/definitions/updatedAt"
119
+ },
120
+ "systemData": {
121
+ "$ref": "https://api.kohost.app/schemas/v3/definitions/common.json#/definitions/systemData"
122
+ }
123
+ }
124
+ }
@@ -6,19 +6,22 @@
6
6
  "type": "object",
7
7
  "properties": {
8
8
  "id": {
9
- "$ref": "https://api.kohost.app/schemas/v3/device.json#/definitions/id"
9
+ "$ref": "https://api.kohost.app/schemas/v3/definitions/device.json#/definitions/id"
10
10
  },
11
11
  "type": {
12
- "$ref": "https://api.kohost.app/schemas/v3/device.json#/definitions/type"
12
+ "$ref": "https://api.kohost.app/schemas/v3/definitions/device.json#/definitions/type"
13
+ },
14
+ "subType": {
15
+ "$ref": "https://api.kohost.app/schemas/v3/definitions/device.json#/definitions/subType"
13
16
  },
14
17
  "systemData": {
15
- "$ref": "https://api.kohost.app/schemas/v3/device.json#/definitions/systemData"
18
+ "$ref": "https://api.kohost.app/schemas/v3/definitions/device.json#/definitions/systemData"
16
19
  },
17
20
  "supportedNotifications": {
18
- "$ref": "https://api.kohost.app/schemas/v3/device.json#/definitions/supportedNotifications"
21
+ "$ref": "https://api.kohost.app/schemas/v3/definitions/device.json#/definitions/supportedNotifications"
19
22
  },
20
23
  "notification": {
21
- "$ref": "https://api.kohost.app/schemas/v3/device.json#/definitions/notification"
24
+ "$ref": "https://api.kohost.app/schemas/v3/definitions/device.json#/definitions/notification"
22
25
  },
23
26
  "position": {
24
27
  "type": "number",
@@ -0,0 +1,31 @@
1
+ const Space = require("../../../models/space");
2
+
3
+ const valid = {
4
+ name: "Test Space",
5
+ };
6
+
7
+ test("throws error if invalid name provided ", () => {
8
+ const data = { ...valid };
9
+ data.name = "";
10
+ expect(() => new Space(data)).toThrow();
11
+ });
12
+
13
+ test("sets defaults based on hotelRoom type ", () => {
14
+ const data = { ...valid, type: "hotelRoom" };
15
+ const space = new Space(data);
16
+ expect(space).toHaveProperty("type", "hotelRoom");
17
+ expect(space).toHaveProperty("maximumOccupancy", 2);
18
+ expect(space).toHaveProperty("housekeepingStatus", "dirty");
19
+ expect(space).toHaveProperty("serviceStatus", "inService");
20
+ expect(space).toHaveProperty("features");
21
+ });
22
+
23
+ test("only sets defaults based on hotelRoom type ", () => {
24
+ const data = { ...valid, type: "classRoom" };
25
+ const space = new Space(data);
26
+ expect(space).not.toHaveProperty("type", "hotelRoom");
27
+ expect(space).not.toHaveProperty("maximumOccupancy");
28
+ expect(space).not.toHaveProperty("housekeepingStatus");
29
+ expect(space).not.toHaveProperty("serviceStatus");
30
+ expect(space).not.toHaveProperty("features");
31
+ });
@@ -0,0 +1,146 @@
1
+ const Thermostat = require("../../../models/thermostat");
2
+
3
+ const valid = {
4
+ id: "1",
5
+ type: "thermostat",
6
+ name: "Test Thermostat",
7
+ hvacMode: "cool",
8
+ hvacState: "off",
9
+ fanMode: "auto",
10
+ fanState: "off",
11
+ temperatureScale: "fahrenheit",
12
+ supportedHvacModes: ["cool", "heat"],
13
+ supportedFanModes: ["auto", "low"],
14
+ currentTemperature: 72,
15
+ systemData: {},
16
+ setpoints: {
17
+ cool: {
18
+ min: 60,
19
+ max: 85,
20
+ value: 72,
21
+ },
22
+ heat: {
23
+ value: 68,
24
+ min: 60,
25
+ max: 85,
26
+ },
27
+ },
28
+ };
29
+
30
+ test("Thermostat properties exist", () => {
31
+ expect(Thermostat.name).toBe("Thermostat");
32
+ expect(Thermostat.actionProperties).toBeDefined();
33
+ expect(Thermostat.actionProperties).toBeInstanceOf(Array);
34
+ expect(Thermostat.actionProperties).toEqual(
35
+ expect.arrayContaining(["hvacMode", "fanMode", "setpoints"])
36
+ );
37
+ expect(Thermostat.validProperties).toBeDefined();
38
+ });
39
+
40
+ test("Thermostat validator exists", () => {
41
+ const thermostat = new Thermostat(valid);
42
+ const validator = thermostat.validator;
43
+ expect(validator).toBeDefined();
44
+ expect(validator).toBeInstanceOf(Function);
45
+ });
46
+
47
+ test("Thermostat schema exists", () => {
48
+ const thermostat = new Thermostat(valid);
49
+ const schema = thermostat.schema;
50
+ expect(schema).toBeDefined();
51
+ expect(schema).toBeInstanceOf(Object);
52
+ });
53
+
54
+ test("throws error if missing all required properties", () => {
55
+ expect(() => new Thermostat()).toThrow();
56
+ });
57
+
58
+ test("throws error if missing any required property", () => {
59
+ const data = {
60
+ id: "1",
61
+ name: "Test Thermostat",
62
+ };
63
+ expect(() => new Thermostat(data)).toThrow();
64
+ });
65
+
66
+ test("throws error if invalid hvacMode provided ", () => {
67
+ const data = { ...valid };
68
+ data.hvacMode = "a";
69
+ expect(() => new Thermostat(data)).toThrow();
70
+ });
71
+
72
+ test("throws error if unsupported hvacMode provided ", () => {
73
+ const data = { ...valid };
74
+ data.supportedHvacModes = ["cool"];
75
+ data.hvacMode = "heat";
76
+ expect(() => new Thermostat(data)).toThrow();
77
+ });
78
+
79
+ test("throws error if invalid hvacState provided ", () => {
80
+ const data = { ...valid };
81
+ data.hvacState = "a";
82
+ expect(() => new Thermostat(data)).toThrow();
83
+ });
84
+
85
+ test("throws error if invalid temperatureScale provided ", () => {
86
+ const data = { ...valid };
87
+ data.temperatureScale = "a";
88
+ expect(() => new Thermostat(data)).toThrow();
89
+ });
90
+
91
+ test("throws error if invalid humidityScale provided ", () => {
92
+ const data = { ...valid };
93
+ data.humidityScale = "a";
94
+ expect(() => new Thermostat(data)).toThrow();
95
+ });
96
+
97
+ test("throws error if invalid fanState provided ", () => {
98
+ const data = { ...valid };
99
+ data.fanState = "a";
100
+ expect(() => new Thermostat(data)).toThrow();
101
+ });
102
+
103
+ test("throws error if currentTemperature is out of range ", () => {
104
+ const data = { ...valid };
105
+ const data2 = { ...valid };
106
+ data.currentTemperature = 131;
107
+ data2.currentTemperature = -1;
108
+ expect(() => new Thermostat(data)).toThrow();
109
+ expect(() => new Thermostat(data2)).toThrow();
110
+ });
111
+
112
+ test("throws error if currentHumidity is out of range ", () => {
113
+ const data = { ...valid };
114
+ const data2 = { ...valid };
115
+ data.currentHumidity = 100;
116
+ data2.currentHumidity = -1;
117
+ expect(() => new Thermostat(data)).toThrow();
118
+ expect(() => new Thermostat(data2)).toThrow();
119
+ });
120
+
121
+ test("returns deltas", () => {
122
+ const thermostat = new Thermostat({ ...valid });
123
+
124
+ const delta1 = Thermostat.getActionDelta(thermostat, {
125
+ hvacMode: "heat",
126
+ setpoints: {
127
+ cool: {
128
+ value: 71,
129
+ },
130
+ },
131
+ });
132
+
133
+ const delta2 = Thermostat.getActionDelta(thermostat, {
134
+ setpoints: {
135
+ heat: {
136
+ value: 71,
137
+ },
138
+ },
139
+ });
140
+
141
+ expect(delta1.hvacMode).toBe(1);
142
+ expect(delta1["setpoints.cool"]).toBeLessThan(0);
143
+ expect(delta1["setpoints.cool"]).toBeGreaterThan(-1);
144
+ expect(delta2["setpoints.heat"]).toBeGreaterThan(0);
145
+ expect(delta2["setpoints.heat"]).toBeLessThan(1);
146
+ });
@@ -0,0 +1,28 @@
1
+ const User = require("../../../models/user");
2
+
3
+ const valid = {
4
+ firstName: "Ian",
5
+ lastName: "Rogers",
6
+ active: true,
7
+ type: "user",
8
+ email: "a3@bc.com",
9
+ phone: "+15555555555",
10
+ roles: ["Guest"],
11
+ };
12
+
13
+ test("does not throw error if invalid name provided ", () => {
14
+ const data = { ...valid };
15
+ expect(() => new User(data)).not.toThrow();
16
+ });
17
+
18
+ test("allows email to be empty", () => {
19
+ const data = { ...valid };
20
+ delete data.email;
21
+ expect(() => new User(data)).not.toThrow();
22
+ });
23
+
24
+ test("allows phone to be empty", () => {
25
+ const data = { ...valid };
26
+ delete data.phone;
27
+ expect(() => new User(data)).not.toThrow();
28
+ });