@cuppet/core 1.3.2 → 1.3.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.
@@ -63,9 +63,35 @@ When(
63
63
  await dataStorage.generateAndSaveDateWithCustomFormat(format, variable, days);
64
64
  }
65
65
  );
66
- When('I generate time in {string} format for now and store it in {string}', async function (format, variable) {
67
- await dataStorage.generateAndSaveDateWithCustomFormat(format, variable);
68
- });
66
+ /**
67
+ * Generate date with custom format and timezone and store it in a variable
68
+ * @param format - date format
69
+ * @param variable - variable name
70
+ * @param offset - UTC offset in hours (acceptable values are -12, -6, -3, 0, 3, 6, 12, etc.)
71
+ * @returns {Promise<void>}
72
+ */
73
+ When(
74
+ 'I generate date in {string} format for today with UTC offset {int} hours and store it in {string}',
75
+ async function (format, offset, variable) {
76
+ const utcOffset = offset * 60;
77
+ await dataStorage.generateAndSaveDateWithCustomFormatAndTz(format, variable, 0, utcOffset);
78
+ }
79
+ );
80
+ /**
81
+ * Generate date with custom format and timezone and store it in a variable
82
+ * @param format - date format
83
+ * @param variable - variable name
84
+ * @param days - number of days to add/subtract from the current date
85
+ * @param offset - UTC offset in hours (acceptable values are -12, -6, -3, 0, 3, 6, 12, etc.)
86
+ * @returns {Promise<void>}
87
+ */
88
+ When(
89
+ 'I generate date in {string} format for {string} days from now with UTC offset {int} hours and store it in {string}',
90
+ async function (format, offset, days, variable) {
91
+ const utcOffset = offset * 60;
92
+ await dataStorage.generateAndSaveDateWithCustomFormatAndTz(format, variable, days, utcOffset);
93
+ }
94
+ );
69
95
  When('I create json object from {string} file and store it in {string} variable', async function (filePath, variable) {
70
96
  const checkedPath = await dataStorage.checkForSavedVariable(filePath);
71
97
  const getFileData = dataStorage.getJsonFile(checkedPath);
@@ -27,7 +27,7 @@ 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) {
30
+ When('I prepare a JSON as MQTT message', async function (docString) {
31
31
  const message = JSON.stringify(docString);
32
32
  await mqttFunctions.prepareMessage(message, true);
33
33
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cuppet/core",
3
- "version": "1.3.2",
3
+ "version": "1.3.4",
4
4
  "description": "Core testing framework components for Cuppet - BDD framework based on Cucumber and Puppeteer",
5
5
  "main": "index.js",
6
6
  "files": [
@@ -276,17 +276,34 @@ module.exports = {
276
276
  },
277
277
 
278
278
  /**
279
- *
280
- * @param format
281
- * @param variable
282
- * @param days
279
+ * Generate date with custom format in local timezone and store it in a variable
280
+ * @param format - date format
281
+ * @param variable - variable name
282
+ * @param days - number of days to add/subtract from the current date
283
283
  * @returns {Promise<void>}
284
284
  */
285
285
  generateAndSaveDateWithCustomFormat: async function (format, variable, days = 0) {
286
- let date = moment()
286
+ const date = moment()
287
287
  .add(days >= 0 ? days : -days, 'days')
288
288
  .format(format);
289
289
 
290
290
  await this.iStoreVariableWithValueToTheJsonFile(date, variable);
291
291
  },
292
+
293
+ /**
294
+ * Generate date with custom format and timezone and store it in a variable
295
+ * THIS METHID IS NOT COMBINED WITH THE generateAndSaveDateWithCustomFormat due to ease of use in Gherkin steps.
296
+ * @param format - date format
297
+ * @param variable - variable name
298
+ * @param days - number of days to add/subtract from the current date
299
+ * @param offset - UTC offset in minutes (acceptable values are -240, -120, -60, 0, 60, 120, 240, etc.)
300
+ * @returns {Promise<void>}
301
+ */
302
+ generateAndSaveDateWithCustomFormatAndTz: async function (format, variable, days = 0, offset = 0) {
303
+ const date = moment()
304
+ .utcOffset(offset)
305
+ .add(days >= 0 ? days : -days, 'days')
306
+ .format(format);
307
+ await this.iStoreVariableWithValueToTheJsonFile(date, variable);
308
+ },
292
309
  };
@@ -7,8 +7,8 @@ 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,
10
+ /** @type {string} */
11
+ messageString: null,
12
12
 
13
13
  /**
14
14
  * Prepare topic by replacing variables
@@ -28,8 +28,11 @@ module.exports = {
28
28
  const resolvedMessage = await storage.checkForMultipleVariables(message);
29
29
  if (json) {
30
30
  try {
31
- this.messageObject = JSON.parse(resolvedMessage);
32
- return this.messageObject;
31
+ // Validate JSON (do not assign the value to the message object)
32
+ JSON.parse(resolvedMessage);
33
+ // Pass it as a string
34
+ this.messageString = resolvedMessage;
35
+ return this.messageString;
33
36
  } catch (error) {
34
37
  throw new Error(`Invalid JSON message: ${error.message}`);
35
38
  }
@@ -86,9 +89,9 @@ module.exports = {
86
89
  */
87
90
  publishJsonMessage: async function (mqttManager, topic, jsonString = null, qos = 0, retain = false) {
88
91
  const resolvedTopic = await this.prepareTopic(topic);
89
- const resolvedJson = jsonString ? await this.prepareMessage(jsonString, true) : this.messageObject;
92
+ const resolvedJson = jsonString ? await this.prepareMessage(jsonString, true) : this.messageString;
90
93
  // Delete the message object before the message is published to avoid conflicts if the request fails.
91
- delete this.messageObject;
94
+ delete this.messageString;
92
95
  await mqttManager.publish(resolvedTopic, resolvedJson, { qos, retain });
93
96
  },
94
97