fix: address audit findings — nil pointers, timezone bug, dead code, tests, README

- Fix nil pointer dereference in clock.go (guard GetOrCreateSettings and
  GetOrCreateRPGStats errors before accessing fields)
- Fix timezone bug in handleSetBreakMsg (was using system time.Now()
  instead of user's configured timezone)
- Remove dead code: sendExportMonthPicker (unused wrapper)
- Simplify xpForWorkSeconds (xpPerSecond=1, inline to just return sec)
- Extract computeStreakFromDates as pure testable function from
  recalcAggregates; add 6 tests covering empty, current, gaps,
  no-today, long streak, longest-not-current edge cases
- Update README with full feature documentation: RPG, League, Salary,
  Burnout, Work Types, Inline History Editing, all missing commands
This commit is contained in:
2026-06-25 02:25:13 +03:30
parent 5cd811e057
commit af23f80fbb
6 changed files with 207 additions and 72 deletions

View File

@@ -1,6 +1,7 @@
package bot
import (
"fmt"
"strings"
"testing"
)
@@ -225,3 +226,72 @@ func TestComputeTrendFromAvgs(t *testing.T) {
}
}
}
func TestComputeStreakFromDates_Empty(t *testing.T) {
cur, longest := computeStreakFromDates(nil, "2026-06-25")
if cur != 0 || longest != 0 {
t.Errorf("empty dates: got (%d, %d), want (0, 0)", cur, longest)
}
}
func TestComputeStreakFromDates_CurrentOnly(t *testing.T) {
dates := []string{"2026-06-25", "2026-06-26"}
cur, longest := computeStreakFromDates(dates, "2026-06-26")
if cur != 2 {
t.Errorf("current streak = %d, want 2", cur)
}
if longest != 2 {
t.Errorf("longest streak = %d, want 2", longest)
}
}
func TestComputeStreakFromDates_GapBreaksStreak(t *testing.T) {
dates := []string{"2026-06-23", "2026-06-25", "2026-06-26"}
cur, longest := computeStreakFromDates(dates, "2026-06-26")
if cur != 2 {
t.Errorf("current streak = %d, want 2 (today and yesterday)", cur)
}
if longest != 2 {
t.Errorf("longest streak = %d, want 2", longest)
}
}
func TestComputeStreakFromDates_NoEventsToday(t *testing.T) {
dates := []string{"2026-06-24", "2026-06-25"}
cur, longest := computeStreakFromDates(dates, "2026-06-26")
if cur != 0 {
t.Errorf("current streak = %d, want 0 (no events today)", cur)
}
if longest != 2 {
t.Errorf("longest streak = %d, want 2", longest)
}
}
func TestComputeStreakFromDates_LongStreak(t *testing.T) {
dates := []string{}
for d := 1; d <= 10; d++ {
dates = append(dates, fmt.Sprintf("2026-06-%02d", d))
}
cur, longest := computeStreakFromDates(dates, "2026-06-10")
if cur != 10 {
t.Errorf("current streak = %d, want 10", cur)
}
if longest != 10 {
t.Errorf("longest streak = %d, want 10", longest)
}
}
func TestComputeStreakFromDates_LongestNotCurrent(t *testing.T) {
dates := []string{}
for d := 1; d <= 5; d++ {
dates = append(dates, fmt.Sprintf("2026-06-%02d", d))
}
dates = append(dates, "2026-06-09", "2026-06-10")
cur, longest := computeStreakFromDates(dates, "2026-06-10")
if cur != 2 {
t.Errorf("current streak = %d, want 2", cur)
}
if longest != 5 {
t.Errorf("longest streak = %d, want 5", longest)
}
}