Skip to content

Commit

Permalink
Merge pull request #6 from prashanth-sams/testcycle
Browse files Browse the repository at this point in the history
feat: Added testcycle improvements
  • Loading branch information
prashanth-sams authored Sep 26, 2024
2 parents 9934727 + 118ad6c commit 9a5fb12
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 8 deletions.
5 changes: 3 additions & 2 deletions Readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,13 @@ Create `qmetry.config.json` file in the test project's root folder and add the b
"baseUrl": "https://<your base url>",
"apiKey": "<project api key>",
"authorization": "<jira auth creds encoded by base64>",
"projectId": <your project id>
"projectId": <your project id>,
"testCycleId": <your test cycle id>,
"summary": "<test summary>",
"description": "<test description>"
}
```
Here, `summary` and `description` fields are optional.
Here, `testCycleId`, `summary` and `description` fields are optional.

#### Feature
```
Expand Down
3 changes: 2 additions & 1 deletion src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
36 changes: 31 additions & 5 deletions src/qmetry-cucumber.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -218,4 +222,26 @@ export async function linkAllTestCases(testCycleId: string): Promise<void> {
.catch((error) => {
console.error('Error linking test cases:', error);
});
}
}

export async function validateTestCycleId(testCycleId: string): Promise<boolean> {
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;
}
1 change: 1 addition & 0 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ export interface QmetryConfig {
apiKey: string;
authorization: string;
projectId: number;
testCycleId?: string;
summary?: string;
description?: string;
}

0 comments on commit 9a5fb12

Please sign in to comment.