runner-runtime 1.0.46 → 1.0.48

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/events/api.js CHANGED
@@ -9,7 +9,7 @@ const FileType = require("file-type"),
9
9
  tough = require("tough-cookie"),
10
10
  Buffer = require("buffer/").Buffer,
11
11
  isImage = require("is-image");
12
- const { getAPIFromCollection, smartUrlJoin, replace2RegExp, getParentTargetIDs,encodeURIComponentUnique, base64toCacheFile, getInsideVariables, getCaseInsensitive, camelCaseToSnakeCase } = require('../libs/utils'),
12
+ const { getAPIFromCollection, smartUrlJoin, jsfGenerate, replace2RegExp, getParentTargetIDs, encodeURIComponentUnique, base64toCacheFile, getInsideVariables, getCaseInsensitive, camelCaseToSnakeCase } = require('../libs/utils'),
13
13
  { generateHarFromRequest } = require('../libs/2har'),
14
14
 
15
15
  _ = require('lodash');
@@ -22,7 +22,6 @@ const { v4: uuidv4 } = require("uuid");
22
22
  const fs = require("fs");
23
23
  const { minimatch } = require("minimatch");
24
24
  const runtime = require("postman-runtime-pro");
25
- const { error } = require("console");
26
25
 
27
26
  // 将api转postman请求参数
28
27
  const convert2PostmanRequest = (request, option) => {
@@ -38,6 +37,8 @@ const convert2PostmanRequest = (request, option) => {
38
37
  }
39
38
  };
40
39
 
40
+ const { lang } = option;
41
+
41
42
  // 处理 url
42
43
  const raw = autoReplaceMockVar(_.get(request, "request.url") || _.get(request, "url"));
43
44
  const uri = new Url(raw);
@@ -53,10 +54,17 @@ const convert2PostmanRequest = (request, option) => {
53
54
  );
