Skip to content

Commit 66ddd9f

Browse files
test(calendar): add unit tests for dedupeCalendarTargets and collectCalendarInputs
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 58a25aa commit 66ddd9f

1 file changed

Lines changed: 50 additions & 0 deletions

File tree

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
package cmd
2+
3+
import (
4+
"testing"
5+
)
6+
7+
func TestDedupeCalendarTargets(t *testing.T) {
8+
tests := []struct {
9+
name string
10+
input []string
11+
expect []string
12+
}{
13+
{"empty", nil, nil},
14+
{"single", []string{"cal@example.com"}, []string{"cal@example.com"}},
15+
{"dedup", []string{"a@b.com", "a@b.com"}, []string{"a@b.com"}},
16+
{"primary normalization", []string{"primary", "Primary", "PRIMARY"}, []string{"primary"}},
17+
{"mixed", []string{"a@b.com", "primary", "c@d.com", "a@b.com"}, []string{"a@b.com", "primary", "c@d.com"}},
18+
{"whitespace", []string{" a@b.com ", "", " "}, []string{"a@b.com"}},
19+
}
20+
for _, tt := range tests {
21+
t.Run(tt.name, func(t *testing.T) {
22+
got := dedupeCalendarTargets(tt.input)
23+
if len(got) == 0 && len(tt.expect) == 0 {
24+
return
25+
}
26+
if len(got) != len(tt.expect) {
27+
t.Fatalf("expected %v, got %v", tt.expect, got)
28+
}
29+
for i := range got {
30+
if got[i] != tt.expect[i] {
31+
t.Fatalf("at index %d: expected %q, got %q", i, tt.expect[i], got[i])
32+
}
33+
}
34+
})
35+
}
36+
}
37+
38+
func TestCollectCalendarInputs(t *testing.T) {
39+
got := collectCalendarInputs([]string{"a", "b"}, "c,d")
40+
if len(got) != 4 || got[0] != "a" || got[1] != "b" || got[2] != "c" || got[3] != "d" {
41+
t.Fatalf("unexpected: %#v", got)
42+
}
43+
}
44+
45+
func TestCollectCalendarInputs_EmptyCalendars(t *testing.T) {
46+
got := collectCalendarInputs([]string{"a"}, "")
47+
if len(got) != 1 || got[0] != "a" {
48+
t.Fatalf("unexpected: %#v", got)
49+
}
50+
}

0 commit comments

Comments
 (0)