All checks were successful
CI / build (push) Successful in 48s
- Add /setcalendar command for calendar type parity (Settings UI) - Add 17 store tests covering all repository methods - Add handler tests for formatDuration, fmtHHMM, fmtDDHHMM - Add domain tests for BurnoutLevel.String, NavMonth, FormatSalary - Fix silent error discarding in save* helpers (log write failures) - Fix computeAndAwardXP error handling instead of discarding - Wrap critical store.go SQL errors with fmt.Errorf context - Update README commands table with /setcalendar
71 lines
1.2 KiB
Go
71 lines
1.2 KiB
Go
package handler
|
|
|
|
import (
|
|
"testing"
|
|
)
|
|
|
|
func TestFormatDuration(t *testing.T) {
|
|
tests := []struct {
|
|
seconds int64
|
|
want string
|
|
}{
|
|
{0, "0m"},
|
|
{30, "0m"},
|
|
{59, "0m"},
|
|
{60, "1m"},
|
|
{3599, "59m"},
|
|
{3600, "1h 0m"},
|
|
{3661, "1h 1m"},
|
|
{7200, "2h 0m"},
|
|
{7260, "2h 1m"},
|
|
{86399, "23h 59m"},
|
|
{86400, "24h 0m"},
|
|
}
|
|
for _, tc := range tests {
|
|
got := formatDuration(tc.seconds)
|
|
if got != tc.want {
|
|
t.Errorf("formatDuration(%d) = %q, want %q", tc.seconds, got, tc.want)
|
|
}
|
|
}
|
|
}
|
|
|
|
func TestFmtHHMM(t *testing.T) {
|
|
tests := []struct {
|
|
seconds int64
|
|
want string
|
|
}{
|
|
{0, "0:00"},
|
|
{60, "0:01"},
|
|
{3600, "1:00"},
|
|
{3661, "1:01"},
|
|
{86399, "23:59"},
|
|
{86400, "24:00"},
|
|
}
|
|
for _, tc := range tests {
|
|
got := fmtHHMM(tc.seconds)
|
|
if got != tc.want {
|
|
t.Errorf("fmtHHMM(%d) = %q, want %q", tc.seconds, got, tc.want)
|
|
}
|
|
}
|
|
}
|
|
|
|
func TestFmtDDHHMM(t *testing.T) {
|
|
tests := []struct {
|
|
seconds int64
|
|
want string
|
|
}{
|
|
{0, "0:00:00"},
|
|
{60, "0:00:01"},
|
|
{3600, "0:01:00"},
|
|
{86400, "1:00:00"},
|
|
{90061, "1:01:01"},
|
|
{172800, "2:00:00"},
|
|
}
|
|
for _, tc := range tests {
|
|
got := fmtDDHHMM(tc.seconds)
|
|
if got != tc.want {
|
|
t.Errorf("fmtDDHHMM(%d) = %q, want %q", tc.seconds, got, tc.want)
|
|
}
|
|
}
|
|
}
|