Skip to content

Commit

Permalink
Merge pull request #74 from Staffbase/error-handling-for-prepare-comment
Browse files Browse the repository at this point in the history
✨ early error message when wrong os or device category
  • Loading branch information
jreimone committed Dec 14, 2023
2 parents 95d1009 + 0000b7d commit a92d954
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 0 deletions.
15 changes: 15 additions & 0 deletions src/TestIOTriggerTestGHA.ts
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,21 @@ export class TestIOTriggerTestGHA {
const deviceSpecParts = commentSuffix.split(/\s+/);
const osName = deviceSpecParts[0];
const categoryName = (deviceSpecParts[1] ? deviceSpecParts[1] : "smartphones");

const deviceCategoryId = await TestIOUtil.retrieveDeviceCategoryIdByName(categoryName);
if (deviceCategoryId == -1) {
const errorMessage = `Device category '${categoryName}' is not valid`;
const error = Util.prepareErrorMessageAndOptionallyThrow(errorMessage, this.errorFile, true);
return Promise.reject(error);
}

const osId = await TestIOUtil.retrieveOperatingSystemIdByDeviceCategoryIdAndName(deviceCategoryId, osName);
if (osId == -1) {
const errorMessage = `Operating System '${osName}' is not valid`;
const error = Util.prepareErrorMessageAndOptionallyThrow(errorMessage, this.errorFile, true);
return Promise.reject(error);
}

device = {
os: osName,
category: categoryName,
Expand Down
23 changes: 23 additions & 0 deletions test/TestIOTriggerTestGHA.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,29 @@ describe("Trigger TestIO Test GHA", () => {
await expect(gha.triggerTestIoTest()).rejects.toEqual(new Error("TestIO properties are not configured"));
});

it('should return Error with wrong create comment attributes', async () => {
let gha = setupWithMockedCommentCreation();
const createCommentUrl = `https://github.com/${owner}/${repo}/issues/${pr}/comments#987654321`;

// os: wrong, device category: correct
let createComment = "@bot-testio exploratory-test create androiddd"; // without category it defaults to 'smartphones'
await expect(gha.addPrepareComment(createCommentUrl, createComment)).rejects.toEqual(new Error("Operating System 'androiddd' is not valid"));
createComment = "@bot-testio exploratory-test create iossss tablets";
await expect(gha.addPrepareComment(createCommentUrl, createComment)).rejects.toEqual(new Error("Operating System 'iossss' is not valid"));

// os: wrong, device category: wrong
createComment = "@bot-testio exploratory-test create androiddd tabletssss";
await expect(gha.addPrepareComment(createCommentUrl, createComment)).rejects.toEqual(new Error("Device category 'tabletssss' is not valid"));

// os: correct, device category: wrong
createComment = "@bot-testio exploratory-test create android tabletsXYZ";
await expect(gha.addPrepareComment(createCommentUrl, createComment)).rejects.toEqual(new Error("Device category 'tabletsXYZ' is not valid"));

// os: correct, device category: correct
createComment = "@bot-testio exploratory-test create ios smartphones";
await expect(gha.addPrepareComment(createCommentUrl, createComment)).resolves.toBeDefined();
});

describe("[default context] Comment Creation and Retrieval", () => {

it("should create comment", async () => {
Expand Down

0 comments on commit a92d954

Please sign in to comment.