From 118ad6c45e1fe6eacb1fd595bd4d009e0c9ab552 Mon Sep 17 00:00:00 2001 From: "prashanth.rajappa" Date: Thu, 26 Sep 2024 14:54:11 +0400 Subject: [PATCH] feat: Added testcycle improvements --- Readme.md | 5 +++-- src/config.ts | 3 ++- src/qmetry-cucumber.ts | 36 +++++++++++++++++++++++++++++++----- src/types.ts | 1 + 4 files changed, 37 insertions(+), 8 deletions(-) diff --git a/Readme.md b/Readme.md index 2751f16..4303e08 100644 --- a/Readme.md +++ b/Readme.md @@ -18,12 +18,13 @@ Create `qmetry.config.json` file in the test project's root folder and add the b "baseUrl": "https://", "apiKey": "", "authorization": "", - "projectId": + "projectId": , + "testCycleId": , "summary": "", "description": "" } ``` -Here, `summary` and `description` fields are optional. +Here, `testCycleId`, `summary` and `description` fields are optional. #### Feature ``` diff --git a/src/config.ts b/src/config.ts index b8494cd..c44cf39 100644 --- a/src/config.ts +++ b/src/config.ts @@ -27,8 +27,9 @@ export const getConfig = async () => { apiKey: data?.apiKey, authorization: data?.authorization, projectId: data?.projectId, + testCycleId: data?.testCycleId, summary: data?.summary || 'Test Cycle Summary', - description: data?.description || 'Automated status update using qmetry-cucumber', + description: data?.description || 'Automated status update using qmetry-cucumber' }; } catch (error) { console.error('Error fetching configuration:', error); diff --git a/src/qmetry-cucumber.ts b/src/qmetry-cucumber.ts index f92e4ac..99d1c14 100644 --- a/src/qmetry-cucumber.ts +++ b/src/qmetry-cucumber.ts @@ -4,11 +4,15 @@ import { getConfig } from './config'; import { delay, checkStatusId } from './utils'; export async function updateQmetryStatus (name: string, status?: TestStepResultStatus) { + const config = await getConfig(); + + let testCycleId; + + testCycleId = config.testCycleId?.trim() || (await createTestCycle())[0]; + const isValid = await validateTestCycleId(testCycleId); + + if (!isValid) testCycleId = (await createTestCycle())[0]; - const testCycleId = await createTestCycle().then((data) => { - return data[0]; - }); - linkAllTestCases(testCycleId); const matches = name.match(/\[.*?\]/g); @@ -218,4 +222,26 @@ export async function linkAllTestCases(testCycleId: string): Promise { .catch((error) => { console.error('Error linking test cases:', error); }); -} \ No newline at end of file +} + +export async function validateTestCycleId(testCycleId: string): Promise { + const config = await getConfig(); + + const url = `${config.baseUrl}/rest/qtm4j/ui/latest/testcycles/${testCycleId}`; + + const headers = { + 'Content-Type': 'application/json', + 'apiKey': `${config.apiKey}`, + 'Authorization': `${config.authorization}` + }; + + const response = await axios.get(url, { headers }) + .then((response) => { + return response.status === 200; + }) + .catch((error) => { + return false; + }); + + return response; +} diff --git a/src/types.ts b/src/types.ts index aadc123..4317b5a 100644 --- a/src/types.ts +++ b/src/types.ts @@ -69,6 +69,7 @@ export interface QmetryConfig { apiKey: string; authorization: string; projectId: number; + testCycleId?: string; summary?: string; description?: string; } \ No newline at end of file