Skip to content
Open
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
58 changes: 58 additions & 0 deletions src/lib/__tests__/yearInReviewUtils.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -174,3 +174,61 @@ describe("getMostActiveDayFromCalendar", () => {
expect(getMostActiveDayFromCalendar(calendar)).toBe("Thursday");
});
});

describe("buildHourlyHeatmapFromCommitDates - edge cases", () => {
// Note: The following tests use mock objects cast to string to intentionally trigger specific
// internal parsing failures and verify the fallback logic without relying on invalid JS Date quirks
// that differ between environments.

it("falls back to full date parsing if cached day parsing results in NaN but full date is parseable", () => {
const mockDateStr = {
length: 19,
10: "T",
slice: () => "invalid___",
toString: () => "2023-01-01T10:00:00Z"
} as unknown as string;
const heatmap = buildHourlyHeatmapFromCommitDates([mockDateStr]);
expect(heatmap[0][10]).toBe(1);
});
Comment on lines +183 to +192
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 モックオブジェクトが実装詳細に強く依存している

as unknown as string で型システムを回避したオブジェクトを渡すアプローチは、buildHourlyHeatmapFromCommitDates の内部実装(.length[10].slice()new Date(dateString).toString() を呼ぶ等)に強く依存しています。同様の構造が 201–211 行目にも存在します。

実装リファクタリング時にこれらのテストが意図しない形でサイレントに壊れる可能性があります。実際の分岐を通したいなら、実装の内部詳細に依存しないような実際の文字列入力を用いるほうが保守性が高まります。

Prompt To Fix With AI
This is a comment left during a code review.
Path: src/lib/__tests__/yearInReviewUtils.test.ts
Line: 179-188

Comment:
**モックオブジェクトが実装詳細に強く依存している**

`as unknown as string` で型システムを回避したオブジェクトを渡すアプローチは、`buildHourlyHeatmapFromCommitDates` の内部実装(`.length``[10]``.slice()``new Date(dateString)``.toString()` を呼ぶ等)に強く依存しています。同様の構造が 201–211 行目にも存在します。

実装リファクタリング時にこれらのテストが意図しない形でサイレントに壊れる可能性があります。実際の分岐を通したいなら、実装の内部詳細に依存しないような実際の文字列入力を用いるほうが保守性が高まります。

How can I resolve this? If you propose a fix, please make it concise.


it("falls back to full string parsing for unparseable hour data", () => {
const heatmap = buildHourlyHeatmapFromCommitDates(["2023-01-01TX0:00:00Z"]);
const totalCommits = heatmap.flat().reduce((sum, count) => sum + count, 0);
expect(totalCommits).toBe(0);
});

it("falls back to full string parsing for unparseable hour data but valid date", () => {
const heatmap = buildHourlyHeatmapFromCommitDates(["2023-01-01T10:00:00.1234Z"]);
expect(heatmap[0][10]).toBe(1);
});
Comment thread
coderabbitai[bot] marked this conversation as resolved.

it("falls back if caching fails and full date is also invalid", () => {
const mockDateStr = {
length: 19,
10: "T",
slice: () => "invalid___",
toString: () => "invalid-full-date"
} as unknown as string;
const heatmap = buildHourlyHeatmapFromCommitDates([mockDateStr]);
const totalCommits = heatmap.flat().reduce((sum, count) => sum + count, 0);
expect(totalCommits).toBe(0);
});

it("falls back to full date parsing when timezone offsets don't match fast-path ending conditions", () => {
const commitDates = [
"2023-01-01T10:00:00.000Z", // length 24, ends with .000Z
"2023-01-01T10:00:00.123+02:00", // length 29
];
const heatmap = buildHourlyHeatmapFromCommitDates(commitDates);
expect(heatmap[0][10]).toBe(1);
expect(heatmap[0][8]).toBe(1); // 10:00:00+02:00 is 08:00 UTC
});

it("falls back to full date parsing when length is 24 but does not end with .000Z", () => {
const commitDates = [
"2023-01-01T10:00:00.123+", // length 24, invalid ending
];
const heatmap = buildHourlyHeatmapFromCommitDates(commitDates);
expect(heatmap[0][10]).toBe(0);
});
});
Loading