Skip to content

Commit

Permalink
fix: Handle correctly issues with an empty body (#34)
Browse files Browse the repository at this point in the history
* fix: Handle correctly issues with an empty body

Fixes: #33

* Update fixtures/blank/issue.js

Co-authored-by: Gregor Martynus <39992+gr2m@users.noreply.github.com>

Co-authored-by: Stefan Buck <github@stefanbuck.com>
Co-authored-by: Gregor Martynus <39992+gr2m@users.noreply.github.com>
  • Loading branch information
3 people committed Aug 29, 2022
1 parent f7e22bd commit 7da1c3a
Show file tree
Hide file tree
Showing 5 changed files with 66 additions and 1 deletion.
1 change: 1 addition & 0 deletions fixtures/blank/expected.json
@@ -0,0 +1 @@
{}
9 changes: 9 additions & 0 deletions fixtures/blank/form.yml
@@ -0,0 +1,9 @@
body:
- type: textarea
id: textarea-one
attributes:
label: My textarea input
- type: textarea
id: textarea-two
attributes:
label: Another textarea input
5 changes: 5 additions & 0 deletions fixtures/blank/issue.js
@@ -0,0 +1,5 @@
module.exports = {
issue: {
body: null,
},
};
2 changes: 1 addition & 1 deletion index.js
Expand Up @@ -39,7 +39,7 @@ async function run(env, eventPayload, fs, core) {
}

let result;
const body = eventPayload.issue.body;
const body = eventPayload.issue.body || '';
const idMapping = getIDsFromIssueTemplate(form);

function toKey(str) {
Expand Down
50 changes: 50 additions & 0 deletions test.spec.js
Expand Up @@ -106,3 +106,53 @@ it("multiple paragraphs", () => {

run(env, eventPayload, fs, core);
});

it("blank", () => {
const expectedOutput = require("./fixtures/blank/expected.json");
const expectedOutputJson = JSON.stringify(expectedOutput, null, 2);

// mock ENV
const env = {
HOME: "<home path>",
};

// mock event payload
const eventPayload = require("./fixtures/blank/issue");

// mock fs
const fs = {
readFileSync(path, encoding) {
expect(path).toBe("<template-path>");
expect(encoding).toBe("utf8");
return readFileSync("fixtures/blank/form.yml", "utf-8");
},
writeFileSync(path, content) {
expect(path).toBe("<home path>/issue-parser-result.json");
expect(content).toBe(expectedOutputJson);
},
};

// mock core
const core = {
getInput(inputName) {
expect(inputName).toBe("template-path");
return "<template-path>";
},
setOutput(outputName, outputValue) {
if (outputName === "jsonString") {
expect(outputValue).toBe(expectedOutputJson);
return;
}

if (outputName.startsWith("issueparser_")) {
const key = outputName.substr("issueparser_".length);
expect(Object.keys(expectedOutput)).toContain(key);

expect(outputValue).toBe(expectedOutput[key]);
return;
}
},
};

run(env, eventPayload, fs, core);
});

0 comments on commit 7da1c3a

Please sign in to comment.