Skip to content

Commit

Permalink
Merge pull request #12 from Staffbase/adjust-test-title
Browse files Browse the repository at this point in the history
feat: include PR title in test name
  • Loading branch information
jreimone authored Jul 10, 2023
2 parents bcd602e + 696fe13 commit 118df25
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 7 deletions.
7 changes: 4 additions & 3 deletions src/Util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,13 @@ export class Util {
return {valid, validation};
}

public static convertPrepareObjectToTestIOPayload(prepareObject: any, repo: string, owner: string, pr: number): any {
public static convertPrepareObjectToTestIOPayload(prepareObject: any, repo: string, owner: string, pr: number, prTitle: string): any {
const titleBase = `[${owner}/${repo}/${pr}]${prTitle}`;
const testioPayload = {
exploratory_test: {
test_title: `${owner}/${repo}/${pr}`,
test_title: titleBase,
test_environment: {
title: `${owner}/${repo}/${pr} test environment`,
title: `${titleBase} [test environment]`,
url: prepareObject.test_environment.url,
access: prepareObject.test_environment.access,
},
Expand Down
18 changes: 17 additions & 1 deletion src/retrievePayload.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,23 @@ async function createPayload() {
Util.throwErrorAndPrepareErrorMessage("Provided json is not conform to schema", errorFileName);
}

const testIOPayload = Util.convertPrepareObjectToTestIOPayload(preparation, github.context.repo.repo, github.context.repo.owner, github.context.issue.number);
const pullRequest:any = await octokit.request('GET /repos/{owner}/{repo}/pulls/{pull_number}', {
owner: github.context.repo.owner,
repo: github.context.repo.repo,
pull_number: github.context.issue.number,
headers: {
'X-GitHub-Api-Version': '2022-11-28'
}
})

const prTitle = pullRequest.title;
if (!prTitle) {
console.log("The pull request received:");
console.log(JSON.stringify(pullRequest, null, 2));
Util.throwErrorAndPrepareErrorMessage("Could not retrieve title of the PR", errorFileName);
}

const testIOPayload = Util.convertPrepareObjectToTestIOPayload(preparation, github.context.repo.repo, github.context.repo.owner, github.context.issue.number, prTitle);
console.log("Converted payload:");
console.log(testIOPayload);
const payloadFile = `${process.env.TESTIO_SCRIPTS_DIR}/resources/testio_payload.json`;
Expand Down
7 changes: 4 additions & 3 deletions test/Util.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,10 +66,11 @@ describe("TestIO Trigger-from-PR logic", () => {
const owner = "Staffbase";
const pr = 666;
const commentID = 123456;
const testioPayload = Util.convertPrepareObjectToTestIOPayload(prepareObject, repo, owner, pr);
const testName = `${owner}/${repo}/${pr}`;
const prTitle = "My awesome feature";
const testioPayload = Util.convertPrepareObjectToTestIOPayload(prepareObject, repo, owner, pr, prTitle);
const testName = `[${owner}/${repo}/${pr}]${prTitle}`;
expect(testioPayload.exploratory_test.test_title).toBe(testName);
expect(testioPayload.exploratory_test.test_environment.title).toBe(testName + " test environment");
expect(testioPayload.exploratory_test.test_environment.title).toBe(testName + " [test environment]");
expect(testioPayload.exploratory_test.test_environment.url).toBe(prepareObject.test_environment.url);
expect(testioPayload.exploratory_test.test_environment.access).toBe(prepareObject.test_environment.access);
expect(testioPayload.exploratory_test.features[0].title).toBe(prepareObject.feature.title);
Expand Down

0 comments on commit 118df25

Please sign in to comment.