@cuppet/core 1.3.3 → 1.3.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.
@@ -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);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cuppet/core",
3
- "version": "1.3.3",
3
+ "version": "1.3.5",
4
4
  "description": "Core testing framework components for Cuppet - BDD framework based on Cucumber and Puppeteer",
5
5
  "main": "index.js",
6
6
  "files": [
@@ -200,13 +200,19 @@ module.exports = {
200
200
 
201
201
  /**
202
202
  * Validate value of property from the http response.
203
+ * Automatically converts expectedValue from Gherkin string to match the actual type (string, number, boolean, null).
203
204
  * @param property
204
205
  * @param expectedValue
205
206
  * @returns {Promise<void>}
206
207
  */
207
208
  propertyHasValue: async function (property, expectedValue) {
208
209
  const actualValue = await helper.getPropertyValue(this.response.data, property);
209
- assert.strictEqual(actualValue, expectedValue, `Property "${property}" does not have the expected value`);
210
+ const castedExpectedValue = helper.castPrimitiveType(expectedValue);
211
+ assert.strictEqual(
212
+ actualValue,
213
+ castedExpectedValue,
214
+ `Property "${property}" does not have the expected value. Expected: ${castedExpectedValue} , Actual: ${actualValue}`
215
+ );
210
216
  },
211
217
 
212
218
  /**
@@ -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
  };