Some checks failed
ci/woodpecker/push/woodpecker Pipeline failed
Complete MVP implementation of the Cast GHL Conversation Provider bridge: - Go module setup with chi router and mongo-driver dependencies - Config loading with env var validation and defaults - MongoDB token store with upsert, get, update, delete operations - Cast.ph SMS client with 429 retry logic and typed errors - Phone number normalization (E.164 ↔ Philippine local format) - GHL OAuth 2.0 install/callback/refresh flow - GHL webhook handler with ECDSA signature verification (async dispatch) - GHL API client for message status updates and inbound message stubs - Multi-stage Dockerfile, docker-compose with MongoDB, Woodpecker CI pipeline - Unit tests for phone normalization, Cast client, GHL webhook, and OAuth handlers Co-Authored-By: SideKx <sidekx.ai@sds.dev>
66 lines
1.9 KiB
Go
66 lines
1.9 KiB
Go
package phone
|
|
|
|
import "testing"
|
|
|
|
func TestToLocal(t *testing.T) {
|
|
tests := []struct {
|
|
name string
|
|
input string
|
|
want string
|
|
wantErr bool
|
|
}{
|
|
{"e164 with plus", "+639171234567", "09171234567", false},
|
|
{"e164 without plus", "639171234567", "09171234567", false},
|
|
{"already local", "09171234567", "09171234567", false},
|
|
{"missing leading zero", "9171234567", "09171234567", false},
|
|
{"non-PH number", "+1234567890", "", true},
|
|
{"empty", "", "", true},
|
|
{"with spaces", "+63 917 123 4567", "09171234567", false},
|
|
{"with dashes", "0917-123-4567", "09171234567", false},
|
|
{"too short", "0917", "", true},
|
|
{"too long", "091712345678", "", true},
|
|
}
|
|
for _, tt := range tests {
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
got, err := ToLocal(tt.input)
|
|
if (err != nil) != tt.wantErr {
|
|
t.Errorf("ToLocal(%q) error = %v, wantErr %v", tt.input, err, tt.wantErr)
|
|
return
|
|
}
|
|
if got != tt.want {
|
|
t.Errorf("ToLocal(%q) = %q, want %q", tt.input, got, tt.want)
|
|
}
|
|
})
|
|
}
|
|
}
|
|
|
|
func TestToE164(t *testing.T) {
|
|
tests := []struct {
|
|
name string
|
|
input string
|
|
want string
|
|
wantErr bool
|
|
}{
|
|
{"standard local", "09171234567", "+639171234567", false},
|
|
{"missing leading zero", "9171234567", "+639171234567", false},
|
|
{"already e164", "+639171234567", "+639171234567", false},
|
|
{"e164 without plus", "639171234567", "+639171234567", false},
|
|
{"with spaces", "0917 123 4567", "+639171234567", false},
|
|
{"with dashes", "0917-123-4567", "+639171234567", false},
|
|
{"empty", "", "", true},
|
|
{"too short", "0917", "", true},
|
|
}
|
|
for _, tt := range tests {
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
got, err := ToE164(tt.input)
|
|
if (err != nil) != tt.wantErr {
|
|
t.Errorf("ToE164(%q) error = %v, wantErr %v", tt.input, err, tt.wantErr)
|
|
return
|
|
}
|
|
if got != tt.want {
|
|
t.Errorf("ToE164(%q) = %q, want %q", tt.input, got, tt.want)
|
|
}
|
|
})
|
|
}
|
|
}
|