summaryrefslogtreecommitdiff
path: root/internal/worktime/db_test.go
diff options
context:
space:
mode:
authorPaul Buetow <paul@buetow.org>2026-03-03 23:42:04 +0200
committerPaul Buetow <paul@buetow.org>2026-03-03 23:42:04 +0200
commit293406c3bd2acc85490da11afabaf6733babd5e4 (patch)
tree1d3df45b9fb4511c37feaeacc885e1913e7f8ed6 /internal/worktime/db_test.go
parent2c414a53dc95c75584398246beb34f7ddf181448 (diff)
tui: wire real entries/report data and improve entry editing
Includes task 354 error-wrapping updates in cli/timer.go.
Diffstat (limited to 'internal/worktime/db_test.go')
-rw-r--r--internal/worktime/db_test.go52
1 files changed, 52 insertions, 0 deletions
diff --git a/internal/worktime/db_test.go b/internal/worktime/db_test.go
index d011a9e..f599fa1 100644
--- a/internal/worktime/db_test.go
+++ b/internal/worktime/db_test.go
@@ -129,6 +129,32 @@ func TestLoadAllMergesAndSortsEntries(t *testing.T) {
}
}
+func TestLoadAllBackfillsMissingSourceFromHost(t *testing.T) {
+ dbDir := t.TempDir()
+ dbFile := filepath.Join(dbDir, "db.host-a.json")
+ content := `{
+ "entries": {
+ "host-a": [
+ {"action":"login","what":"work","epoch":10,"human":"h1"}
+ ]
+ }
+}`
+ if err := os.WriteFile(dbFile, []byte(content), 0o644); err != nil {
+ t.Fatalf("WriteFile() error = %v", err)
+ }
+
+ entries, err := LoadAll(dbDir)
+ if err != nil {
+ t.Fatalf("LoadAll() error = %v", err)
+ }
+ if len(entries) != 1 {
+ t.Fatalf("entries len = %d, want 1", len(entries))
+ }
+ if entries[0].Source != "host-a" {
+ t.Fatalf("entries[0].Source = %q, want host-a", entries[0].Source)
+ }
+}
+
func TestLoadAllOnMissingDirectoryReturnsEmptySlice(t *testing.T) {
dbDir := filepath.Join(t.TempDir(), "does-not-exist")
@@ -159,6 +185,32 @@ func TestLoadHostInvalidJSON(t *testing.T) {
}
}
+func TestLoadAllAcceptsFloatValueEncoding(t *testing.T) {
+ dbDir := t.TempDir()
+ dbFile := filepath.Join(dbDir, "db.host-a.json")
+ content := `{
+ "entries": {
+ "host-a": [
+ {"action":"add","what":"work","epoch":10,"source":"host-a","human":"h1","value":31680.000000000004}
+ ]
+ }
+}`
+ if err := os.WriteFile(dbFile, []byte(content), 0o644); err != nil {
+ t.Fatalf("WriteFile() error = %v", err)
+ }
+
+ entries, err := LoadAll(dbDir)
+ if err != nil {
+ t.Fatalf("LoadAll() error = %v", err)
+ }
+ if len(entries) != 1 {
+ t.Fatalf("entries len = %d, want 1", len(entries))
+ }
+ if entries[0].Value != 31680 {
+ t.Fatalf("entries[0].Value = %d, want 31680", entries[0].Value)
+ }
+}
+
func TestLoadAllInvalidJSON(t *testing.T) {
dbDir := t.TempDir()
badFile := filepath.Join(dbDir, "db.host-a.json")