zephyr-enterprise-tools 1.0.2 → 1.0.4

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": "zephyr-enterprise-tools",
3
- "version": "1.0.2",
3
+ "version": "1.0.4",
4
4
  "description": "Comprehensive Zephyr Enterprise Tools - Release Readiness, Project Health, Test Analytics & More",
5
5
  "main": "zephyr-enterprise-tools.js",
6
6
  "exports": {
@@ -919,42 +919,66 @@ export class QualityGates {
919
919
  async getTestCaseTrends(projectId, releaseId, options = {}) {
920
920
  const { days = 30 } = options;
921
921
 
922
- // Get executions
923
- const executionData = await this.GET("/execution", {
924
- releaseid: releaseId,
925
- offset: 0,
926
- pagesize: 10000,
927
- includeanyoneuser: true,
922
+ // Calculate start date for ZQL query
923
+ const now = new Date();
924
+ const startDate = new Date(now.getTime() - days * 24 * 60 * 60 * 1000);
925
+ const startDateStr = startDate.toISOString().split('T')[0]; // YYYY-MM-DD format
926
+
927
+ // Use v3 ZQL advanced search API to get executions within date range
928
+ const v3BaseUrl = this.baseUrl.replace('/latest', '/v3');
929
+ const url = new URL(`${v3BaseUrl}/advancesearch/zql`);
930
+
931
+ const requestBody = {
932
+ firstresult: 0,
933
+ maxresults: 10000,
934
+ entitytype: "execution",
935
+ order: "testcaseId",
936
+ isascorder: true,
937
+ is_cfield: false,
938
+ releaseid: String(releaseId),
939
+ projectid: String(projectId),
940
+ word: `executedOn > "${startDateStr}"`,
941
+ zql: true,
942
+ isOld: false
943
+ };
944
+
945
+ const res = await fetch(url.toString(), {
946
+ method: 'POST',
947
+ headers: { Accept: 'application/json', 'Content-Type': 'application/json', ...this.authHeader() },
948
+ body: JSON.stringify(requestBody),
928
949
  });
929
950
 
930
- const executions = executionData.results || executionData || [];
951
+ if (!res.ok) {
952
+ throw new Error(`ZQL API ${res.status}: ${await res.text()}`);
953
+ }
954
+
955
+ const responseData = await res.json();
956
+ const executions = responseData[0]?.results || [];
957
+ const totalCount = responseData[0]?.resultSize || executions.length;
931
958
 
932
959
  // Group executions by date
933
960
  const trendsByDate = {};
934
- const now = new Date();
935
- const startDate = new Date(now.getTime() - days * 24 * 60 * 60 * 1000);
936
961
 
937
962
  for (const exec of executions) {
938
- const executedOn = exec.lastTestResult?.executedOn || exec.executedOn;
963
+ // Use lastModifiedOn or createDatetime as execution date
964
+ const executedOn = exec.lastModifiedOn || exec.createDatetime;
939
965
  if (!executedOn) continue;
940
966
 
941
967
  const execDate = new Date(executedOn);
942
- if (execDate < startDate) continue;
943
-
944
968
  const dateKey = execDate.toISOString().split('T')[0];
945
969
 
946
970
  if (!trendsByDate[dateKey]) {
947
971
  trendsByDate[dateKey] = { passed: 0, failed: 0, blocked: 0, wip: 0, total: 0 };
948
972
  }
949
973
 
950
- const status = exec.lastTestResult?.executionStatus || exec.status || 0;
974
+ const status = exec.status || '0';
951
975
  trendsByDate[dateKey].total++;
952
976
 
953
- switch (Number(status)) {
954
- case 1: trendsByDate[dateKey].passed++; break;
955
- case 2: trendsByDate[dateKey].failed++; break;
956
- case 3: trendsByDate[dateKey].wip++; break;
957
- case 4: trendsByDate[dateKey].blocked++; break;
977
+ switch (String(status)) {
978
+ case '1': trendsByDate[dateKey].passed++; break;
979
+ case '2': trendsByDate[dateKey].failed++; break;
980
+ case '3': trendsByDate[dateKey].wip++; break;
981
+ case '4': trendsByDate[dateKey].blocked++; break;
958
982
  }
959
983
  }
960
984
 
@@ -979,11 +1003,12 @@ export class QualityGates {
979
1003
  timestamp: new Date().toISOString(),
980
1004
  period: {
981
1005
  days,
982
- from: startDate.toISOString().split('T')[0],
1006
+ from: startDateStr,
983
1007
  to: now.toISOString().split('T')[0],
984
1008
  },
985
1009
  summary: {
986
1010
  totalExecutionsInPeriod: totals.total,
1011
+ totalFromAPI: totalCount,
987
1012
  passed: totals.passed,
988
1013
  failed: totals.failed,
989
1014
  blocked: totals.blocked,