Address code review feedback: improve input validation

Co-authored-by: blackboxprogramming <118287761+blackboxprogramming@users.noreply.github.com>
This commit is contained in:
copilot-swe-agent[bot]
2025-11-24 23:00:17 +00:00
parent f1b267a12a
commit 21763f3f4e
2 changed files with 18 additions and 2 deletions

View File

@@ -9,8 +9,9 @@ module.exports = function calculateEmojiStats(reactions = []) {
total: 0, total: 0,
}; };
reactions.forEach(({ content }) => { reactions.forEach((reaction) => {
if (stats.hasOwnProperty(content)) { const content = reaction?.content;
if (content && content in stats) {
stats[content]++; stats[content]++;
stats.total++; stats.total++;
} }

View File

@@ -82,4 +82,19 @@ describe("calculateEmojiStats", () => {
expect(result.report["✅"]).toBe("67%"); // 2/3 = 66.67% rounded expect(result.report["✅"]).toBe("67%"); // 2/3 = 66.67% rounded
expect(result.report["❌"]).toBe("33%"); // 1/3 = 33.33% rounded expect(result.report["❌"]).toBe("33%"); // 1/3 = 33.33% rounded
}); });
it("handles reactions with missing content property", () => {
const reactionsWithMissing = [
{ content: "✅" },
{}, // missing content
{ content: "❌" },
{ otherProp: "value" }, // different property
];
const result = calculateEmojiStats(reactionsWithMissing);
expect(result.total).toBe(2);
expect(result.confirmed).toBe(1);
expect(result.blocked).toBe(1);
});
}); });