forked from guigui42/mcp-vosdroits
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathimpots_client_test.go
More file actions
147 lines (130 loc) · 3.32 KB
/
impots_client_test.go
File metadata and controls
147 lines (130 loc) · 3.32 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
package client
import (
"context"
"testing"
"time"
)
func TestNewImpotsClient(t *testing.T) {
client := NewImpotsClient(30 * time.Second)
if client == nil {
t.Fatal("NewImpotsClient returned nil")
}
if client.baseURL != "https://www.impots.gouv.fr" {
t.Errorf("expected baseURL to be https://www.impots.gouv.fr, got %s", client.baseURL)
}
if client.timeout != 30*time.Second {
t.Errorf("expected timeout to be 30s, got %v", client.timeout)
}
}
func TestSearchImpots_InvalidInput(t *testing.T) {
tests := []struct {
name string
query string
limit int
}{
{
name: "empty query",
query: "",
limit: 10,
},
{
name: "negative limit",
query: "formulaire 2042",
limit: -1,
},
{
name: "excessive limit",
query: "formulaire 2042",
limit: 200,
},
}
client := NewImpotsClient(30 * time.Second)
ctx := context.Background()
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
_, err := client.SearchImpots(ctx, tt.query, tt.limit)
// Empty query should return fallback results, not error
// Invalid limits should be normalized, not error
if err != nil && tt.query != "" {
t.Errorf("SearchImpots() unexpected error: %v", err)
}
})
}
}
func TestGetImpotsArticle_InvalidURL(t *testing.T) {
tests := []struct {
name string
url string
wantErr bool
}{
{
name: "empty URL",
url: "",
wantErr: true,
},
{
name: "invalid URL",
url: "not a url",
wantErr: true,
},
{
name: "wrong domain",
url: "https://www.google.com",
wantErr: true,
},
{
name: "valid domain",
url: "https://www.impots.gouv.fr/formulaire/2042/declaration-des-revenus",
wantErr: false,
},
}
client := NewImpotsClient(30 * time.Second)
ctx := context.Background()
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
_, err := client.GetImpotsArticle(ctx, tt.url)
if (err != nil) != tt.wantErr {
t.Errorf("GetImpotsArticle() error = %v, wantErr %v", err, tt.wantErr)
}
})
}
}
func TestListImpotsCategories_DefaultCategories(t *testing.T) {
client := NewImpotsClient(30 * time.Second)
categories := client.getDefaultImpotsCategories()
if len(categories) == 0 {
t.Fatal("getDefaultImpotsCategories returned empty slice")
}
expectedCategories := []string{"Particulier", "Professionnel", "Partenaire", "Collectivité", "International"}
if len(categories) != len(expectedCategories) {
t.Errorf("expected %d categories, got %d", len(expectedCategories), len(categories))
}
for i, cat := range categories {
if cat.Name != expectedCategories[i] {
t.Errorf("expected category %s, got %s", expectedCategories[i], cat.Name)
}
if cat.Description == "" {
t.Errorf("category %s has empty description", cat.Name)
}
if cat.URL == "" {
t.Errorf("category %s has empty URL", cat.Name)
}
}
}
func TestFallbackImpotsSearch(t *testing.T) {
client := NewImpotsClient(30 * time.Second)
ctx := context.Background()
results, err := client.fallbackImpotsSearch(ctx, "test query", 10)
if err != nil {
t.Fatalf("fallbackImpotsSearch returned error: %v", err)
}
if len(results) == 0 {
t.Fatal("fallbackImpotsSearch returned empty results")
}
if results[0].Title == "" {
t.Error("fallback result has empty title")
}
if results[0].URL == "" {
t.Error("fallback result has empty URL")
}
}