@mablhq/mabl-cli 2.41.1 → 2.45.2

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.
@@ -428,7 +428,7 @@ class MablApiClient extends basicApiClient_1.BasicApiClient {
428
428
  catch (error) {
429
429
  throw toApiError(`Failed to get Snippet [${snippetId}]. ${workspaceId
430
430
  ? `The Snippet was likely deleted. To recover this snippet, visit the activity feed [workspaces/${workspaceId}/settings/activity-log?activityLogEntity=snippet&activityLogEvent=delete]`
431
- : ''}`, error);
431
+ : 'The Snippet was likely deleted. To recover this snippet, visit the activity feed.'}`, error);
432
432
  }
433
433
  }
434
434
  async getBranchById(branchId) {
@@ -579,11 +579,12 @@ class MablApiClient extends basicApiClient_1.BasicApiClient {
579
579
  throw toApiError(`Failed to update mailbox ${mailboxId} with error`, error);
580
580
  }
581
581
  }
582
- async evaluateAiAssertion(workspaceId, testRunId, screenshot, userPrompt, metaPrompt, test) {
582
+ async evaluateAiAssertion(workspaceId, testRunId, screenshot, userPrompt, metaPrompt, criteria, test) {
583
583
  try {
584
584
  const body = {
585
585
  test_run_id: testRunId,
586
586
  assertion_prompt: userPrompt,
587
+ assertion_criteria: criteria,
587
588
  screenshot: Buffer.from(screenshot).toString('base64'),
588
589
  test_invariant_id: test === null || test === void 0 ? void 0 : test.invariant_id,
589
590
  test_type: test === null || test === void 0 ? void 0 : test.test_type,
@@ -139,10 +139,6 @@ class ChromiumBrowserEngine {
139
139
  plugins: {
140
140
  always_open_pdf_externally: true,
141
141
  },
142
- safebrowsing: {
143
- enabled: false,
144
- enhanced: false,
145
- },
146
142
  };
147
143
  if (windowPlacement) {
148
144
  preferences.browser = {
@@ -71,8 +71,6 @@ class ChromiumElementHandleDelegate {
71
71
  await this.enableOverlay();
72
72
  const nodeInfo = await ((_a = this.getInternalCDPSession()) === null || _a === void 0 ? void 0 : _a.send('DOM.describeNode', {
73
73
  objectId: this.getRemoteObjectId(),
74
- depth: -1,
75
- pierce: true,
76
74
  }));
77
75
  if (!nodeInfo) {
78
76
  return;
package/cli.js CHANGED
@@ -33,7 +33,6 @@ const constants_1 = require("./commands/constants");
33
33
  const middleware_1 = require("./middleware");
34
34
  const path_1 = __importDefault(require("path"));
35
35
  const fs_1 = __importDefault(require("fs"));
36
- require('v8-compile-cache');
37
36
  require('yargonaut').style('cyan').helpStyle('magenta').errorsStyle('red');
38
37
  const hasInternalDirectory = fs_1.default.existsSync(path_1.default.resolve(__dirname, 'commands', 'internal', 'internal_cmds'));
39
38
  const excludeInternal = !hasInternalDirectory ? { exclude: /.*/gm } : undefined;
@@ -30,8 +30,8 @@ const fs = __importStar(require("fs"));
30
30
  const path = __importStar(require("path"));
31
31
  const resourceUtil_1 = require("../../../util/resourceUtil");
32
32
  const OperatingSystemDescriptor_1 = require("../../../mablscript/types/OperatingSystemDescriptor");
33
- const UI_AUTOMATOR_VERSION = '2.35.0';
34
- const XCUITEST_VERSION = '5.12.2';
33
+ const UI_AUTOMATOR_VERSION = '3.7.6';
34
+ const XCUITEST_VERSION = '7.24.15';
35
35
  const addOnConfigKey = 'add-on';
36
36
  var AddOnOptions;
37
37
  (function (AddOnOptions) {
@@ -469,6 +469,10 @@ async function extractTestRunConfig(executionMessage, apiClient) {
469
469
  platformName: mobileMessage.mobile_device.platform,
470
470
  mobileAppFileId: mobileMessage.mobile_app_file_id,
471
471
  };
472
+ if (mobileMessage.mobile_device.platform === mablApi_1.MobilePlatformEnum.Ios) {
473
+ config.mobileConfig.platformVersion =
474
+ mobileMessage.mobile_device.os_version;
475
+ }
472
476
  }
473
477
  return config;
474
478
  }
@@ -3,8 +3,8 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.processPostmanItems = exports.createEmptyRequest = exports.createEmptyRequestEventArray = exports.splitLines = exports.PRE_REQUEST_LISTEN = exports.convertMablAssertionsToExecArray = exports.convertMablVariableAssignmentsToExecArray = exports.createMablGeneratedScripts = exports.insertMablAssertionScripts = exports.toPostmanScript = exports.replaceVariables = exports.getActualValue = exports.readBody = exports.getResponseContentType = exports.valueToUnquotedString = exports.humanizeAssertion = exports.getAssertionTargetArgument = exports.assertionHasTest = exports.isValidMablAssertion = exports.normalizeExpectedValue = exports.assertionRequiresValue = exports.filterValidMablAssertions = exports.filterValidMablVariableAssignments = exports.isValidMablVariableAssignment = exports.removeMablGeneratedScripts = exports.createEmptyRequestEvent = exports.findFirstMatchingEvent = exports.restoreCustomRequestFields = exports.deduplicateApiTestExecutionResults = exports.createEmptyVariable = exports.createEmptyAssertion = exports.humanizeAssertionType = exports.getAssertionTypesForTarget = exports.caseInsensitiveEquals = exports.compareStringsCaseInsensitive = exports.ASSERT_TYPES = exports.ASSERT_TARGETS = exports.COLLECTION_WITH_FOLDERS_ERROR = exports.HMAC_SHA1_SIGNATURE = exports.DEFAULT_ADD_OAUTH1_TO_HEADER_VALUE = exports.DEFAULT_OAUTH1_VERSION = exports.OAUTH1_AUTH = exports.NO_AUTH = exports.BEARER_TOKEN_AUTH = exports.BASIC_AUTH = exports.API_KEY_AUTH = exports.INHERIT_AUTH_FROM_PARENT_VALUE = exports.MABL_GENERATED_COMMENT = exports.MABL_GENERATED_ASSERTION_TOKEN = exports.TEST_LISTEN = void 0;
7
- exports.uuid = exports.createCommentForApiTestSnippet = exports.convertMablSnippetsToExecArray = exports.createPostmanScript = exports.processPostmanItem = exports.replaceRawScriptWithExecArray = exports.removeInvalidHeaders = exports.processItemAuth = exports.mablAuthToPostman = exports.formatContent = exports.getRequestMode = exports.getFormDataArray = exports.isText = exports.isXML = exports.isJson = exports.isSupportedAuthType = exports.isItemDefinition = exports.isCollectionDefinition = exports.isItemGroupDefinition = exports.isFolder = exports.validateCollectionFeaturesForApiTestEditor = exports.generateRawScriptField = void 0;
6
+ exports.createEmptyRequestEventArray = exports.splitLines = exports.PRE_REQUEST_LISTEN = exports.convertMablAssertionsToExecArray = exports.convertMablVariableAssignmentsToExecArray = exports.createMablGeneratedScripts = exports.insertMablAssertionScripts = exports.toPostmanScript = exports.replaceVariables = exports.getActualValue = exports.readBody = exports.getResponseContentType = exports.valueToUnquotedString = exports.assertionTypeSupportsCaseSensitivity = exports.assertionTargetSupportsCaseSensitivity = exports.humanizeAssertion = exports.getAssertionTargetArgument = exports.assertionHasTest = exports.isValidMablAssertion = exports.normalizeExpectedValue = exports.assertionRequiresValue = exports.filterValidMablAssertions = exports.filterValidMablVariableAssignments = exports.isValidMablVariableAssignment = exports.removeMablGeneratedScripts = exports.createEmptyRequestEvent = exports.findFirstMatchingEvent = exports.restoreCustomRequestFields = exports.deduplicateApiTestExecutionResults = exports.createEmptyVariable = exports.createEmptyAssertion = exports.humanizeAssertionType = exports.getAssertionTypesForTarget = exports.caseInsensitiveEquals = exports.compareStringsCaseInsensitive = exports.ASSERT_TYPES = exports.ASSERT_TARGETS = exports.COLLECTION_WITH_FOLDERS_ERROR = exports.HMAC_SHA1_SIGNATURE = exports.DEFAULT_ADD_OAUTH1_TO_HEADER_VALUE = exports.DEFAULT_OAUTH1_VERSION = exports.OAUTH1_AUTH = exports.NO_AUTH = exports.BEARER_TOKEN_AUTH = exports.BASIC_AUTH = exports.API_KEY_AUTH = exports.INHERIT_AUTH_FROM_PARENT_VALUE = exports.MABL_GENERATED_COMMENT = exports.MABL_GENERATED_ASSERTION_TOKEN = exports.TEST_LISTEN = void 0;
7
+ exports.uuid = exports.createCommentForApiTestSnippet = exports.convertMablSnippetsToExecArray = exports.createPostmanScript = exports.insertMablScriptsIntoCollection = exports.processPostmanItem = exports.replaceRawScriptWithExecArray = exports.removeInvalidHeaders = exports.processItemAuth = exports.mablAuthToPostman = exports.formatContent = exports.getRequestMode = exports.getFormDataArray = exports.isText = exports.isXML = exports.isJson = exports.isSupportedAuthType = exports.isItemDefinition = exports.isCollectionDefinition = exports.isItemGroupDefinition = exports.isFolder = exports.validateCollectionFeaturesForApiTestEditor = exports.generateRawScriptField = exports.processPostmanItems = exports.createEmptyRequest = void 0;
8
8
  const newman_types_1 = require("./newman-types");
9
9
  const lodash_1 = __importDefault(require("lodash"));
10
10
  const uuid_1 = require("uuid");
@@ -41,18 +41,36 @@ exports.ASSERT_TYPES = [
41
41
  { label: 'Not contains', value: newman_types_1.AssertionType.DoesNotContain },
42
42
  { label: 'Is present', value: newman_types_1.AssertionType.Present },
43
43
  { label: 'Not present', value: newman_types_1.AssertionType.NotPresent },
44
+ { label: 'Greater than', value: newman_types_1.AssertionType.GreaterThan },
45
+ {
46
+ label: 'Greater than or equal to',
47
+ value: newman_types_1.AssertionType.GreaterThanOrEqualTo,
48
+ },
49
+ { label: 'Less than', value: newman_types_1.AssertionType.LessThan },
50
+ { label: 'Less than or equal to', value: newman_types_1.AssertionType.LessThanOrEqualTo },
51
+ { label: 'Starts with', value: newman_types_1.AssertionType.StartsWith },
52
+ { label: 'Ends with', value: newman_types_1.AssertionType.EndsWith },
53
+ { label: 'Matches regular expression', value: newman_types_1.AssertionType.MatchesRegExp },
44
54
  ];
55
+ const EXPECTED_VALUE_TOKEN = '!!EXPECTED_VALUE!!';
45
56
  const EXPECT_FUNCTIONS = {
46
- Equals: 'eql',
47
- NotEquals: 'not.eql',
48
- Contains: 'include',
49
- DoesNotContain: 'not.include',
50
- Present: 'not.be.undefined',
51
- NotPresent: 'be.undefined',
57
+ Equals: `eql(${EXPECTED_VALUE_TOKEN})`,
58
+ NotEquals: `not.eql(${EXPECTED_VALUE_TOKEN})`,
59
+ Contains: `include(${EXPECTED_VALUE_TOKEN})`,
60
+ DoesNotContain: `not.include(${EXPECTED_VALUE_TOKEN})`,
61
+ Present: `not.be.undefined`,
62
+ NotPresent: `be.undefined`,
63
+ GreaterThan: `be.above(${EXPECTED_VALUE_TOKEN})`,
64
+ GreaterThanOrEqualTo: `be.at.least(${EXPECTED_VALUE_TOKEN})`,
65
+ LessThan: `be.below(${EXPECTED_VALUE_TOKEN})`,
66
+ LessThanOrEqualTo: `be.at.most(${EXPECTED_VALUE_TOKEN})`,
67
+ StartsWith: `satisfy(value => value.startsWith(${EXPECTED_VALUE_TOKEN}))`,
68
+ EndsWith: `satisfy(value => value.endsWith(${EXPECTED_VALUE_TOKEN}))`,
69
+ MatchesRegExp: `match(${EXPECTED_VALUE_TOKEN})`,
52
70
  };
53
71
  function compareStringsCaseInsensitive(a, b) {
54
- a = a === null || a === void 0 ? void 0 : a.toLowerCase();
55
- b = b === null || b === void 0 ? void 0 : b.toLowerCase();
72
+ a = a === null || a === void 0 ? void 0 : a.toUpperCase().toLowerCase();
73
+ b = b === null || b === void 0 ? void 0 : b.toUpperCase().toLowerCase();
56
74
  if (!a) {
57
75
  return -1;
58
76
  }
@@ -70,8 +88,14 @@ function getAssertionTypesForTarget(target) {
70
88
  switch (target) {
71
89
  case newman_types_1.AssertionTarget.Size:
72
90
  case newman_types_1.AssertionTarget.Status:
73
- return exports.ASSERT_TYPES.filter((assertType) => assertType.value === newman_types_1.AssertionType.Equals ||
74
- assertType.value === newman_types_1.AssertionType.NotEquals);
91
+ return exports.ASSERT_TYPES.filter((assertType) => [
92
+ newman_types_1.AssertionType.Equals,
93
+ newman_types_1.AssertionType.NotEquals,
94
+ newman_types_1.AssertionType.GreaterThan,
95
+ newman_types_1.AssertionType.GreaterThanOrEqualTo,
96
+ newman_types_1.AssertionType.LessThan,
97
+ newman_types_1.AssertionType.LessThanOrEqualTo,
98
+ ].includes(assertType.value));
75
99
  default:
76
100
  return exports.ASSERT_TYPES;
77
101
  }
@@ -87,6 +111,20 @@ function humanizeAssertionType(assertionType) {
87
111
  return 'is present';
88
112
  case 'NotPresent':
89
113
  return 'is not present';
114
+ case 'GreaterThan':
115
+ return 'greater than';
116
+ case 'GreaterThanOrEqualTo':
117
+ return 'greater than or equal to';
118
+ case 'LessThan':
119
+ return 'less than';
120
+ case 'LessThanOrEqualTo':
121
+ return 'less than or equal to';
122
+ case 'StartsWith':
123
+ return 'starts with';
124
+ case 'EndsWith':
125
+ return 'ends with';
126
+ case 'MatchesRegExp':
127
+ return 'matches regular expression';
90
128
  default:
91
129
  return assertionType.toString().toLowerCase();
92
130
  }
@@ -236,7 +274,7 @@ function normalizeExpectedValue(value) {
236
274
  if (value.match(/".*"/)) {
237
275
  return `pm.variables.replaceIn(${value})`;
238
276
  }
239
- const lower = value.toLowerCase();
277
+ const lower = value.toUpperCase().toLowerCase();
240
278
  if (lower === 'true' || lower === 'false' || !Number.isNaN(Number(value))) {
241
279
  return JSON.stringify(value);
242
280
  }
@@ -244,14 +282,15 @@ function normalizeExpectedValue(value) {
244
282
  }
245
283
  exports.normalizeExpectedValue = normalizeExpectedValue;
246
284
  function isValidMablAssertion(assertion) {
247
- var _a, _b, _c, _d, _e, _f, _g, _h;
285
+ var _a, _b, _c, _d, _e, _f;
248
286
  if (!assertion.assertType) {
249
287
  return false;
250
288
  }
251
289
  const assertTarget = assertion.assertTarget;
252
290
  const requiresValue = assertionRequiresValue(assertion);
253
291
  const expectedValue = normalizeExpectedValue(assertion.value);
254
- const hasRequiredValue = !requiresValue || ((_a = expectedValue === null || expectedValue === void 0 ? void 0 : expectedValue.length) !== null && _a !== void 0 ? _a : 0) > 0;
292
+ const hasExpectedValue = ((_a = expectedValue === null || expectedValue === void 0 ? void 0 : expectedValue.length) !== null && _a !== void 0 ? _a : 0) > 0;
293
+ const hasRequiredValue = !requiresValue || hasExpectedValue;
255
294
  let valid = false;
256
295
  switch (assertTarget) {
257
296
  case 'JSONBody':
@@ -259,19 +298,32 @@ function isValidMablAssertion(assertion) {
259
298
  valid = hasBodyPath && hasRequiredValue;
260
299
  break;
261
300
  case 'Status':
262
- valid = ((_e = expectedValue === null || expectedValue === void 0 ? void 0 : expectedValue.length) !== null && _e !== void 0 ? _e : 0) > 0;
301
+ valid = hasExpectedValue;
263
302
  break;
264
303
  case 'Header':
265
- const hasHeaderName = ((_g = (_f = assertion.headerName) === null || _f === void 0 ? void 0 : _f.length) !== null && _g !== void 0 ? _g : 0) > 0;
304
+ const hasHeaderName = ((_f = (_e = assertion.headerName) === null || _e === void 0 ? void 0 : _e.length) !== null && _f !== void 0 ? _f : 0) > 0;
266
305
  valid = hasHeaderName && hasRequiredValue;
267
306
  break;
268
307
  case 'Size':
269
- valid = ((_h = expectedValue === null || expectedValue === void 0 ? void 0 : expectedValue.length) !== null && _h !== void 0 ? _h : 0) > 0;
308
+ valid =
309
+ isValidSizeAssertionType(assertion.assertType) && hasExpectedValue;
270
310
  break;
271
311
  }
272
312
  return valid;
273
313
  }
274
314
  exports.isValidMablAssertion = isValidMablAssertion;
315
+ function isValidSizeAssertionType(assertType) {
316
+ switch (assertType) {
317
+ case newman_types_1.AssertionType.Equals:
318
+ case newman_types_1.AssertionType.NotEquals:
319
+ case newman_types_1.AssertionType.GreaterThan:
320
+ case newman_types_1.AssertionType.GreaterThanOrEqualTo:
321
+ case newman_types_1.AssertionType.LessThan:
322
+ case newman_types_1.AssertionType.LessThanOrEqualTo:
323
+ return true;
324
+ }
325
+ return false;
326
+ }
275
327
  function assertionHasTest(assertion) {
276
328
  if (!assertion.assertTarget || !assertion.assertType) {
277
329
  return false;
@@ -321,13 +373,14 @@ function generateAssertionScript(assertion) {
321
373
  const description = humanizeAssertion(assertion);
322
374
  const requiresValue = assertionRequiresValue(assertion);
323
375
  const expectedValue = normalizeExpectedValue(assertion.value);
376
+ const caseSensitive = assertion.caseSensitive !== false;
324
377
  switch (assertTarget) {
325
378
  case 'JSONBody':
326
- return generateJsonBodyAssertion(description, assertType, requiresValue, assertion.bodyPath, expectedValue);
379
+ return generateJsonBodyAssertion(description, assertType, requiresValue, assertion.bodyPath, expectedValue, caseSensitive);
327
380
  case 'Status':
328
381
  return generateStatusAssertion(description, assertType, expectedValue);
329
382
  case 'Header':
330
- return generateHeaderAssertion(description, assertType, assertion.headerName, expectedValue);
383
+ return generateHeaderAssertion(description, assertType, assertion.headerName, expectedValue, caseSensitive);
331
384
  case 'Size':
332
385
  return generateSizeAssertion(description, assertTarget, assertType, expectedValue);
333
386
  }
@@ -347,7 +400,7 @@ function generateVariableAssignmentScript(variable) {
347
400
  return generateSimpleVariableAssignment(variable.variableName, assertTarget);
348
401
  }
349
402
  }
350
- function generateJsonBodyAssertion(description, assertType, requiresValues, path, expectedValue) {
403
+ function generateJsonBodyAssertion(description, assertType, requiresValues, path, expectedValue, caseSensitive) {
351
404
  if (!(path === null || path === void 0 ? void 0 : path.trim().length) || (requiresValues && !(expectedValue === null || expectedValue === void 0 ? void 0 : expectedValue.length))) {
352
405
  return;
353
406
  }
@@ -355,12 +408,10 @@ function generateJsonBodyAssertion(description, assertType, requiresValues, path
355
408
  if (requiresValues) {
356
409
  propertyAccessor = valueToUnquotedString(propertyAccessor);
357
410
  }
358
- const expect = EXPECT_FUNCTIONS[assertType];
359
- let test = `pm.expect(${propertyAccessor}).to.${expect}`;
360
- if (requiresValues) {
361
- test += `(${expectedValue})`;
411
+ if (assertType === newman_types_1.AssertionType.MatchesRegExp) {
412
+ expectedValue = `new RegExp(${expectedValue})`;
362
413
  }
363
- return generatePostmanTest(description, test);
414
+ return generatePostmanAssertion(description, propertyAccessor, assertType, expectedValue, caseSensitive);
364
415
  }
365
416
  function generateJsonBodyVariableAssignment(variableName, path) {
366
417
  return generatePostmanVariableAssignment(variableName, getJsonBodyProperty(path));
@@ -385,34 +436,41 @@ function generateStatusAssertion(description, assertType, expectedValue) {
385
436
  return;
386
437
  }
387
438
  let expect;
388
- let test;
439
+ let target = 'pm.response.code';
389
440
  switch (assertType) {
390
441
  case 'Equals':
391
- expect = 'to.have.status';
442
+ expect = `pm.response.to.have.status(parseInt(${expectedValue}))`;
392
443
  break;
393
444
  case 'NotEquals':
394
- expect = 'to.not.have.status';
445
+ expect = `pm.response.to.not.have.status(parseInt(${expectedValue}))`;
395
446
  break;
396
447
  case 'Contains':
397
- expect = 'to.include';
398
- test = `pm.expect(pm.response.code.toString()).${expect}(${expectedValue})`;
399
- break;
400
448
  case 'DoesNotContain':
401
- expect = 'to.not.include';
402
- test = `pm.expect(pm.response.code.toString()).${expect}(${expectedValue})`;
449
+ case 'StartsWith':
450
+ case 'EndsWith':
451
+ target += '.toString()';
452
+ break;
453
+ case 'GreaterThan':
454
+ case 'GreaterThanOrEqualTo':
455
+ case 'LessThan':
456
+ case 'LessThanOrEqualTo':
457
+ expectedValue = `parseInt(${expectedValue})`;
458
+ break;
459
+ case 'MatchesRegExp':
460
+ target += '.toString()';
461
+ expectedValue = `new RegExp(${expectedValue})`;
403
462
  break;
404
463
  default:
405
464
  throw new Error(`Unexpected status assert type: ${assertType}`);
406
465
  }
407
- return generatePostmanTest(description, test !== null && test !== void 0 ? test : `pm.response.${expect}(parseInt(${expectedValue}))`);
466
+ return generatePostmanTest(description, expect !== null && expect !== void 0 ? expect : generatePostmanExpect(target, assertType, expectedValue));
408
467
  }
409
- function generateHeaderAssertion(description, assertType, headerName, expectedValue) {
468
+ function generateHeaderAssertion(description, assertType, headerName, expectedValue, caseSensitive) {
410
469
  if (!headerName) {
411
470
  return;
412
471
  }
413
472
  const normalizedHeaderName = JSON.stringify(headerName);
414
473
  let test;
415
- const expect = EXPECT_FUNCTIONS[assertType];
416
474
  switch (assertType) {
417
475
  case 'Present':
418
476
  test = `pm.response.to.have.header(${normalizedHeaderName})`;
@@ -421,27 +479,39 @@ function generateHeaderAssertion(description, assertType, headerName, expectedVa
421
479
  test = `pm.response.to.not.have.header(${normalizedHeaderName})`;
422
480
  break;
423
481
  case 'Equals':
424
- break;
425
482
  case 'NotEquals':
426
- break;
427
483
  case 'Contains':
428
- break;
429
484
  case 'DoesNotContain':
485
+ case 'StartsWith':
486
+ case 'EndsWith':
487
+ break;
488
+ case 'MatchesRegExp':
489
+ expectedValue = `new RegExp(${expectedValue})`;
430
490
  break;
491
+ case 'GreaterThan':
492
+ case 'GreaterThanOrEqualTo':
493
+ case 'LessThan':
494
+ case 'LessThanOrEqualTo':
495
+ return;
431
496
  default:
432
497
  throw new Error(`Unexpected header assert type: ${assertType}`);
433
498
  }
434
- return generatePostmanTest(description, test !== null && test !== void 0 ? test : `pm.expect(pm.response.headers.get(${normalizedHeaderName})).to.${expect}(${expectedValue})`);
499
+ return generatePostmanTest(description, test !== null && test !== void 0 ? test : generatePostmanExpect(`pm.response.headers.get(${normalizedHeaderName})`, assertType, expectedValue, caseSensitive));
435
500
  }
436
501
  function generateSizeAssertion(description, target, type, expectedValue) {
437
502
  if (!(expectedValue === null || expectedValue === void 0 ? void 0 : expectedValue.length)) {
438
503
  return;
439
504
  }
440
- return generateSimpleAssertion(description, target, type, `parseInt(${expectedValue})`);
505
+ if (type === newman_types_1.AssertionType.MatchesRegExp) {
506
+ expectedValue = `new RegExp(${expectedValue})`;
507
+ }
508
+ else {
509
+ expectedValue = `parseInt(${expectedValue})`;
510
+ }
511
+ return generateSimpleAssertion(description, target, type, expectedValue);
441
512
  }
442
- function generateSimpleAssertion(description, target, type, expectedValue) {
443
- const expect = EXPECT_FUNCTIONS[type];
444
- return generatePostmanTest(description, `pm.expect(${getResponseProperty(target)}).to.${expect}(${expectedValue})`);
513
+ function generateSimpleAssertion(description, target, type, expectedValue, caseSensitive = true) {
514
+ return generatePostmanTest(description, generatePostmanExpect(getResponseProperty(target), type, expectedValue, caseSensitive));
445
515
  }
446
516
  function generateSimpleVariableAssignment(name, target) {
447
517
  return generatePostmanVariableAssignment(name, getResponseProperty(target));
@@ -453,6 +523,40 @@ function getResponseProperty(target) {
453
523
  }
454
524
  return `pm.response.${property}`;
455
525
  }
526
+ function generatePostmanAssertion(description, target, assertType, expectedValue, caseSensitive) {
527
+ return generatePostmanTest(description, generatePostmanExpect(target, assertType, expectedValue, caseSensitive));
528
+ }
529
+ function generatePostmanExpect(target, assertType, expectedValue, caseSensitive = true) {
530
+ if (!caseSensitive && assertionTypeSupportsCaseSensitivity(assertType)) {
531
+ target += '?.toUpperCase().toLowerCase()';
532
+ expectedValue = `${expectedValue !== null && expectedValue !== void 0 ? expectedValue : ''}.toUpperCase().toLowerCase()`;
533
+ }
534
+ return `pm.expect(${target}).to.${EXPECT_FUNCTIONS[assertType].replace(new RegExp(EXPECTED_VALUE_TOKEN, 'g'), expectedValue !== null && expectedValue !== void 0 ? expectedValue : '')}`;
535
+ }
536
+ function assertionTargetSupportsCaseSensitivity(assertTarget) {
537
+ switch (assertTarget) {
538
+ case 'Header':
539
+ case 'JSONBody':
540
+ return true;
541
+ default:
542
+ return false;
543
+ }
544
+ }
545
+ exports.assertionTargetSupportsCaseSensitivity = assertionTargetSupportsCaseSensitivity;
546
+ function assertionTypeSupportsCaseSensitivity(assertionType) {
547
+ switch (assertionType) {
548
+ case 'Contains':
549
+ case 'DoesNotContain':
550
+ case 'StartsWith':
551
+ case 'EndsWith':
552
+ case 'Equals':
553
+ case 'NotEquals':
554
+ return true;
555
+ default:
556
+ return false;
557
+ }
558
+ }
559
+ exports.assertionTypeSupportsCaseSensitivity = assertionTypeSupportsCaseSensitivity;
456
560
  function generatePostmanTest(description, test) {
457
561
  return `pm.test(${JSON.stringify(description)}, function () { ${test}; });`;
458
562
  }
@@ -856,17 +960,36 @@ function replaceRawScriptWithExecArray(eventsContainer, processingForRepair) {
856
960
  });
857
961
  }
858
962
  exports.replaceRawScriptWithExecArray = replaceRawScriptWithExecArray;
859
- function processPostmanItem(item, processingForRepair) {
963
+ function processPostmanItem(item) {
860
964
  if (!item.id) {
861
965
  item.id = (0, uuid_1.v4)();
862
966
  }
863
967
  processMablProtocolProfileBehavior(item);
864
968
  processItemAuth(item);
865
969
  removeInvalidHeaders(item);
866
- replaceRawScriptWithExecArray(item, processingForRepair);
867
- insertMablAssertionScripts(item);
868
970
  }
869
971
  exports.processPostmanItem = processPostmanItem;
972
+ function insertMablScriptsIntoCollection(collection, getSnippet) {
973
+ var _a, _b;
974
+ (_a = collection.event) === null || _a === void 0 ? void 0 : _a.forEach((event) => insertMablScriptsIntoEvent(event, getSnippet));
975
+ (_b = collection.item) === null || _b === void 0 ? void 0 : _b.forEach((item) => {
976
+ var _a;
977
+ return (_a = item.event) === null || _a === void 0 ? void 0 : _a.forEach((event) => insertMablScriptsIntoEvent(event, getSnippet));
978
+ });
979
+ }
980
+ exports.insertMablScriptsIntoCollection = insertMablScriptsIntoCollection;
981
+ function insertMablScriptsIntoEvent(event, getSnippet) {
982
+ var _a;
983
+ removeMablGeneratedScripts(event);
984
+ const mablScripts = createPostmanScript(convertMablSnippetsToExecArray(event, getSnippet), createMablGeneratedScripts(event));
985
+ if (!((_a = event.mablSnippets) === null || _a === void 0 ? void 0 : _a.length)) {
986
+ mablScripts.exec = [...event.script.exec, ...mablScripts.exec];
987
+ }
988
+ event.script = mablScripts;
989
+ delete event.mablAssertions;
990
+ delete event.mablSnippets;
991
+ delete event.mablVariables;
992
+ }
870
993
  function createPostmanScript(...scripts) {
871
994
  return {
872
995
  id: (0, exports.uuid)(),
@@ -12,10 +12,17 @@ var AssertionType;
12
12
  (function (AssertionType) {
13
13
  AssertionType["Contains"] = "Contains";
14
14
  AssertionType["DoesNotContain"] = "DoesNotContain";
15
+ AssertionType["EndsWith"] = "EndsWith";
15
16
  AssertionType["Equals"] = "Equals";
17
+ AssertionType["GreaterThan"] = "GreaterThan";
18
+ AssertionType["GreaterThanOrEqualTo"] = "GreaterThanOrEqualTo";
19
+ AssertionType["LessThan"] = "LessThan";
20
+ AssertionType["LessThanOrEqualTo"] = "LessThanOrEqualTo";
21
+ AssertionType["MatchesRegExp"] = "MatchesRegExp";
16
22
  AssertionType["NotEquals"] = "NotEquals";
17
23
  AssertionType["NotPresent"] = "NotPresent";
18
24
  AssertionType["Present"] = "Present";
25
+ AssertionType["StartsWith"] = "StartsWith";
19
26
  })(AssertionType || (exports.AssertionType = AssertionType = {}));
20
27
  exports.SUPPORTED_COLLECTION_SCHEMA = 'https://schema.getpostman.com/json/collection/v2.1.0/collection.json';
21
28
  exports.MablSupportedPostmanAuthTypes = [
@@ -118,9 +118,10 @@ function createAssertFailureMessage(assertFailure) {
118
118
  exports.createAssertFailureMessage = createAssertFailureMessage;
119
119
  function createAssertResultMessage(assertResult) {
120
120
  if (assertResult) {
121
- const { success } = assertResult;
121
+ const { success, assertionCriteria } = assertResult;
122
122
  return {
123
123
  success,
124
+ assertionCriteria,
124
125
  ...createAssertFailureMessage(assertResult),
125
126
  };
126
127
  }