Skip to content

Commit cfdfbc4

Browse files
wesmclaude
andcommitted
Add regression test for hasGmailSource filtering
Covers three cases: no sources (hint shown), non-Gmail source only (hint shown), and Gmail source exists (hint suppressed). This logic regressed across multiple commits so it deserves explicit coverage. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent a273003 commit cfdfbc4

File tree

1 file changed

+42
-0
lines changed

1 file changed

+42
-0
lines changed
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
package cmd
2+
3+
import (
4+
"testing"
5+
6+
"github.com/wesm/msgvault/internal/store"
7+
)
8+
9+
func TestHasGmailSource(t *testing.T) {
10+
tmpDir := t.TempDir()
11+
s, err := store.Open(tmpDir + "/msgvault.db")
12+
if err != nil {
13+
t.Fatalf("open store: %v", err)
14+
}
15+
defer func() { _ = s.Close() }()
16+
if err := s.InitSchema(); err != nil {
17+
t.Fatalf("init schema: %v", err)
18+
}
19+
20+
const email = "user@company.com"
21+
22+
// No sources at all — should suggest add-account.
23+
if hasGmailSource(s, email) {
24+
t.Error("hasGmailSource should be false with no sources")
25+
}
26+
27+
// Non-Gmail source exists — should still suggest add-account.
28+
if _, err := s.GetOrCreateSource("mbox", email); err != nil {
29+
t.Fatalf("create mbox source: %v", err)
30+
}
31+
if hasGmailSource(s, email) {
32+
t.Error("hasGmailSource should be false with only mbox source")
33+
}
34+
35+
// Gmail source exists — should suppress the hint.
36+
if _, err := s.GetOrCreateSource("gmail", email); err != nil {
37+
t.Fatalf("create gmail source: %v", err)
38+
}
39+
if !hasGmailSource(s, email) {
40+
t.Error("hasGmailSource should be true with gmail source")
41+
}
42+
}

0 commit comments

Comments
 (0)