54
55
  _.forEach(_.get(request, "request.query.parameter"), (item) => {
55
56
  if (_.isObject(item) && item?.is_checked > 0) {
56
- let { key, value } = item;
57
+ let { key, value, schema } = item;
57
58
  key = String(autoReplaceMockVar(_.trim(key)));
58
59
  value = String(autoReplaceMockVar(value));
59
60
 
61
+ if (value == '' && _.isObject(schema)) {
62
+ const tmpValue = jsfGenerate(schema, [], option?.lang);
63
+
64
+ if (!_.isUndefined(tmpValue)) {
65
+ value = tmpValue;
66
+ }
67
+ }
60
68
  if (key != "") {
61
69
  if (value == "" && queryAddEqual < 1) {
62
70
  // 不拼接 = 号
@@ -85,10 +93,18 @@ const convert2PostmanRequest = (request, option) => {
85
93
  _.forEach(
86
94
  _.get(request, "request.restful.parameter"), (item) => {
87
95
  if (_.isObject(item) && item?.is_checked > 0) {
88
- let { key, value } = item;
96
+ let { key, value, schema } = item;
89
97
  key = autoReplaceMockVar(_.trim(key));
90
98
  value = autoReplaceMockVar(value);
91
99
 
100
+ if (value == '' && _.isObject(schema)) {
101
+ const tmpValue = jsfGenerate(schema, [], option?.lang);
102
+
103
+ if (!_.isUndefined(tmpValue)) {
104
+ value = tmpValue;
105
+ }
106
+ }
107
+
92
108
  if (key != "") {
93
109
  uriVariable.push({ key, value });
94
110
  }
@@ -258,9 +274,17 @@ const convert2PostmanRequest = (request, option) => {
258
274
  _.forEach(_.get(request, "request.header.parameter"), (item) => {
259
275
  if (_.isObject(item) && item?.is_checked > 0) {
260
276
  let disabled = item?.is_checked > 0 ? false : true;
261
- let { key, value } = item;
277
+ let { key, value, schema } = item;
262
278
  key = autoReplaceMockVar(_.trim(key));
263
279
  value = autoReplaceMockVar(value);
280
+
281
+ if (value == '' && _.isObject(schema)) {
282
+ const tmpValue = jsfGenerate(schema, [], option?.lang);
283
+
284
+ if (!_.isUndefined(tmpValue)) {
285
+ value = tmpValue;
286
+ }
287
+ }
264
288
  key != "" && header.push({ key, value, disabled });
265
289
  }
266
290
  }
@@ -344,6 +368,14 @@ const convert2PostmanRequest = (request, option) => {
344
368
 
345
369
  let value = autoReplaceMockVar(item.value);
346
370
 
371
+ if (value == '' && _.isObject(item?.schema)) {
372
+ const tmpValue = jsfGenerate(item?.schema, [], option?.lang);
373
+
374
+ if (!_.isUndefined(tmpValue)) {
375
+ value = tmpValue;
376
+ }
377
+ }
378
+
347
379
  if (_.isUndefined(_.get(request, "request.cookie.cookie_encode")) || _.parseInt(_.get(request, "request.cookie.cookie_encode")) > 0) {
348
380
  value = encodeURIComponentUnique(value);
349
381
  }
@@ -390,10 +422,7 @@ const convert2PostmanRequest = (request, option) => {
390
422
  }
391
423
  }
392
424
  }
393
- } catch (e) {
394
-
395
- console.log(e)
396
- }
425
+ } catch (e) { }
397
426
 
398
427
  // 处理body
399
428
  const body = {};
@@ -432,10 +461,21 @@ const convert2PostmanRequest = (request, option) => {
432
461
  disabled: false,
433
462
  });
434
463
  } else {
464
+ let { value, schema } = item;
465
+ value = autoReplaceMockVar(value);
466
+
467
+ if (value == '' && _.isObject(schema)) {
468
+ const tmpValue = jsfGenerate(schema, [], option?.lang);
469
+
470
+ if (!_.isUndefined(tmpValue)) {
471
+ value = tmpValue;
472
+ }
473
+ }
474
+
435
475
  if (bodyMode == "form-data" && item.content_type != "") {
436
476
  body[body.mode].push({
437
477
  key: autoReplaceMockVar(item.key),
438
- value: autoReplaceMockVar(item.value),
478
+ value,
439
479
  type: "text",
440
480
  disabled: false,
441
481
  contentType: item.content_type,
@@ -443,7 +483,7 @@ const convert2PostmanRequest = (request, option) => {
443
483
  } else {
444
484
  body[body.mode].push({
445
485
  key: autoReplaceMockVar(item.key),
446
- value: autoReplaceMockVar(item.value),
486
+ value,
447
487
  type: "text",
448
488
  disabled: false,
449
489
  });
@@ -556,7 +596,7 @@ const convert2PostmanOptions = (request, option, variables) => {
556
596
  const globals = new sdk.VariableScope({
557
597
  values: globalsVariables,
558
598
  });
559
- console.log(JSON.stringify(variables, null,2))
599
+
560
600
  const requester = {
561
601
  strictSSL: false,
562
602
  protocolVersion: requestJson?.protocol == 'http/1.1' ? 'http1' : 'http2',
@@ -1101,11 +1141,11 @@ const convert2PostmanEvent = (request, listen, option) => {
1101
1141
  exec = `${exec}
1102
1142
  ! await (async function(){
1103
1143
  const dbData = ${JSON.stringify(item.data || { query: '' })}
1104
- const query = pm.variables.replaceIn(_.get(dbData, "query"));
1105
- const method = pm.variables.replaceIn(_.get(dbData, "method") || "");
1144
+ const query = pm.variables.replaceIn(lodashv4.get(dbData, "query"));
1145
+ const method = pm.variables.replaceIn(lodashv4.get(dbData, "method") || "");
1106
1146
 
1107
1147
  try{
1108
- let dbResultList = await pm.queryDatabase(_.assign(${dbconfig},{
1148
+ let dbResultList = await pm.queryDatabase(lodashv4.assign(${dbconfig},{
1109
1149
  method:method,
1110
1150
  query:query
1111
1151
  }));
@@ -1116,14 +1156,14 @@ const convert2PostmanEvent = (request, listen, option) => {
1116
1156
  if(${item.data?.isConsoleOutput} > 0){
1117
1157
  console.log(query, result)
1118
1158
  }
1119
- if(_.isObject(result)){
1120
- _.forEach(${JSON.stringify(item.data?.variables || [])}, (item) => {
1121
- let extra_value = jsonpath.value(result, _.trim(item?.pattern));
1159
+ if(lodashv4.isObject(result)){
1160
+ lodashv4.forEach(${JSON.stringify(item.data?.variables || [])}, (item) => {
1161
+ let extra_value = jsonpath.value(result, lodashv4.trim(item?.pattern));
1122
1162
  pm[item?.type].set(item?.name, extra_value);
1123
1163
  });
1124
1164
  }else{
1125
- if(!_.isObject(result)){
1126
- _.forEach(${JSON.stringify(item.data?.variables || [])}, (item) => {
1165
+ if(!lodashv4.isObject(result)){
1166
+ lodashv4.forEach(${JSON.stringify(item.data?.variables || [])}, (item) => {
1127
1167
  let extra_value = result;
1128
1168
  pm[item?.type].set(item?.name, extra_value);
1129
1169
  });
@@ -1947,6 +1987,7 @@ const initRequestJson = (event, option) => {
1947
1987
  let currentCookie = {
1948
1988
  key: key,
1949
1989
  value: item?.value,
1990
+ schema: item?.schema
1950
1991
  };
1951
1992
  if (currentKey > -1) {
1952
1993
  cookieArr[currentKey] = currentCookie;
@@ -2137,7 +2178,6 @@ module.exports = (event, option, callback, eventRuntimeData, eventResultList) =>
2137
2178
 
2138
2179
  // script print
2139
2180
  console(cursor, level, ...args) {
2140
- console.log({ level, args })
2141
2181
  if (_.isUndefined(_.get(eventRuntimeData, [event?.event_id, "console"]))) {
2142
2182
  _.set(eventRuntimeData, [event?.event_id, "console"], []);
2143
2183
  }
@@ -2203,7 +2243,7 @@ module.exports = (event, option, callback, eventRuntimeData, eventResultList) =>
2203
2243
  })
2204
2244
  }
2205
2245
  }
2206
- console.log(String(request?.url), 111111)
2246
+ // console.log(String(request?.url), 111111)
2207
2247
  const requestOptions = convert2EchoRequest(request, requestJson, postmanJSON, history);
2208
2248
  _.set(eventRuntimeData, [event?.event_id, "request"], requestOptions);
2209
2249
 
@@ -2256,13 +2296,13 @@ console.log(String(request?.url), 111111)
2256
2296
  },
2257
2297
 
2258
2298
  assertion(cursor, assertions) {
2299
+ console.log(JSON.stringify(assertions, null, 2), 111111)
2259
2300
  if (!_.includes(['get_parsed_request'], scene)) {
2260
2301
  if (!_.isEmpty(assertions) && _.isArray(assertions)) {
2261
2302
  if (_.isUndefined(_.get(eventRuntimeData, [event?.event_id, "assertions"]))) {
2262
2303
  _.set(eventRuntimeData, [event?.event_id, "assertions"], []);
2263
2304
  }
2264
2305
 
2265
- console.log(assertions,`assertionsassertionsassertionsassertionsassertions`)
2266
2306
  eventRuntimeData[event?.event_id].assertions = _.unionWith(_.concat(_.get(eventRuntimeData, [event?.event_id, "assertions"]), assertions), _.isEqual);
2267
2307
  }
2268
2308
  }
@@ -2296,7 +2336,7 @@ console.log(String(request?.url), 111111)
2296
2336
  const success_assert = _.filter(_.get(eventRuntimeData, [event?.event_id, "assertions"]), (item) => {
2297
2337
  return item?.passed === false
2298
2338
  })
2299
-
2339
+
2300
2340
  _.set(eventRuntimeData, [event?.event_id, "status"], {
2301
2341
  assert: _.get(eventRuntimeData, [event?.event_id, "assertions"], []),
2302
2342
  success_assert,
@@ -2305,11 +2345,17 @@ console.log(String(request?.url), 111111)
2305
2345
  }
2306
2346
 
2307
2347
  // 返回结果
2348
+ // 增加控制器开始时间
2349
+ _.set(eventRuntimeData, [event.event_id, 'iteration', 'endTime'], Date.now());
2350
+
2351
+ // 增加初始化变量
2352
+ const { environment = {}, variables = {}, _globals = {}, iterationData = {} } = _.get(eventRuntimeData, 'variables', {});
2353
+ _.set(eventRuntimeData, [event.event_id, 'iteration', 'endVariables'], { environment, variables, iterationData, globals: _globals });
2308
2354
  const tempVars = _.pick(_.get(eventRuntimeData, 'variables'), ['environment', '_globals']);
2309
2355
  const toLowerResponseJson = camelCaseToSnakeCase(_.get(eventRuntimeData, event?.event_id));
2310
2356
  const finalRequestResult = _.assign(
2311
2357
  _.pick(requestJson, ['parent_id', 'project_id', 'test_id', 'target_id']),
2312
- _.defaults(_.pick(toLowerResponseJson, ['error', 'iteration_id']), { error: null }),
2358
+ _.defaults(_.pick(toLowerResponseJson, ['error', 'iteration_id','iteration']), { error: null }),
2313
2359
  {
2314
2360
  action: 'request',
2315
2361
  type: 'request',
package/events/index.js CHANGED
@@ -230,22 +230,30 @@ const events = {
230
230
 
231
231
  // 调度器核心函数,用于递归执行具体场景步骤
232
232
  const executeEvent = (event, option, callback, eventRuntimeData, eventResultList) => {
233
+ // console.log(_.cloneDeep(eventRuntimeData?.variables),1111111)
233
234
  return new Promise((resolve, reject) => {
234
235
  if (_.isUndefined(event.event_id) && option?.scene === 'http_request') {
235
236
  _.set(event, 'event_id', _.get(event, 'data.target_id'))
236
237
  }
237
- // console.log(option?.scene)
238
+
238
239
  _.assign(eventRuntimeData?.variables?.iterationData, _.get(option, 'iterationData'))
239
240
  _.set(eventRuntimeData, [event.event_id, 'iteration_id'], aTools.snowflakeId());
240
241
 
241
242
  const eventCall = _.get(events, `${event?.type}`);
242
243
 
243
244
  if (_.isFunction(eventCall)) {
245
+ const { total, scene } = option;
246
+
247
+ // 增加控制器开始时间
248
+ _.set(eventRuntimeData, [event.event_id, 'iteration', 'startTime'], Date.now());
249
+
250
+ // 增加初始化变量
251
+ const { environment = {}, variables = {}, _globals = {}, iterationData = {} } = _.get(eventRuntimeData, 'variables', {});
252
+ _.set(eventRuntimeData, [event.event_id, 'iteration', 'startVariables'], _.cloneDeep({ environment, variables, iterationData, globals: _globals }));
253
+
244
254
  try {
245
255
  eventCall(event, option, callback, eventRuntimeData, eventResultList).then((data) => {
246
256
  resolve(data);
247
-
248
- const { total, scene } = option;
249
257
  if (scene == 'auto_test' && _.isInteger(event?.progress)) {
250
258
  callback({
251
259
  action: 'process',
package/index.js CHANGED
@@ -14,6 +14,7 @@ const run = async (events, option, callback) => {
14
14
  const eventRuntimeData = {
15
15
  variables: {
16
16
  environment: {},
17
+ variables: {},
17
18
  globals: {},
18
19
  _globals: {},
19
20
  iterationData: {},
package/libs/2har.js CHANGED
@@ -71,7 +71,7 @@ function generateHarFromRequest(options) {
71
71
  ],
72
72
  },
73
73
  };
74
- console.log(JSON.stringify(har, null,2))
74
+
75
75
  return har;
76
76
  }
77
77
 
package/libs/utils.js CHANGED
@@ -1,6 +1,9 @@
1
+ const { Schema } = require("../../json-schema-faker-pro/dist/vendor");
2
+
1
3
  const atomicSleep = require("atomic-sleep"),
2
4
  _ = require('lodash'),
3
5
  fs = require("fs"),
6
+ jsf = require("json-schema-faker-pro"),
4
7
  path = require("path"),
5
8
  { mockExp } = require('exp-mock'),
6
9
  Mock = require('mockjs5-pro'),
@@ -312,14 +315,13 @@ const getCaseInsensitive = (object, keyToFind) => {
312
315
  const variableReplace = (str, variables, option) => {
313
316
  const AllVars = getInsideVariables();
314
317
  ["variables", "globals", "_globals", "environment"].forEach((varName) => {
315
- console.log(11111111,_.get(variables, `${varName}`))
316
318
  _.assign(AllVars, _.get(variables, `${varName}`))
317
319
  })
318
320
 
319
321
  str = _.replace(str, /\{\{([^}]+)\}\}/g, (match, key) => {
320
322
  return _.get(AllVars, key.trim(), match);
321
323
  });
322
- console.log(2222222, str, _.get(AllVars, 'IF_xunhuan'),_.keys(AllVars))
324
+
323
325
  const { lang, custom_functions } = option;
324
326
 
325
327
  try {
@@ -449,7 +451,7 @@ const formatAutotestReportList = (eventResultList) => {
449
451
  if (_.includes(['assert_visual', 'assert'], item?.type)) {
450
452
  type = 'api';
451
453
  }
452
- console.log(item?.status?.success_assert,`item?.status?.success_assertitem?.status?.success_assertitem?.status?.success_assertitem?.status?.success_assert`)
454
+
453
455
  list.push(_.assign(
454
456
  _.pick(item?.response, ['timings', 'response_time', 'response_at', 'proxy', 'status', 'code', 'response_size']),
455
457
  _.pick(item?.request, ['url', 'method', 'name', 'target_id', 'project_id']),
@@ -535,7 +537,7 @@ const camelCaseToSnakeCase = (obj) => {
535
537
  return obj;
536
538
  }
537
539
 
538
- const encodeURIComponentUnique = (str) =>{
540
+ const encodeURIComponentUnique = (str) => {
539
541
  if (_.startsWith(str, '{{') && _.endsWith(str, '}}')) {
540
542
  return str;
541
543
  } else {
@@ -550,8 +552,32 @@ const encodeURIComponentUnique = (str) =>{
550
552
  }
551
553
  }
552
554
 
555
+ const jsfGenerate = (schema, mockRules = [], lang) => {
556
+ jsf.option({
557
+ alwaysFakeOptionals: true,
558
+ useExamplesValue: true,
559
+ fillProperties: false,
560
+ useDefaultValue: true,
561
+ mockRules,
562
+ lang: 'zh-cn',
563
+ });
564
+
565
+ let genResult = undefined;
566
+
567
+ if (_.some(["default", "examples", "pattern", "format", "x-mock","enum"], (value) => _.includes(_.keys(schema?.schema), value))) {
568
+ try {
569
+ genResult = jsf.generate(schema);
570
+ } catch (e) { }
571
+ }
572
+
573
+ if (!_.isUndefined(genResult)) {
574
+ return genResult;
575
+ }
576
+ }
577
+
553
578
  module.exports = {
554
579
  atomicSleep,
580
+ jsfGenerate,
555
581
  getAPIFromCollection,
556
582
  getParentTargetIDs,
557
583
  base64toCacheFile,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "runner-runtime",
3
- "version": "1.0.46",
3
+ "version": "1.0.48",
4
4
  "description": "runner-runtime.",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -24,11 +24,13 @@
24
24
  "apipost-tools": "^0.0.38",
25
25
  "atomic-sleep": "^1.0.0",
26
26
  "content-disposition": "^0.5.4",
27
+ "database-query": "^1.1.12",
27
28
  "exp-mock": "^2.0.15",
28
29
  "file-type": "^16.5.4",
29
30
  "is-image": "^3.0.0",
30
31
  "is-svg": "^4.3.2",
31
32
  "json-bigint": "^1.0.0",
33
+ "json-schema-faker-pro": "^0.5.15",
32
34
  "json5": "^2.2.3",
33
35
  "jsonpath": "^1.1.1",
34
36
  "lodash": "^4.17.21",
package/tmp/request.js CHANGED
@@ -1,6 +1,6 @@
1
1
  module.exports = {
2
2
  "option": {
3
- "scene": "auto_test",
3
+ "scene": "http_request",
4
4
  "globals": {},
5
5
  "project": {
6
6
  "request": {
@@ -70,168 +70,20 @@ module.exports = {
70
70
  "server_id": "1",
71
71
  "server_type": 1,
72
72
  "uri": ""
73
+ },
74
+ "1a9074f63fc07001": {
75
+ "sort": 600,
76
+ "name": "Idea_apipost-demo",
77
+ "server_id": "1a9074f63fc07001",
78
+ "server_type": -1,
79
+ "uri": ""
73
80
  }
74
81
  },
75
- "environment": {
76
- "ID": "222",
77
- "key": "value"
78
- }
82
+ "environment": {}
79
83
  },
80
84
  "cookies": {
81
85
  "switch": 1,
82
- "data": [
83
- {
84
- "key": "security_session_verify",
85
- "value": "4560bdb4c5ddc22643bc99515ea21fcf",
86
- "expires": "2025-04-19T14:45:34.000Z",
87
- "path": "/",
88
- "httpOnly": true,
89
- "creation": "2025-04-16T06:45:35.543Z",
90
- "name": "security_session_verify",
91
- "cookie_id": "375d8dd3f700a",
92
- "domain": "echo.apipost.cn",
93
- "project_id": "1a8a2a84eb7da002"
94
- },
95
- {
96
- "key": "security_session_verify",
97
- "value": "4560bdb4c5ddc22643bc99515ea21fcf",
98
- "expires": "2025-04-19T14:10:50.000Z",
99
- "path": "/",
100
- "httpOnly": true,
101
- "creation": "2025-04-16T06:10:50.623Z",
102
- "name": "security_session_verify",
103
- "cookie_id": "375d8dd3f700b",
104
- "domain": "echo.apipost.cn",
105
- "project_id": "1a8a2a84eb7da002"
106
- },
107
- {
108
- "key": "cookie-test1-folder",
109
- "value": "B",
110
- "expires": "Wed, 16 Apr 2025 07:45:42 GMT",
111
- "maxAge": 3600,
112
- "domain": "echo.apipost.cn",
113
- "path": "/echo",
114
- "creation": "2025-04-16T06:45:35.542Z",
115
- "name": "cookie-test1-folder",
116
- "cookie_id": "375d8dd3f700c",
117
- "project_id": "1a8a2a84eb7da002"
118
- },
119
- {
120
- "key": "cookie-test1",
121
- "value": "0",
122
- "expires": "Wed, 16 Apr 2025 07:45:42 GMT",
123
- "maxAge": 3600,
124
- "domain": "echo.apipost.cn",
125
- "path": "/",
126
- "creation": "2025-04-16T06:45:35.542Z",
127
- "name": "cookie-test1",
128
- "cookie_id": "375d8dd3f700d",
129
- "project_id": "1a8a2a84eb7da002"
130
- },
131
- {
132
- "key": "cookie-test2",
133
- "value": "0",
134
- "expires": "Wed, 16 Apr 2025 07:45:42 GMT",
135
- "maxAge": 3600,
136
- "domain": "echo.apipost.cn",
137
- "path": "/",
138
- "creation": "2025-04-16T06:45:35.542Z",
139
- "name": "cookie-test2",
140
- "cookie_id": "375d8dd3f700e",
141
- "project_id": "1a8a2a84eb7da002"
142
- },
143
- {
144
- "key": "cookie-test3",
145
- "value": "%25E4%25BD%25A0%25E5%25A5%25BD",
146
- "expires": "Wed, 16 Apr 2025 07:45:42 GMT",
147
- "maxAge": 3600,
148
- "domain": "echo.apipost.cn",
149
- "path": "/",
150
- "creation": "2025-04-16T06:45:35.542Z",
151
- "name": "cookie-test3",
152
- "cookie_id": "375d8dd3f700f",
153
- "project_id": "1a8a2a84eb7da002"
154
- },
155
- {
156
- "key": "cookie-test6",
157
- "value": "deleted",
158
- "expires": "Wed, 16 Apr 2025 06:45:42 GMT",
159
- "maxAge": 0,
160
- "domain": "echo.apipost.cn",
161
- "path": "/",
162
- "creation": "2025-04-16T06:45:35.543Z",
163
- "name": "cookie-test6",
164
- "cookie_id": "375d8dd3f7012",
165
- "project_id": "1a8a2a84eb7da002"
166
- },
167
- {
168
- "key": "cookie-test7",
169
- "value": "0",
170
- "expires": "Wed, 16 Apr 2025 06:45:42 GMT",
171
- "maxAge": 0,
172
- "domain": "echo.apipost.cn",
173
- "path": "/",
174
- "creation": "2025-04-16T06:45:35.543Z",
175
- "name": "cookie-test7",
176
- "cookie_id": "375d8dd3f7013",
177
- "project_id": "1a8a2a84eb7da002"
178
- },
179
- {
180
- "key": "cookie-test8",
181
- "value": "renge%3D%3D%3B-%2F%3F",
182
- "creation": "2025-04-16T06:45:35.543Z",
183
- "name": "cookie-test8",
184
- "cookie_id": "375d8dd3f7014",
185
- "domain": "echo.apipost.cn",
186
- "project_id": "1a8a2a84eb7da002"
187
- },
188
- {
189
- "key": "httponly-cookie",
190
- "value": "httponly-value",
191
- "httpOnly": true,
192
- "creation": "2025-04-16T06:45:35.543Z",
193
- "name": "httponly-cookie",
194
- "cookie_id": "375d8dd3f7015",
195
- "domain": "echo.apipost.cn",
196
- "project_id": "1a8a2a84eb7da002"
197
- },
198
- {
199
- "key": "security_session_verify",
200
- "value": "4560bdb4c5ddc22643bc99515ea21fcf",
201
- "expires": "2025-04-19T14:10:50.000Z",
202
- "path": "/",
203
- "httpOnly": true,
204
- "creation": "2025-04-16T06:10:50.626Z",
205
- "name": "security_session_verify",
206
- "cookie_id": "375d8dd3f7016",
207
- "domain": "echo.apipost.cn",
208
- "project_id": "1a8a2a84eb7da002"
209
- },
210
- {
211
- "key": "cookie-test4",
212
- "value": "%E4%BD%A0%E5%A5%BD%3D%3D%3D",
213
- "expires": "Wed, 16 Apr 2025 07:45:42 GMT",
214
- "maxAge": 3600,
215
- "domain": "apipost.cn",
216
- "path": "/",
217
- "creation": "2025-04-16T06:45:35.542Z",
218
- "name": "cookie-test4",
219
- "cookie_id": "375d8dd3f7010",
220
- "project_id": "1a8a2a84eb7da002"
221
- },
222
- {
223
- "key": "cookie-test5",
224
- "value": "nihao",
225
- "expires": "Wed, 16 Apr 2025 07:45:42 GMT",
226
- "maxAge": 3600,
227
- "domain": "apipost.cn",
228
- "path": "/",
229
- "creation": "2025-04-16T06:45:35.542Z",
230
- "name": "cookie-test5",
231
- "cookie_id": "375d8dd3f7011",
232
- "project_id": "1a8a2a84eb7da002"
233
- }
234
- ]
86
+ "data": []
235
87
  },
236
88
  "system_configs": {
237
89
  "send_timeout": 0,
@@ -263,181 +115,192 @@ module.exports = {
263
115
  "custom_functions": {},
264
116
  "collection": [
265
117
  {
266
- "target_id": "378a5473f704e",
118
+ "target_id": "1a9078f904007002",
267
119
  "target_type": "api",
268
- "parent_id": "0",
269
- "name": "副本",
120
+ "parent_id": "1a9078d81a407002",
121
+ "name": "/t3/save10",
270
122
  "request": {
271
123
  "auth": {
272
- "type": "inherit"
273
- },
274
- "body": {
275
- "mode": "none",
276
- "parameter": [],
277
- "raw": "",
278
- "raw_parameter": [],
279
- "raw_schema": {
280
- "type": "object"
281
- },
282
- "binary": null
124
+ "type": "noauth"
283
125
  },
284
- "pre_tasks": [],
285
- "post_tasks": [],
286
126
  "header": {
287
127
  "parameter": []
288
128
  },
289
129
  "query": {
290
- "parameter": [
130
+ "query_add_equal": 1,
131
+ "parameter": []
132
+ },
133
+ "restful": {
134
+ "parameter": []
135
+ },
136
+ "cookie": {
137
+ "cookie_encode": 1,
138
+ "parameter": []
139
+ },
140
+ "body": {
141
+ "mode": "json",
142
+ "parameter": [],
143
+ "binary": "",
144
+ "raw": "{\n \"map2\": {\n \"KEY\": {\n \"roleId\": 1,\n \"roleName\": \"\"\n }\n }\n}",
145
+ "raw_parameter": [
146
+ {
147
+ "key": "map2",
148
+ "value": "",
149
+ "type": "Text",
150
+ "description": "",
151
+ "is_checked": 1,
152
+ "not_null": "0",
153
+ "field_type": "Object"
154
+ },
291
155
  {
156
+ "key": "map2.KEY",
157
+ "value": "",
158
+ "type": "Text",
292
159
  "description": "",
293
- "field_type": "string",
294
160
  "is_checked": 1,
295
- "key": "id",
296
- "value": "{{id}}",
297
- "not_null": 1,
298
- "schema": {
299
- "type": "string"
300
- },
301
- "param_id": "375b74ab9b006"
161
+ "not_null": "0",
162
+ "field_type": "Object"
163
+ },
164
+ {
165
+ "key": "map2.KEY.roleId",
166
+ "value": "1",
167
+ "type": "Text",
168
+ "description": "角色id",
169
+ "is_checked": 1,
170
+ "not_null": "0",
171
+ "field_type": "Integer"
172
+ },
173
+ {
174
+ "key": "map2.KEY.roleName",
175
+ "value": "",
176
+ "type": "Text",
177
+ "description": "角色名称",
178
+ "is_checked": 1,
179
+ "not_null": "0",
180
+ "field_type": "String"
302
181
  }
303
182
  ],
304
- "query_add_equal": 1
183
+ "raw_schema": {
184
+ "type": "object",
185
+ "properties": {},
186
+ "APIPOST_ORDERS": [
187
+ "1a909547a042b003"
188
+ ],
189
+ "APIPOST_REFS": {
190
+ "1a909547a042b003": {}
191
+ }
192
+ }
305
193
  },
306
- "cookie": {
307
- "parameter": [],
308
- "cookie_encode": 1
194
+ "pre_tasks": [
195
+ {
196
+ "type": "customScript",
197
+ "id": "b40b7cc7d600d",
198
+ "name": "自定义脚本",
199
+ "enabled": 1,
200
+ "data": "pm.environment.set(\"key\", \"value\");\npm.variables.set(\"haha\",\"666666\")"
201
+ }
202
+ ],
203
+ "post_tasks": [
204
+ {
205
+ "type": "customScript",
206
+ "id": "b121041317005",
207
+ "name": "自定义脚本",
208
+ "enabled": -1,
209
+ "data": "apt.test(\"响应时间小于 200ms\", function () {\n apt.expect(apt.response.responseTime).to.be.below(200);\n });\napt.test(\"成功的POST请求\", function () {\n apt.expect(apt.response.code).to.be.oneOf([201, 202]);\n });\napt.test(\"状态码包含字符串\", function () {\n apt.response.to.have.status(\"Created\");\n });\nvar jsonObject = xml2Json(responseBody);\nvar schema = {\n \"items\": {\n \"type\": \"boolean\"\n }\n };\n\n var data1 = [true, false];\n var data2 = [true, 123];\n\n apt.test('Schema is valid', function () {\n apt.expect(tv4.validate(data1, schema)).to.be.true;\n apt.expect(tv4.validate(data2, schema)).to.be.true;\n });\npm.response.setBody(\"Response Body\");\napt.test(\"响应码为 200\", function () {\n apt.response.to.have.status(200);\n });"
210
+ }
211
+ ]
212
+ },
213
+ "parents": [
214
+ {
215
+ "target_id": "1a9078d81a407002",
216
+ "target_type": "folder"
309
217
  },
310
- "restful": {
311
- "parameter": []
218
+ {
219
+ "target_id": "1a9078d816407002",
220
+ "target_type": "folder",
221
+ "server_id": "1a9074f63fc07001"
312
222
  }
313
- },
314
- "parents": [],
223
+ ],
224
+ "server_id": "1a9074f63fc07001",
315
225
  "method": "POST",
316
226
  "protocol": "http/1.1",
317
- "url": "echo.apipost.cn/get.php?id={{id}}",
227
+ "url": "https://httpbin.org/anything",
228
+ "pre_url": ""
229
+ },
230
+ {
231
+ "target_id": "1a9078d816407002",
232
+ "target_type": "folder",
233
+ "parent_id": "0",
234
+ "name": "apipost-demo",
235
+ "request": {
236
+ "header": {
237
+ "parameter": []
238
+ },
239
+ "query": {
240
+ "parameter": []
241
+ },
242
+ "body": {
243
+ "parameter": []
244
+ },
245
+ "cookie": {
246
+ "parameter": []
247
+ },
248
+ "auth": {
249
+ "type": "noauth"
250
+ },
251
+ "pre_tasks": [],
252
+ "post_tasks": []
253
+ },
254
+ "parents": [],
255
+ "server_id": "1a9074f63fc07001",
256
+ "pre_url": ""
257
+ },
258
+ {
259
+ "target_id": "1a9078d81a407002",
260
+ "target_type": "folder",
261
+ "parent_id": "1a9078d816407002",
262
+ "name": "测试类3",
263
+ "request": {
264
+ "header": {
265
+ "parameter": []
266
+ },
267
+ "query": {
268
+ "parameter": []
269
+ },
270
+ "body": {
271
+ "parameter": []
272
+ },
273
+ "cookie": {
274
+ "parameter": []
275
+ },
276
+ "auth": {
277
+ "type": "noauth"
278
+ },
279
+ "pre_tasks": [],
280
+ "post_tasks": []
281
+ },
282
+ "parents": [
283
+ {
284
+ "target_id": "1a9078d816407002",
285
+ "target_type": "folder",
286
+ "server_id": "1a9074f63fc07001"
287
+ }
288
+ ],
289
+ "server_id": "0",
318
290
  "pre_url": ""
319
291
  }
320
292
  ],
321
- "database_configs": {},
322
- "name": "新建用例2",
323
- "ignore_error": -1,
324
- "enable_sandbox": -1,
325
- "iterationCount": 1,
326
- "sleep": 0,
327
- "testing_id": "37896d73f7045",
328
- "iterates_data_id": "0",
329
- "iterationData": []
293
+ "database_configs": {}
330
294
  },
331
295
  "test_events": [
332
296
  {
333
- "parent_event_id": "0",
334
- "enabled": 1,
335
- "type": "assert_visual",
297
+ "type": "api",
336
298
  "data": {
337
- "name": "可视化断言",
338
- "data": {
339
- "type": "envVars",
340
- "expression": {
341
- "compareType": "eq",
342
- "compareValue": "222",
343
- "path": "{{ID}}"
344
- }
345
- }
346
- },
347
- "project_id": "1a8a2a84eb7da002",
348
- "test_id": "37896d73f7045",
349
- "event_id": "37c37987f706e",
350
- "sort": 0
351
- },
352
- {
353
- "parent_event_id": "0",
354
- "enabled": -1,
355
- "type": "loop",
356
- "data": {
357
- "name": "循环",
358
- "loop_type": 3,
359
- "sleep": 0,
360
- "loop_timeout": 0,
361
- "loop_condition": {
362
- "var": "{{ID}}",
363
- "compare": "eq",
364
- "value": "222"
365
- },
366
- "loop_traverse_data": {
367
- "type": 1,
368
- "iterationData": [],
369
- "name": ""
370
- }
371
- },
372
- "project_id": "1a8a2a84eb7da002",
373
- "test_id": "37896d73f7045",
374
- "event_id": "37d3975bf7079",
375
- "sort": 2,
376
- "children": [
377
- {
378
- "type": "api",
379
- "auto_sync": false,
380
- "test_id": "37896d73f7045",
381
- "event_id": "378b6a33f7053",
382
- "enabled": -1,
383
- "data": {
384
- "target_id": "378a5473f704e",
385
- "project_id": "1a8a2a84eb7da002",
386
- "parent_id": "0",
387
- "target_type": "api",
388
- "apiData": {
389
- "name": "测试 副本",
390
- "method": "POST",
391
- "protocol": "http/1.1",
392
- "url": "echo.apipost.cn/get.php?id={{id}}",
393
- "request": {
394
- "auth": {
395
- "type": "inherit"
396
- },
397
- "body": {
398
- "raw": "",
399
- "mode": "none",
400
- "binary": "",
401
- "parameter": [],
402
- "raw_schema": {
403
- "type": "object"
404
- },
405
- "raw_parameter": []
406
- },
407
- "query": {
408
- "parameter": [
409
- {
410
- "key": "id",
411
- "value": "{{id}}",
412
- "schema": {
413
- "type": "string"
414
- },
415
- "not_null": 1,
416
- "param_id": "375b74ab9b006",
417
- "field_type": "string",
418
- "is_checked": 1,
419
- "description": ""
420
- }
421
- ],
422
- "query_add_equal": 1
423
- },
424
- "cookie": {
425
- "parameter": [],
426
- "cookie_encode": 1
427
- },
428
- "header": {
429
- "parameter": []
430
- },
431
- "restful": {
432
- "parameter": []
433
- },
434
- "pre_tasks": [],
435
- "post_tasks": []
436
- }
437
- }
438
- }
439
- }
440
- ]
299
+ "target_id": "1a9078f904007002",
300
+ "project_id": "1a8b7f4d6f51e002",
301
+ "parent_id": "1a9078d81a407002",
302
+ "target_type": "api"
303
+ }
441
304
  }
442
305
  ]
443
306
  }