artes 1.1.5 → 1.1.6

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.1.5",
3
+ "version": "1.1.6",
4
4
  "description": "The simplest way to automate UI and API tests using Cucumber-style steps.",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -4,9 +4,10 @@ const {
4
4
  context,
5
5
  selector,
6
6
  resolveVariable,
7
- moduleConfig,
7
+ moduleConfig
8
8
  } = require("../imports/commons");
9
9
 
10
+
10
11
  function getMimeType(filePath) {
11
12
  const ext = path.extname(filePath).toLowerCase();
12
13
  const mimeTypes = {
@@ -28,52 +29,59 @@ function getMimeType(filePath) {
28
29
  return mimeTypes[ext] || "application/octet-stream";
29
30
  }
30
31
 
31
- function processForm(formData, key, value) {
32
- if (typeof value === "object") {
33
- if (value.contentType) {
34
- const content =
35
- typeof value.data === "object"
36
- ? JSON.stringify(value.data)
37
- : String(value.data);
38
-
39
- formData[key] = {
40
- name: value.filename || key,
41
- mimeType: value.contentType,
42
- buffer: Buffer.from(content, "utf8"),
43
- };
44
- return;
45
- } else {
46
- formData[key] = JSON.stringify(value);
47
- return;
48
- }
49
- }
50
-
51
- if (
52
- typeof value === "string" &&
53
- (value.endsWith(".pdf") ||
54
- value.endsWith(".jpg") ||
55
- value.endsWith(".png") ||
56
- value.endsWith(".txt") ||
57
- value.endsWith(".doc") ||
58
- value.endsWith(".docx") ||
59
- value.includes("/"))
60
- ) {
61
- try {
62
- const filePath = path.join(moduleConfig.projectPath, value);
63
- if (fs.existsSync(filePath)) {
64
- formData[key] = {
65
- name: path.basename(filePath),
66
- mimeType: getMimeType(filePath),
67
- buffer: fs.readFileSync(filePath),
68
- };
69
- return;
32
+ function processForm( requestBody) {
33
+ for (const [key, value] of Object.entries(requestBody)) {
34
+
35
+ for (const item of value) {
36
+ if (typeof value === "object") {
37
+ if (value.contentType) {
38
+ const content =
39
+ typeof value.data === "object"
40
+ ? JSON.stringify(value.data)
41
+ : String(value.data);
42
+
43
+ formData[key] = {
44
+ name: value.filename || key,
45
+ mimeType: value.contentType,
46
+ buffer: Buffer.from(content, "utf8"),
47
+ };
48
+ return;
49
+ } else {
50
+ formData[key] = JSON.stringify(value);
51
+ return;
52
+ }
53
+ }
54
+
55
+ if (
56
+ typeof value === "string" &&
57
+ (value.endsWith(".pdf") ||
58
+ value.endsWith(".jpg") ||
59
+ value.endsWith(".png") ||
60
+ value.endsWith(".txt") ||
61
+ value.endsWith(".doc") ||
62
+ value.endsWith(".docx") ||
63
+ value.includes("/"))
64
+ ) {
65
+ try {
66
+ const filePath = path.join(moduleConfig.projectPath, value);
67
+ if (fs.existsSync(filePath)) {
68
+ formData[key] = {
69
+ name: path.basename(filePath),
70
+ mimeType: getMimeType(filePath),
71
+ buffer: fs.readFileSync(filePath),
72
+ };
73
+ return;
74
+ }
75
+ } catch (error) {
76
+ console.log(error);
77
+ }
78
+ }
79
+
80
+ formData[key] = value;
81
+
70
82
  }
71
- } catch (error) {
72
- console.log(error);
73
83
  }
74
- }
75
-
76
- formData[key] = value;
84
+ return formData;
77
85
  }
78
86
 
79
87
  async function requestMaker(headers, data, requestDataType) {
@@ -124,14 +132,12 @@ async function responseMaker(request, response, duration) {
124
132
  }
125
133
 
126
134
 
127
-
128
135
  return responseObject;
129
136
  }
130
137
 
131
138
  const api = {
132
139
  get: async (url, payload) => {
133
140
  const URL = await selector(url);
134
- const resolvedURL = await resolveVariable(URL);
135
141
 
136
142
  const resolvedPayload = (await payload) && resolveVariable(payload);
137
143
  const payloadJSON = (await resolvedPayload) && JSON.parse(resolvedPayload);
@@ -140,7 +146,7 @@ const api = {
140
146
 
141
147
  const requestStarts = performance.now();
142
148
 
143
- const res = await context.request.get(resolvedURL, req);
149
+ const res = await context.request.get(URL[0], req);
144
150
 
145
151
  const duration = performance.now() - requestStarts;
146
152
 
@@ -150,11 +156,10 @@ const api = {
150
156
  },
151
157
  head: async (url) => {
152
158
  const URL = await selector(url);
153
- const resolvedURL = await resolveVariable(URL);
154
159
 
155
160
  const requestStarts = performance.now();
156
161
 
157
- const res = await context.request.head(resolvedURL);
162
+ const res = await context.request.head(URL[0]);
158
163
 
159
164
  const duration = performance.now() - requestStarts;
160
165
 
@@ -164,7 +169,6 @@ const api = {
164
169
  },
165
170
  post: async (url, payload, requestDataType) => {
166
171
  const URL = await selector(url);
167
- const resolvedURL = await resolveVariable(URL);
168
172
 
169
173
  const resolvedPayload = (await payload) && resolveVariable(payload);
170
174
  const payloadJSON = (await resolvedPayload) && JSON.parse(resolvedPayload);
@@ -173,15 +177,12 @@ const api = {
173
177
 
174
178
  switch (requestDataType) {
175
179
  case "multipart":
176
- let formData = {};
177
180
 
178
- for (const [key, value] of Object.entries(payloadJSON?.body)) {
179
- processForm(formData, key, value);
180
- }
181
+ const formRequest = processForm( payloadJSON?.body || {});
181
182
 
182
183
  req = await requestMaker(
183
184
  payloadJSON?.headers || {},
184
- formData || {},
185
+ formRequest || {},
185
186
  requestDataType,
186
187
  );
187
188
  break;
@@ -194,7 +195,7 @@ const api = {
194
195
 
195
196
  const requestStarts = performance.now();
196
197
 
197
- const res = await context.request.post(resolvedURL, req);
198
+ const res = await context.request.post(URL[0], req);
198
199
 
199
200
  const duration = performance.now() - requestStarts;
200
201
 
@@ -204,7 +205,6 @@ const api = {
204
205
  },
205
206
  put: async (url, payload, requestDataType) => {
206
207
  const URL = await selector(url);
207
- const resolvedURL = await resolveVariable(URL);
208
208
 
209
209
  const resolvedPayload = (await payload) && resolveVariable(payload);
210
210
  const payloadJSON = (await resolvedPayload) && JSON.parse(resolvedPayload);
@@ -213,15 +213,14 @@ const api = {
213
213
 
214
214
  switch (requestDataType) {
215
215
  case "multipart":
216
- let formData = {};
217
216
 
218
- for (const [key, value] of Object.entries(payloadJSON?.body)) {
219
- processForm(formData, key, value);
220
- }
217
+ const formRequest = processForm( payloadJSON?.body || {});
218
+
219
+
221
220
 
222
221
  req = await requestMaker(
223
222
  payloadJSON?.headers || {},
224
- formData || {},
223
+ formRequest || {},
225
224
  requestDataType,
226
225
  );
227
226
 
@@ -235,7 +234,7 @@ const api = {
235
234
 
236
235
  const requestStarts = performance.now();
237
236
 
238
- const res = await context.request.put(resolvedURL, req);
237
+ const res = await context.request.put(URL[0], req);
239
238
 
240
239
  const duration = performance.now() - requestStarts;
241
240
 
@@ -245,7 +244,6 @@ const api = {
245
244
  },
246
245
  patch: async (url, payload, requestDataType) => {
247
246
  const URL = await selector(url);
248
- const resolvedURL = await resolveVariable(URL);
249
247
 
250
248
  const resolvedPayload = (await payload) && resolveVariable(payload);
251
249
  const payloadJSON = (await resolvedPayload) && JSON.parse(resolvedPayload);
@@ -256,13 +254,12 @@ const api = {
256
254
  case "multipart":
257
255
  let formData = {};
258
256
 
259
- for (const [key, value] of Object.entries(payloadJSON?.body)) {
260
- processForm(formData, key, value);
261
- }
257
+ const formRequest = processForm( payloadJSON?.body || {});
258
+
262
259
 
263
260
  req = await requestMaker(
264
261
  payloadJSON?.headers || {},
265
- formData || {},
262
+ formRequest || {},
266
263
  requestDataType,
267
264
  );
268
265
 
@@ -276,7 +273,7 @@ const api = {
276
273
 
277
274
  const requestStarts = performance.now();
278
275
 
279
- const res = await context.request.patch(resolvedURL, req);
276
+ const res = await context.request.patch(URL[0], req);
280
277
 
281
278
  const duration = performance.now() - requestStarts;
282
279
 
@@ -286,7 +283,6 @@ const api = {
286
283
  },
287
284
  delete: async (url, payload) => {
288
285
  const URL = await selector(url);
289
- const resolvedURL = await resolveVariable(URL);
290
286
 
291
287
  const resolvedPayload = (await payload) && resolveVariable(payload);
292
288
  const payloadJSON = (await resolvedPayload) && JSON.parse(resolvedPayload);
@@ -297,7 +293,7 @@ const api = {
297
293
 
298
294
  const requestStarts = performance.now();
299
295
 
300
- const res = await context.request.delete(resolvedURL, req);
296
+ const res = await context.request.delete(URL[0], req);
301
297
 
302
298
  const duration = performance.now() - requestStarts;
303
299