auto-update-daily-20260202
  1package output
  2
  3import (
  4	"bytes"
  5	"strings"
  6	"testing"
  7	"time"
  8
  9	"github.com/vdemeester/home/tools/review-tool/internal/activity"
 10)
 11
 12func TestWriteMarkdown_Header(t *testing.T) {
 13	report := &activity.ReviewReport{
 14		GeneratedAt: time.Date(2026, 1, 27, 15, 30, 0, 0, time.UTC),
 15		TimeRange: activity.TimeRange{
 16			Start:       time.Date(2026, 1, 20, 0, 0, 0, 0, time.UTC),
 17			End:         time.Date(2026, 1, 27, 0, 0, 0, 0, time.UTC),
 18			Description: "last week",
 19		},
 20		Activities: make(map[string]*activity.Activity),
 21	}
 22
 23	var buf bytes.Buffer
 24	err := WriteMarkdown(&buf, report)
 25	if err != nil {
 26		t.Fatalf("WriteMarkdown() error = %v", err)
 27	}
 28
 29	output := buf.String()
 30	if !strings.Contains(output, "# Activity Review: last week") {
 31		t.Errorf("missing title header, got:\n%s", output)
 32	}
 33	if !strings.Contains(output, "**Period:** 2026-01-20 to 2026-01-27") {
 34		t.Errorf("missing period, got:\n%s", output)
 35	}
 36}
 37
 38func TestWriteMarkdown_WithSummary(t *testing.T) {
 39	report := &activity.ReviewReport{
 40		GeneratedAt: time.Now(),
 41		TimeRange: activity.TimeRange{
 42			Start:       time.Now().AddDate(0, 0, -7),
 43			End:         time.Now(),
 44			Description: "last week",
 45		},
 46		Activities: make(map[string]*activity.Activity),
 47		Summary: &activity.Summary{
 48			TotalItems:      5,
 49			ItemsByCategory: map[string]int{"github": 3, "org": 2},
 50			ItemsByType:     map[string]int{"pr_merged": 3, "todo_done": 2},
 51		},
 52	}
 53
 54	var buf bytes.Buffer
 55	err := WriteMarkdown(&buf, report)
 56	if err != nil {
 57		t.Fatalf("WriteMarkdown() error = %v", err)
 58	}
 59
 60	output := buf.String()
 61	if !strings.Contains(output, "## Summary") {
 62		t.Errorf("missing summary section, got:\n%s", output)
 63	}
 64	if !strings.Contains(output, "**Total activities:** 5") {
 65		t.Errorf("missing total count, got:\n%s", output)
 66	}
 67}
 68
 69func TestWriteMarkdown_WithActivities(t *testing.T) {
 70	report := &activity.ReviewReport{
 71		GeneratedAt: time.Now(),
 72		TimeRange: activity.TimeRange{
 73			Start:       time.Now().AddDate(0, 0, -7),
 74			End:         time.Now(),
 75			Description: "last week",
 76		},
 77		Activities: map[string]*activity.Activity{
 78			"github": {
 79				Source: "github",
 80				Items: []activity.ActivityItem{
 81					{
 82						ID:        "1",
 83						Title:     "Fix authentication bug",
 84						Type:      "pr_merged",
 85						Category:  activity.CategoryGitHub,
 86						Timestamp: time.Now(),
 87						URL:       "https://github.com/org/repo/pull/123",
 88					},
 89				},
 90			},
 91		},
 92	}
 93
 94	var buf bytes.Buffer
 95	err := WriteMarkdown(&buf, report)
 96	if err != nil {
 97		t.Fatalf("WriteMarkdown() error = %v", err)
 98	}
 99
100	output := buf.String()
101	if !strings.Contains(output, "## GitHub") {
102		t.Errorf("missing GitHub section, got:\n%s", output)
103	}
104	if !strings.Contains(output, "Fix authentication bug") {
105		t.Errorf("missing activity item, got:\n%s", output)
106	}
107	if !strings.Contains(output, "https://github.com/org/repo/pull/123") {
108		t.Errorf("missing URL, got:\n%s", output)
109	}
110}
111
112func TestFormatSourceName(t *testing.T) {
113	tests := []struct {
114		source string
115		want   string
116	}{
117		{"github", "GitHub"},
118		{"org", "Org-mode"},
119		{"jira", "Jira"},
120		{"claude", "Claude Sessions"},
121		{"unknown", "Unknown"},
122	}
123
124	for _, tt := range tests {
125		t.Run(tt.source, func(t *testing.T) {
126			got := formatSourceName(tt.source)
127			if got != tt.want {
128				t.Errorf("formatSourceName(%q) = %q, want %q", tt.source, got, tt.want)
129			}
130		})
131	}
132}
133
134func TestFormatTypeName(t *testing.T) {
135	tests := []struct {
136		typ  string
137		want string
138	}{
139		{"pr_merged", "PRs Merged"},
140		{"todo_done", "Tasks Completed"},
141		{"session", "Sessions"},
142		{"custom_type", "Custom Type"},
143	}
144
145	for _, tt := range tests {
146		t.Run(tt.typ, func(t *testing.T) {
147			got := formatTypeName(tt.typ)
148			if got != tt.want {
149				t.Errorf("formatTypeName(%q) = %q, want %q", tt.typ, got, tt.want)
150			}
151		})
152	}
153}