artes 1.0.66 → 1.0.67

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "artes",
3
- "version": "1.0.66",
3
+ "version": "1.0.67",
4
4
  "description": "The simplest way to automate UI and API tests using Cucumber-style steps.",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -1,4 +1,6 @@
1
- const { context, selector, resolveVariable } = require("../imports/commons");
1
+ const path = require("path");
2
+ const fs = require("fs");
3
+ const { context, selector, resolveVariable, moduleConfig } = require("../imports/commons");
2
4
 
3
5
  function getMimeType(filePath) {
4
6
  const ext = path.extname(filePath).toLowerCase();
@@ -21,9 +23,7 @@ function getMimeType(filePath) {
21
23
  return mimeTypes[ext] || "application/octet-stream";
22
24
  }
23
25
 
24
- function processForm(key, value) {
25
- let formData = {};
26
-
26
+ function processForm(formData, key, value) {
27
27
  if (typeof value === "object") {
28
28
  if (value.contentType) {
29
29
  const content =
@@ -36,8 +36,10 @@ function processForm(key, value) {
36
36
  mimeType: value.contentType,
37
37
  buffer: Buffer.from(content, "utf8"),
38
38
  };
39
+ return;
39
40
  } else {
40
41
  formData[key] = JSON.stringify(value);
42
+ return;
41
43
  }
42
44
  }
43
45
 
@@ -52,18 +54,21 @@ function processForm(key, value) {
52
54
  value.includes("/"))
53
55
  ) {
54
56
  try {
55
- if (fs.existsSync(value)) {
57
+ const filePath = path.join(moduleConfig.projectPath, value);
58
+ if (fs.existsSync(filePath)) {
56
59
  formData[key] = {
57
- name: path.basename(value),
58
- mimeType: getMimeType(value),
59
- buffer: fs.readFileSync(value),
60
+ name: path.basename(filePath),
61
+ mimeType: getMimeType(filePath),
62
+ buffer: fs.readFileSync(filePath),
60
63
  };
61
64
  return;
62
65
  }
63
- } catch (error) {}
66
+ } catch (error) {
67
+ console.log(error);
68
+ }
64
69
  }
65
70
 
66
- return formData;
71
+ formData[key] = value;
67
72
  }
68
73
 
69
74
  async function requestMaker(headers, data, requestDataType) {
@@ -148,23 +153,22 @@ const api = {
148
153
 
149
154
  switch (requestDataType) {
150
155
  case "multipart":
151
- let combinedFormData = {};
152
-
153
- for (const [key, value] of Object.entries(payloadJSON.body)) {
154
- const formData = processForm(key, value);
155
- Object.assign(combinedFormData, formData);
156
+ let formData = {};
157
+
158
+ for (const [key, value] of Object.entries(payloadJSON?.body)) {
159
+ processForm(formData, key, value);
156
160
  }
157
161
 
158
162
  req = await requestMaker(
159
- payloadJSON.headers || {},
160
- combinedFormData || {},
163
+ payloadJSON?.headers || {},
164
+ formData || {},
161
165
  requestDataType,
162
166
  );
163
167
  break;
164
168
  default:
165
169
  req = await requestMaker(
166
- payloadJSON.headers || {},
167
- payloadJSON.body || {},
170
+ payloadJSON?.headers || {},
171
+ payloadJSON?.body || {},
168
172
  );
169
173
  }
170
174
 
@@ -172,7 +176,7 @@ const api = {
172
176
 
173
177
  const response = await responseMaker(payloadJSON, res);
174
178
 
175
- context.response = await response;
179
+ context.response = response;
176
180
  },
177
181
  put: async (url, payload, requestDataType) => {
178
182
  const URL = await selector(url);
@@ -185,23 +189,23 @@ const api = {
185
189
 
186
190
  switch (requestDataType) {
187
191
  case "multipart":
188
- let combinedFormData = {};
189
- for (const [key, value] of Object.entries(payloadJSON.body)) {
190
- const formData = processForm(key, value);
191
- Object.assign(combinedFormData, formData);
192
+ let formData = {};
193
+
194
+ for (const [key, value] of Object.entries(payloadJSON?.body)) {
195
+ processForm(formData, key, value);
192
196
  }
193
197
 
194
198
  req = await requestMaker(
195
- payloadJSON.headers || {},
196
- combinedFormData || {},
199
+ payloadJSON?.headers || {},
200
+ formData || {},
197
201
  requestDataType,
198
202
  );
199
203
 
200
204
  break;
201
205
  default:
202
206
  req = await requestMaker(
203
- payloadJSON.headers || {},
204
- payloadJSON.body || {},
207
+ payloadJSON?.headers || {},
208
+ payloadJSON?.body || {},
205
209
  );
206
210
  }
207
211
 
@@ -209,7 +213,7 @@ const api = {
209
213
 
210
214
  const response = await responseMaker(payloadJSON, res);
211
215
 
212
- context.response = await response;
216
+ context.response = response;
213
217
  },
214
218
  patch: async (url, payload, requestDataType) => {
215
219
  const URL = await selector(url);
@@ -222,31 +226,31 @@ const api = {
222
226
 
223
227
  switch (requestDataType) {
224
228
  case "multipart":
225
- let combinedFormData = {};
226
- for (const [key, value] of Object.entries(payloadJSON.body)) {
227
- const formData = processForm(key, value);
228
- Object.assign(combinedFormData, formData);
229
+ let formData = {};
230
+
231
+ for (const [key, value] of Object.entries(payloadJSON?.body)) {
232
+ processForm(formData, key, value);
229
233
  }
230
234
 
231
235
  req = await requestMaker(
232
- payloadJSON.headers || {},
233
- combinedFormData || {},
236
+ payloadJSON?.headers || {},
237
+ formData || {},
234
238
  requestDataType,
235
239
  );
236
240
 
237
241
  break;
238
242
  default:
239
243
  req = await requestMaker(
240
- payloadJSON.headers || {},
241
- payloadJSON.body || {},
244
+ payloadJSON?.headers || {},
245
+ payloadJSON?.body || {},
242
246
  );
243
247
  }
244
248
 
245
249
  const res = await context.request.patch(resolvedURL, req);
246
250
 
247
- const response = responseMaker(payloadJSON, res);
251
+ const response = await responseMaker(payloadJSON, res);
248
252
 
249
- context.response = await response;
253
+ context.response = response;
250
254
  },
251
255
  delete: async (url, payload) => {
252
256
  const URL = await selector(url);