-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathinbound_test.go
More file actions
154 lines (130 loc) · 3.37 KB
/
Copy pathinbound_test.go
File metadata and controls
154 lines (130 loc) · 3.37 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
148
149
150
151
152
153
154
package inboundgo
import (
"testing"
)
func TestNewClient(t *testing.T) {
// Test successful client creation
client, err := NewClient("test-api-key")
if err != nil {
t.Fatalf("Expected no error, got %v", err)
}
if client == nil {
t.Fatal("Expected client to be non-nil")
}
if client.apiKey != "test-api-key" {
t.Errorf("Expected API key 'test-api-key', got '%s'", client.apiKey)
}
if client.baseURL != "https://inbound.new/api/v2" {
t.Errorf("Expected default base URL 'https://inbound.new/api/v2', got '%s'", client.baseURL)
}
}
func TestNewClientWithCustomBaseURL(t *testing.T) {
customURL := "https://custom-api.example.com"
client, err := NewClient("test-api-key", customURL)
if err != nil {
t.Fatalf("Expected no error, got %v", err)
}
if client.baseURL != customURL {
t.Errorf("Expected base URL '%s', got '%s'", customURL, client.baseURL)
}
}
func TestNewClientEmptyAPIKey(t *testing.T) {
_, err := NewClient("")
if err == nil {
t.Fatal("Expected error for empty API key, got nil")
}
expectedError := "API key is required"
if err.Error() != expectedError {
t.Errorf("Expected error '%s', got '%s'", expectedError, err.Error())
}
}
func TestHelperFunctions(t *testing.T) {
// Test String helper
s := "test"
ptr := String(s)
if ptr == nil {
t.Fatal("String() returned nil")
}
if *ptr != s {
t.Errorf("Expected '%s', got '%s'", s, *ptr)
}
// Test Int helper
i := 42
intPtr := Int(i)
if intPtr == nil {
t.Fatal("Int() returned nil")
}
if *intPtr != i {
t.Errorf("Expected %d, got %d", i, *intPtr)
}
// Test Bool helper
b := true
boolPtr := Bool(b)
if boolPtr == nil {
t.Fatal("Bool() returned nil")
}
if *boolPtr != b {
t.Errorf("Expected %v, got %v", b, *boolPtr)
}
}
func TestServiceInitialization(t *testing.T) {
client, err := NewClient("test-api-key")
if err != nil {
t.Fatalf("Failed to create client: %v", err)
}
// Test that all services can be accessed
if client.Mail() == nil {
t.Error("Mail service should not be nil")
}
if client.Email() == nil {
t.Error("Email service should not be nil")
}
if client.Domain() == nil {
t.Error("Domain service should not be nil")
}
if client.Endpoint() == nil {
t.Error("Endpoint service should not be nil")
}
// Test nested email address service
emailService := client.Email()
if emailService.Address == nil {
t.Error("Email address service should not be nil")
}
}
func TestBuildQueryString(t *testing.T) {
// Test with nil params
result := buildQueryString(nil)
if result != "" {
t.Errorf("Expected empty string for nil params, got '%s'", result)
}
// Test with struct
params := struct {
Limit *int `json:"limit,omitempty"`
Status string `json:"status,omitempty"`
Active *bool `json:"active,omitempty"`
}{
Limit: Int(10),
Status: "verified",
Active: Bool(true),
}
result = buildQueryString(params)
// Should contain all parameters
if result == "" {
t.Error("Expected non-empty query string")
}
// Should start with ?
if result[0] != '?' {
t.Errorf("Expected query string to start with '?', got '%s'", result)
}
}
func TestWithHTTPClient(t *testing.T) {
client, err := NewClient("test-api-key")
if err != nil {
t.Fatalf("Failed to create client: %v", err)
}
// Test method chaining
result := client.WithHTTPClient(nil)
if result != client {
t.Error("WithHTTPClient should return the same client instance")
}
}