Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

✨ additionalInstructions support #23

Merged
merged 1 commit into from
Jul 12, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,6 @@

# node
node_modules

# Jest
coverage
4 changes: 2 additions & 2 deletions jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
module.exports = {
preset: 'ts-jest',
testEnvironment: 'node',
collectCoverage: false,
// coverageReporters: ["clover", "json", "lcov", "text", "html"],
collectCoverage: true,
coverageReporters: ["clover", "json", "lcov", "text", "html"],
// testTimeout: 10 * 1000,
};
3 changes: 3 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
{
"scripts": {
"test": "jest"
},
"devDependencies": {
"@types/jest": "^29.5.2",
"jest": "^29.6.1",
Expand Down
3 changes: 2 additions & 1 deletion resources/exploratory_test_comment_prepare.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,6 @@
"user_stories": [
"Add 1 or more user stories here which you want the tester to verify"
]
}
},
"additionalInstructions": "(optional, remove it if not needed)"
}
3 changes: 3 additions & 0 deletions resources/exploratory_test_comment_prepare_schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,9 @@
"howtofind",
"user_stories"
]
},
"additionalInstructions": {
"type": "string"
}
},
"required": [
Expand Down
3 changes: 2 additions & 1 deletion src/Util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import Ajv, {ValidateFunction} from "ajv";

export class Util {

public static getJsonObjectFromComment(regex: RegExp, comment: string, expectedIndexOfObject: number): any {
private static getJsonObjectFromComment(regex: RegExp, comment: string, expectedIndexOfObject: number): any {
const matches = regex.exec(comment);
if (!matches) {
throw new Error("Provided comment didn't match");
Expand Down Expand Up @@ -61,6 +61,7 @@ export class Util {
user_stories: prepareObject.feature.user_stories
}
],
instructions: (prepareObject.additionalInstructions ? prepareObject.additionalInstructions : null),
duration: "2",
testing_type: "rapid"
}
Expand Down
7 changes: 4 additions & 3 deletions test/Util.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,13 @@ describe("TestIO Trigger-from-PR logic", () => {
});

it('should parse an object from the Github preparation comment', () => {
const parsedObject = Util.getJsonObjectFromComment( /```json\s(.+)\s```/sm, commentBody, 1);
const parsedObject = Util.retrievePrepareObjectFromComment(commentBody);
expect(parsedObject).not.toBeNull();
});

it('should validate parsed object against schema', () => {
const prepareTestSchemaFile = "resources/exploratory_test_comment_prepare_schema.json";
const parsedObject = Util.getJsonObjectFromComment( /```json\s(.+)\s```/sm, commentBody, 1);
const parsedObject = Util.retrievePrepareObjectFromComment(commentBody);
const {valid, validation} = Util.validateObjectAgainstSchema(parsedObject, prepareTestSchemaFile);
if (!valid) {
if (validation.errors) {
Expand All @@ -61,7 +61,7 @@ describe("TestIO Trigger-from-PR logic", () => {
});

it('should convert prepare object into TestIO payload', () => {
const prepareObject = Util.getJsonObjectFromComment( /```json\s(.+)\s```/sm, commentBody, 1);
const prepareObject = Util.retrievePrepareObjectFromComment(commentBody);
const repo = "testio-management";
const owner = "Staffbase";
const pr = 666;
Expand All @@ -77,6 +77,7 @@ describe("TestIO Trigger-from-PR logic", () => {
expect(testioPayload.exploratory_test.features[0].description).toBe(prepareObject.feature.description);
expect(testioPayload.exploratory_test.features[0].howtofind).toBe(prepareObject.feature.howtofind);
expect(testioPayload.exploratory_test.features[0].user_stories).toBe(prepareObject.feature.user_stories);
expect(testioPayload.exploratory_test.instructions).toBe(prepareObject.additionalInstructions);
});

it('should truncate looooooong PR titles and add suffix', () => {
Expand Down