testit-js-commons 3.7.6 → 3.7.8

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.
@@ -6,6 +6,7 @@ exports.escapeHtmlInObjectArray = escapeHtmlInObjectArray;
6
6
  const NO_ESCAPE_HTML_ENV_VAR = 'NO_ESCAPE_HTML';
7
7
  // Regex pattern to detect HTML tags
8
8
  const HTML_TAG_PATTERN = /<\S.*?(?:>|\/>)/;
9
+ const NO_ESCAPE_KEYS = new Set(['externalId', 'autoTestExternalId']);
9
10
  // Regex patterns to escape only non-escaped characters
10
11
  const LESS_THAN_PATTERN = /</;
11
12
  const GREATER_THAN_PATTERN = />/;
@@ -85,6 +86,9 @@ function processProperties(obj) {
85
86
  try {
86
87
  const value = obj[key];
87
88
  if (typeof value === 'string') {
89
+ if (NO_ESCAPE_KEYS.has(key)) {
90
+ continue;
91
+ }
88
92
  // Escape string properties
89
93
  obj[key] = escapeHtmlTags(value);
90
94
  }
@@ -9,17 +9,17 @@ describe('HtmlEscapeUtils', () => {
9
9
  describe('escapeHtmlTags', () => {
10
10
  it('should escape < and > characters', () => {
11
11
  const input = 'Hello <script>alert("XSS")</script> world';
12
- const expected = 'Hello \\<script\\>alert("XSS")\\</script\\> world';
12
+ const expected = 'Hello &lt;script&gt;alert("XSS")</script> world';
13
13
  expect((0, html_escape_util_1.escapeHtmlTags)(input)).toBe(expected);
14
14
  });
15
15
  it('should not escape already escaped characters', () => {
16
16
  const input = 'Already \\<escaped\\> tags';
17
- const expected = 'Already \\<escaped\\> tags';
17
+ const expected = 'Already \\&lt;escaped\\&gt; tags';
18
18
  expect((0, html_escape_util_1.escapeHtmlTags)(input)).toBe(expected);
19
19
  });
20
20
  it('should handle mixed escaped and unescaped characters', () => {
21
21
  const input = 'Mixed \\<escaped\\> and <unescaped> tags';
22
- const expected = 'Mixed \\<escaped\\> and \\<unescaped\\> tags';
22
+ const expected = 'Mixed \\&lt;escaped\\&gt; and <unescaped> tags';
23
23
  expect((0, html_escape_util_1.escapeHtmlTags)(input)).toBe(expected);
24
24
  });
25
25
  it('should return null for null input', () => {
@@ -45,17 +45,17 @@ describe('HtmlEscapeUtils', () => {
45
45
  });
46
46
  it('should escape only when HTML tags are present', () => {
47
47
  const input = 'Price < $100 and <script>alert("test")</script>';
48
- const expected = 'Price \\< $100 and \\<script\\>alert("test")\\</script\\>';
48
+ const expected = 'Price &lt; $100 and <script&gt;alert("test")</script>';
49
49
  expect((0, html_escape_util_1.escapeHtmlTags)(input)).toBe(expected);
50
50
  });
51
51
  it('should detect self-closing tags', () => {
52
52
  const input = 'Image: <img src="test.jpg"/> and text';
53
- const expected = 'Image: \\<img src="test.jpg"/\\> and text';
53
+ const expected = 'Image: &lt;img src="test.jpg"/&gt; and text';
54
54
  expect((0, html_escape_util_1.escapeHtmlTags)(input)).toBe(expected);
55
55
  });
56
56
  it('should detect tags with attributes', () => {
57
57
  const input = 'Link: <a href="http://example.com">click here</a>';
58
- const expected = 'Link: \\<a href="http://example.com"\\>click here\\</a\\>';
58
+ const expected = 'Link: &lt;a href="http://example.com"&gt;click here</a>';
59
59
  expect((0, html_escape_util_1.escapeHtmlTags)(input)).toBe(expected);
60
60
  });
61
61
  it('should not process malformed tags without proper structure', () => {
@@ -71,10 +71,21 @@ describe('HtmlEscapeUtils', () => {
71
71
  count: 123
72
72
  };
73
73
  const result = (0, html_escape_util_1.escapeHtmlInObject)(input);
74
- expect(result.name).toBe('Test \\<script\\>');
75
- expect(result.description).toBe('Description with \\<tags\\>');
74
+ expect(result.name).toBe('Test &lt;script&gt;');
75
+ expect(result.description).toBe('Description with &lt;tags&gt;');
76
76
  expect(result.count).toBe(123);
77
77
  });
78
+ it('should not escape externalId and autoTestExternalId', () => {
79
+ const input = {
80
+ externalId: '<test>',
81
+ autoTestExternalId: '<auto>',
82
+ name: 'Name <b>bold</b>',
83
+ };
84
+ const result = (0, html_escape_util_1.escapeHtmlInObject)(input);
85
+ expect(result.externalId).toBe('<test>');
86
+ expect(result.autoTestExternalId).toBe('<auto>');
87
+ expect(result.name).toBe('Name &lt;b&gt;bold</b>');
88
+ });
78
89
  it('should handle nested objects', () => {
79
90
  const input = {
80
91
  title: 'Main <title>',
@@ -84,8 +95,8 @@ describe('HtmlEscapeUtils', () => {
84
95
  }
85
96
  };
86
97
  const result = (0, html_escape_util_1.escapeHtmlInObject)(input);
87
- expect(result.title).toBe('Main \\<title\\>');
88
- expect(result.nested.subtitle).toBe('Sub \\<title\\>');
98
+ expect(result.title).toBe('Main &lt;title&gt;');
99
+ expect(result.nested.subtitle).toBe('Sub &lt;title&gt;');
89
100
  expect(result.nested.value).toBe(42);
90
101
  });
91
102
  it('should handle arrays of strings', () => {
@@ -93,7 +104,7 @@ describe('HtmlEscapeUtils', () => {
93
104
  tags: ['<tag1>', '<tag2>', 'normal']
94
105
  };
95
106
  const result = (0, html_escape_util_1.escapeHtmlInObject)(input);
96
- expect(result.tags).toEqual(['\\<tag1\\>', '\\<tag2\\>', 'normal']);
107
+ expect(result.tags).toEqual(['&lt;tag1&gt;', '&lt;tag2&gt;', 'normal']);
97
108
  });
98
109
  it('should handle arrays of objects', () => {
99
110
  const input = {
@@ -103,8 +114,8 @@ describe('HtmlEscapeUtils', () => {
103
114
  ]
104
115
  };
105
116
  const result = (0, html_escape_util_1.escapeHtmlInObject)(input);
106
- expect(result.items[0].name).toBe('\\<item1\\>');
107
- expect(result.items[1].name).toBe('\\<item2\\>');
117
+ expect(result.items[0].name).toBe('&lt;item1&gt;');
118
+ expect(result.items[1].name).toBe('&lt;item2&gt;');
108
119
  });
109
120
  it('should handle null and undefined values', () => {
110
121
  const input = {
@@ -115,7 +126,7 @@ describe('HtmlEscapeUtils', () => {
115
126
  const result = (0, html_escape_util_1.escapeHtmlInObject)(input);
116
127
  expect(result.nullValue).toBeNull();
117
128
  expect(result.undefinedValue).toBeUndefined();
118
- expect(result.text).toBe('\\<script\\>');
129
+ expect(result.text).toBe('&lt;script&gt;');
119
130
  });
120
131
  it('should return null for null input', () => {
121
132
  expect((0, html_escape_util_1.escapeHtmlInObject)(null)).toBeNull();
@@ -136,7 +147,7 @@ describe('HtmlEscapeUtils', () => {
136
147
  name: 'Test <script>'
137
148
  };
138
149
  const result = (0, html_escape_util_1.escapeHtmlInObject)(input);
139
- expect(result.name).toBe('Test \\<script\\>');
150
+ expect(result.name).toBe('Test &lt;script&gt;');
140
151
  });
141
152
  it('should handle simple types without modification', () => {
142
153
  expect((0, html_escape_util_1.escapeHtmlInObject)('simple string')).toBe('simple string');
@@ -152,9 +163,9 @@ describe('HtmlEscapeUtils', () => {
152
163
  { name: '<item2>', value: 2 }
153
164
  ];
154
165
  const result = (0, html_escape_util_1.escapeHtmlInObjectArray)(input);
155
- expect(result === null || result === void 0 ? void 0 : result[0].name).toBe('\\<item1\\>');
166
+ expect(result === null || result === void 0 ? void 0 : result[0].name).toBe('&lt;item1&gt;');
156
167
  expect(result === null || result === void 0 ? void 0 : result[0].value).toBe(1);
157
- expect(result === null || result === void 0 ? void 0 : result[1].name).toBe('\\<item2\\>');
168
+ expect(result === null || result === void 0 ? void 0 : result[1].name).toBe('&lt;item2&gt;');
158
169
  expect(result === null || result === void 0 ? void 0 : result[1].value).toBe(2);
159
170
  });
160
171
  it('should return null for null input', () => {
@@ -190,10 +201,10 @@ describe('HtmlEscapeUtils', () => {
190
201
  }
191
202
  ];
192
203
  const result = (0, html_escape_util_1.escapeHtmlInObjectArray)(input);
193
- expect(result === null || result === void 0 ? void 0 : result[0].title).toBe('\\<Title\\>');
194
- expect(result === null || result === void 0 ? void 0 : result[0].items).toEqual(['\\<tag1\\>', '\\<tag2\\>']);
195
- expect(result === null || result === void 0 ? void 0 : result[0].nested.subtitle).toBe('\\<Subtitle\\>');
196
- expect(result === null || result === void 0 ? void 0 : result[0].nested.data[0].field).toBe('\\<Field\\>');
204
+ expect(result === null || result === void 0 ? void 0 : result[0].title).toBe('&lt;Title&gt;');
205
+ expect(result === null || result === void 0 ? void 0 : result[0].items).toEqual(['&lt;tag1&gt;', '&lt;tag2&gt;']);
206
+ expect(result === null || result === void 0 ? void 0 : result[0].nested.subtitle).toBe('&lt;Subtitle&gt;');
207
+ expect(result === null || result === void 0 ? void 0 : result[0].nested.data[0].field).toBe('&lt;Field&gt;');
197
208
  });
198
209
  });
199
210
  describe('Edge cases and error handling', () => {
@@ -217,7 +228,7 @@ describe('HtmlEscapeUtils', () => {
217
228
  name: '<test>'
218
229
  };
219
230
  const result = (0, html_escape_util_1.escapeHtmlInObject)(maliciousObj);
220
- expect(result.name).toBe('\\<test\\>');
231
+ expect(result.name).toBe('&lt;test&gt;');
221
232
  });
222
233
  it('should handle mixed content with and without HTML tags', () => {
223
234
  const mixedContent = {
@@ -227,7 +238,7 @@ describe('HtmlEscapeUtils', () => {
227
238
  };
228
239
  const result = (0, html_escape_util_1.escapeHtmlInObject)(mixedContent);
229
240
  expect(result.safeText).toBe('Price: 10 < 20'); // No escaping
230
- expect(result.htmlContent).toBe('Click \\<button\\>here\\</button\\>'); // Escaped
241
+ expect(result.htmlContent).toBe('Click &lt;button&gt;here</button>'); // Escaped
231
242
  expect(result.mathExpression).toBe('Result: x > 5'); // No escaping
232
243
  });
233
244
  });
@@ -82,21 +82,23 @@ class AutotestsService extends common_1.BaseService {
82
82
  }
83
83
  loadAutotest(autotest, status) {
84
84
  return __awaiter(this, void 0, void 0, function* () {
85
+ var _a, _b;
85
86
  const originAutotest = yield this.getAutotestByExternalId(autotest.externalId);
86
87
  if (!originAutotest) {
87
88
  yield this.createAutotest(autotest);
88
89
  return;
89
90
  }
91
+ const mergedAutotest = Object.assign(Object.assign({}, autotest), { namespace: (_a = autotest.namespace) !== null && _a !== void 0 ? _a : originAutotest.namespace, classname: (_b = autotest.classname) !== null && _b !== void 0 ? _b : originAutotest.classname });
90
92
  switch (status) {
91
93
  case autotests_type_1.Status.PASSED:
92
- yield this.updateAutotest(autotest);
94
+ yield this.updateAutotest(mergedAutotest);
93
95
  return;
94
96
  case autotests_type_1.Status.FAILED:
95
- yield this.updateAutotestFromFailed(originAutotest, autotest);
97
+ yield this.updateAutotestFromFailed(originAutotest, mergedAutotest);
96
98
  return;
97
99
  case autotests_type_1.Status.SKIPPED:
98
100
  if (originAutotest.name != undefined && originAutotest.externalId != undefined) {
99
- yield this.updateAutotestFromFailed(originAutotest, autotest);
101
+ yield this.updateAutotestFromFailed(originAutotest, mergedAutotest);
100
102
  return;
101
103
  }
102
104
  console.log(`Cannot update skipped autotest ${autotest.name} without name or externalId`);
@@ -10,7 +10,8 @@ class TestResultsConverter extends common_1.BaseConverter {
10
10
  const model = {
11
11
  testRunIds: [this.config.testRunId],
12
12
  configurationIds: [this.config.configurationId],
13
- statusCodes: ["InProgress"],
13
+ statusTypes: ["InProgress"],
14
+ statusCodes: undefined,
14
15
  outcomes: undefined,
15
16
  failureCategories: undefined,
16
17
  namespace: undefined,
@@ -1,5 +1,5 @@
1
1
  import { AutoTestResultsForTestRunModel, TestRunState, TestRunV2ApiResult } from "testit-api-client";
2
- import { BaseConverter, AdapterConfig } from "../../common";
2
+ import { BaseConverter, AdapterConfig, Outcome } from "../../common";
3
3
  import { AutotestResult, RunState, TestRunGet } from "./testruns.type";
4
4
  export interface ITestRunConverter {
5
5
  toOriginState(state: RunState): TestRunState;
@@ -12,6 +12,7 @@ export declare class TestRunConverter extends BaseConverter implements ITestRunC
12
12
  constructor(config: AdapterConfig);
13
13
  toLocalState(state: TestRunState): RunState;
14
14
  toOriginState(state: RunState): TestRunState;
15
+ mapToStatusType(status: Outcome): string;
15
16
  toOriginAutotestResult(autotest: AutotestResult): AutoTestResultsForTestRunModel;
16
17
  toLocalTestRun(testRun: TestRunV2ApiResult): TestRunGet;
17
18
  }
@@ -17,13 +17,23 @@ class TestRunConverter extends common_1.BaseConverter {
17
17
  // @ts-ignore
18
18
  return testit_api_client_1.TestRunState[state];
19
19
  }
20
+ mapToStatusType(status) {
21
+ const statusMap = {
22
+ Passed: "Succeeded",
23
+ Failed: "Failed",
24
+ Blocked: "Incomplete",
25
+ Skipped: "Incomplete"
26
+ };
27
+ return statusMap[status];
28
+ }
20
29
  toOriginAutotestResult(autotest) {
21
30
  var _a, _b, _c, _d;
22
31
  const model = {
23
32
  configurationId: this.config.configurationId,
24
33
  autoTestExternalId: autotest.autoTestExternalId,
25
34
  links: (_a = autotest.links) === null || _a === void 0 ? void 0 : _a.map((link) => this.toOriginLink(link)),
26
- statusCode: autotest.outcome,
35
+ statusType: this.mapToStatusType(autotest.outcome),
36
+ statusCode: null,
27
37
  stepResults: (_b = autotest.stepResults) === null || _b === void 0 ? void 0 : _b.map((step) => this.toOriginStep(step)),
28
38
  setupResults: (_c = autotest.setupResults) === null || _c === void 0 ? void 0 : _c.map((step) => this.toOriginStep(step)),
29
39
  teardownResults: (_d = autotest.teardownResults) === null || _d === void 0 ? void 0 : _d.map((step) => this.toOriginStep(step)),
@@ -12,5 +12,5 @@ export declare class TestRunsService extends BaseService implements ITestRunsSer
12
12
  updateTestRun(testRun: TestRunGet): Promise<void>;
13
13
  startTestRun(testRunId: TestRunId): Promise<void>;
14
14
  completeTestRun(testRunId: TestRunId): Promise<void>;
15
- loadAutotests(testRunId: string, autotests: Array<AutotestResult>): Promise<void>;
15
+ loadAutotests(testRunId: string, results: Array<AutotestResult>): Promise<void>;
16
16
  }
@@ -138,11 +138,11 @@ class TestRunsService extends common_1.BaseService {
138
138
  }
139
139
  });
140
140
  }
141
- loadAutotests(testRunId, autotests) {
141
+ loadAutotests(testRunId, results) {
142
142
  return __awaiter(this, void 0, void 0, function* () {
143
- const autotestResults = autotests.map((test) => this._converter.toOriginAutotestResult(test));
144
- (0, utils_1.escapeHtmlInObjectArray)(autotestResults);
145
- for (const autotestResult of autotestResults) {
143
+ const autotestResultsForTestRun = results.map((result) => this._converter.toOriginAutotestResult(result));
144
+ (0, utils_1.escapeHtmlInObjectArray)(autotestResultsForTestRun);
145
+ for (const autotestResult of autotestResultsForTestRun) {
146
146
  yield this._client.setAutoTestResultsForTestRun(testRunId, { autoTestResultsForTestRunModel: [autotestResult] });
147
147
  }
148
148
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "testit-js-commons",
3
- "version": "3.7.6",
3
+ "version": "3.7.8",
4
4
  "description": "JavaScript commons for Test IT",
5
5
  "main": "lib/index.js",
6
6
  "types": "lib/index.d.ts",
@@ -37,7 +37,7 @@
37
37
  },
38
38
  "dependencies": {
39
39
  "dotenv": "^16.0.3",
40
- "testit-api-client": "7.2.1"
40
+ "testit-api-client": "7.2.6"
41
41
  },
42
42
  "files": [
43
43
  "lib"