@cuppet/core 1.3.0 → 1.3.1
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
CHANGED
|
@@ -132,8 +132,8 @@ For a detailed configuration and step definitions guide, see [GUIDE.MD](./GUIDE.
|
|
|
132
132
|
|
|
133
133
|
This package requires the following peer dependencies:
|
|
134
134
|
|
|
135
|
-
- `@cucumber/cucumber` ^
|
|
136
|
-
- `config` ^
|
|
135
|
+
- `@cucumber/cucumber` ^12.0.0
|
|
136
|
+
- `config` ^4.1.0
|
|
137
137
|
|
|
138
138
|
Make sure to install these in your project:
|
|
139
139
|
|
|
@@ -27,6 +27,10 @@ When('I unsubscribe from MQTT topic {string}', async function (topic) {
|
|
|
27
27
|
await mqttFunctions.unsubscribeFromTopic(this.mqttManager, topic);
|
|
28
28
|
});
|
|
29
29
|
|
|
30
|
+
When('I prepare MQTT message as JSON', async function (docString) {
|
|
31
|
+
await mqttFunctions.prepareMessage(docString, true);
|
|
32
|
+
});
|
|
33
|
+
|
|
30
34
|
/**
|
|
31
35
|
* Publish a message to an MQTT topic
|
|
32
36
|
* @example When I publish "Hello World" to MQTT topic "test/message"
|
package/package.json
CHANGED
package/src/mqttFunctions.js
CHANGED
|
@@ -7,6 +7,9 @@ const helper = require('./helperFunctions');
|
|
|
7
7
|
* Provides core MQTT testing operations following the same pattern as Puppeteer and Appium functions
|
|
8
8
|
*/
|
|
9
9
|
module.exports = {
|
|
10
|
+
/** @type {Object} */
|
|
11
|
+
messageObject: null,
|
|
12
|
+
|
|
10
13
|
/**
|
|
11
14
|
* Prepare topic by replacing variables
|
|
12
15
|
* @param {string} topic - Topic with potential variables
|
|
@@ -21,8 +24,17 @@ module.exports = {
|
|
|
21
24
|
* @param {string} message - Message with potential variables
|
|
22
25
|
* @returns {Promise<string>} - Resolved message
|
|
23
26
|
*/
|
|
24
|
-
prepareMessage: async function (message) {
|
|
25
|
-
|
|
27
|
+
prepareMessage: async function (message, json = false) {
|
|
28
|
+
const resolvedMessage = await storage.checkForMultipleVariables(message);
|
|
29
|
+
if (json) {
|
|
30
|
+
try {
|
|
31
|
+
this.messageObject = JSON.parse(resolvedMessage);
|
|
32
|
+
return this.messageObject;
|
|
33
|
+
} catch (error) {
|
|
34
|
+
throw new Error(`Invalid JSON message: ${error.message}`);
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
return resolvedMessage;
|
|
26
38
|
},
|
|
27
39
|
|
|
28
40
|
/**
|
|
@@ -59,8 +71,9 @@ module.exports = {
|
|
|
59
71
|
*/
|
|
60
72
|
publishMessage: async function (mqttManager, message, topic, qos = 0, retain = false) {
|
|
61
73
|
const resolvedTopic = await this.prepareTopic(topic);
|
|
62
|
-
const resolvedMessage = await this.prepareMessage(message);
|
|
74
|
+
const resolvedMessage = this.messageObject || (await this.prepareMessage(message));
|
|
63
75
|
await mqttManager.publish(resolvedTopic, resolvedMessage, { qos, retain });
|
|
76
|
+
delete this.messageObject;
|
|
64
77
|
},
|
|
65
78
|
|
|
66
79
|
/**
|
|
@@ -74,7 +87,7 @@ module.exports = {
|
|
|
74
87
|
*/
|
|
75
88
|
publishJsonMessage: async function (mqttManager, jsonString, topic, qos = 0, retain = false) {
|
|
76
89
|
const resolvedTopic = await this.prepareTopic(topic);
|
|
77
|
-
const resolvedJson = await this.prepareMessage(jsonString);
|
|
90
|
+
const resolvedJson = this.messageObject || (await this.prepareMessage(jsonString));
|
|
78
91
|
|
|
79
92
|
// Validate JSON
|
|
80
93
|
try {
|
|
@@ -84,6 +97,7 @@ module.exports = {
|
|
|
84
97
|
}
|
|
85
98
|
|
|
86
99
|
await mqttManager.publish(resolvedTopic, resolvedJson, { qos, retain });
|
|
100
|
+
delete this.messageObject;
|
|
87
101
|
},
|
|
88
102
|
|
|
89
103
|
/**
|