Skip to content

Commit

Permalink
Bump cypress-xray-plugin from 7.3.0 to 7.4.0 (#390)
Browse files Browse the repository at this point in the history
* Cleanup

* Cleanup

* Prefer issue data over deprecated options

* Clean up

* Bump cypress-xray-plugin from 7.3.0 to 7.3.1

* Fix ESLint issue

* Add issue transitioning

* Add explicit issue transitioning

* Move towards single issue update retrieval

* Add after run builder

* Fix test issues

* Refactor issue data handling

* Rename variable

* Fix Cypress tests

* Fix Cucumber tests

* Fix tests

* Fix test

* Bump cypress-xray-plugin from 7.3.1 to 7.4.0

* Fix test plan handling

* Update `CHANGELOG.md`
  • Loading branch information
csvtuda authored Oct 27, 2024
1 parent 78e1d9b commit 18c4f6b
Show file tree
Hide file tree
Showing 44 changed files with 1,856 additions and 2,041 deletions.
1 change: 1 addition & 0 deletions .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
},
"rules": {
"no-shadow": "off",
"@typescript-eslint/no-deprecated": "off",
"@typescript-eslint/parameter-properties": "error",
"@typescript-eslint/non-nullable-type-assertion-style": "off",
"@typescript-eslint/member-ordering": "error",
Expand Down
24 changes: 24 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,29 @@
# Changelog

# `7.4.0`

## Notable changes

- Removed unused `jira.fields.testType`

- Projects other than the configured project key can now be used for the test execution issue key

- Added explicit issue transition call for server environments ([#389](https://github.com/Qytera-Gmbh/cypress-xray-plugin/pull/389))

- Added Cypress test results parameter to test execution issue callback

- Added Cypress test results parameter to test plan key callback

## Dependency updates

- Bump @bahmutov/cypress-esbuild-preprocessor from 2.2.2 to 2.2.3

- Bump axios from 1.7.5 to 1.7.7

- Bump @badeball/cypress-cucumber-preprocessor from 20.1.1 to 21.0.0

- Bump cypress from 13.13.2 to 13.14.1

# `7.3.0`

## Notable changes
Expand Down
61 changes: 11 additions & 50 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "cypress-xray-plugin",
"version": "7.3.0",
"version": "7.4.0",
"description": "A Cypress plugin for uploading test results to Xray (test management for Jira)",
"types": "index.d.ts",
"author": "csvtuda",
Expand Down
74 changes: 74 additions & 0 deletions src/client/jira/jira-client.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -609,5 +609,79 @@ describe(path.relative(process.cwd(), __filename), () => {
);
});
});

describe("transitionIssue", () => {
it("transitions issues", async () => {
restClient.post.onFirstCall().resolves({
config: {
headers: new AxiosHeaders(),
},
data: undefined,
headers: {},
status: HttpStatusCode.NoContent,
statusText: HttpStatusCode[HttpStatusCode.NoContent],
});
await client.transitionIssue("CYP-XYZ", {
transition: {
name: "resolve",
to: {
name: "done",
},
},
});
expect(restClient.post).to.have.been.calledOnceWith(
"https://example.org/rest/api/latest/issue/CYP-XYZ/transitions",
{
transition: {
name: "resolve",
to: {
name: "done",
},
},
},
{
headers: { ["Authorization"]: "Basic dXNlcjp0b2tlbg==" },
}
);
});

it("handles bad responses", async () => {
const logger = getMockedLogger({ allowUnstubbedCalls: true });
const error = new AxiosError(
"Request failed with status code 404",
HttpStatusCode.NotFound.toString(),
undefined,
null,
{
config: { headers: new AxiosHeaders() },
data: {
errorMessages: ["issue CYP-XYZ does not exist"],
},
headers: {},
status: HttpStatusCode.NotFound,
statusText: HttpStatusCode[HttpStatusCode.NotFound],
}
);
restClient.post.onFirstCall().rejects(error);
await expect(
client.transitionIssue("CYP-XYZ", {
transition: {
name: "resolve",
to: {
name: "done",
},
},
})
).to.eventually.be.rejectedWith("Failed to transition issue");
expect(logger.message).to.have.been.calledWithExactly(
Level.ERROR,
"Failed to transition issue: Request failed with status code 404"
);
expect(logger.logErrorToFile).to.have.been.calledOnceWithExactly(
error,
"transitionIssue"
);
});
});
});
});
40 changes: 39 additions & 1 deletion src/client/jira/jira-client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,21 @@ export interface JiraClient {
* @see https://docs.atlassian.com/software/jira/docs/api/REST/9.9.1/#api/2/search-searchUsingSearchRequest
*/
search(request: SearchRequest): Promise<Issue[]>;
/**
* Performs an issue transition and, if the transition has a screen, updates the fields from the
* transition screen.
*
* To update the fields on the transition screen, specify the fields in the `fields` or `update`
* parameters in the request body. Get details about the fields using
* [Get transitions](https://developer.atlassian.com/cloud/jira/platform/rest/v3/api-group-issues/#api-rest-api-3-issue-issueidorkey-transitions-get)
* with the `transitions.fields` expand.
*
* @param issueIdOrKey - the ID or key of the issue
* @param issueUpdateData - the issue update data
* @see https://developer.atlassian.com/cloud/jira/platform/rest/v3/api-group-issues/#api-rest-api-3-issue-issueidorkey-transitions-post
* @see https://docs.atlassian.com/software/jira/docs/api/REST/9.9.1/#api/2/issue-doTransition
*/
transitionIssue(issueIdOrKey: string, issueUpdateData: IssueUpdate): Promise<void>;
}

/**
Expand Down Expand Up @@ -298,12 +313,35 @@ export class BaseJiraClient extends Client implements JiraClient {
}
);
LOG.message(Level.DEBUG, `Successfully edited issue: ${issueIdOrKey}`);

return issueIdOrKey;
} catch (error: unknown) {
LOG.message(Level.ERROR, `Failed to edit issue: ${errorMessage(error)}`);
LOG.logErrorToFile(error, "editIssue");
throw new LoggedError("Failed to edit issue");
}
}

public async transitionIssue(
issueIdOrKey: string,
issueUpdateData: IssueUpdate
): Promise<void> {
try {
const header = await this.credentials.getAuthorizationHeader();
LOG.message(Level.DEBUG, "Transitioning issue...");
await this.httpClient.post(
`${this.apiBaseUrl}/rest/api/latest/issue/${issueIdOrKey}/transitions`,
issueUpdateData,
{
headers: {
...header,
},
}
);
LOG.message(Level.DEBUG, `Successfully transitioned issue: ${issueIdOrKey}`);
} catch (error: unknown) {
LOG.message(Level.ERROR, `Failed to transition issue: ${errorMessage(error)}`);
LOG.logErrorToFile(error, "transitionIssue");
throw new LoggedError("Failed to transition issue");
}
}
}
Loading

0 comments on commit 18c4f6b

Please sign in to comment.