Address code review feedback: improve input validation
Co-authored-by: blackboxprogramming <118287761+blackboxprogramming@users.noreply.github.com>
This commit is contained in:
@@ -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++;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user