ultisuite-backend/internal/mail/smtp/outbox_test.go
R3D347HR4Y 747e0d4bb4 Add CI workflow and unit tests for mail API
- Created a CI workflow in `.github/workflows/ci.yml` to run Go tests and verify database migrations.
- Added unit tests for the mail API in `internal/api/mail/handlers_test.go`, covering message listing, retrieval, sending, and label updating.
- Introduced a service interface for the mail handler in `internal/api/mail/service_iface.go`.
- Updated mail handler initialization to accept a service API in `internal/api/mail/handlers.go`.
- Implemented test authentication middleware for testing purposes in `internal/api/middleware/testauth.go`.
- Added various test cases for IMAP and SMTP functionalities, ensuring robust error handling and validation.
- Enhanced project documentation with checklist updates for testing and CI integration.
2026-05-22 17:02:37 +02:00

53 lines
1.5 KiB
Go

package smtp
import (
"reflect"
"testing"
)
func TestParseJSONAddresses_structured(t *testing.T) {
data := []byte(`[{"address":"alice@example.com"},{"address":"bob@example.com"}]`)
got := parseJSONAddresses(data)
want := []string{"alice@example.com", "bob@example.com"}
if !reflect.DeepEqual(got, want) {
t.Fatalf("parseJSONAddresses() = %v, want %v", got, want)
}
}
func TestParseJSONAddresses_plainStrings(t *testing.T) {
data := []byte(`["alice@example.com","bob@example.com"]`)
got := parseJSONAddresses(data)
want := []string{"alice@example.com", "bob@example.com"}
if !reflect.DeepEqual(got, want) {
t.Fatalf("parseJSONAddresses() = %v, want %v", got, want)
}
}
func TestParseJSONAddresses_empty(t *testing.T) {
if got := parseJSONAddresses(nil); got != nil {
t.Fatalf("parseJSONAddresses(nil) = %v, want nil", got)
}
if got := parseJSONAddresses([]byte{}); got != nil {
t.Fatalf("parseJSONAddresses([]) = %v, want nil", got)
}
if got := parseJSONAddresses([]byte(`[]`)); len(got) != 0 {
t.Fatalf("parseJSONAddresses([]) = %v, want empty slice", got)
}
}
func TestParseJSONAddresses_invalid(t *testing.T) {
got := parseJSONAddresses([]byte(`not-json`))
if got != nil {
t.Fatalf("parseJSONAddresses(invalid) = %v, want nil", got)
}
}
func TestParseJSONAddresses_missingAddressField(t *testing.T) {
data := []byte(`[{"name":"Alice"}]`)
got := parseJSONAddresses(data)
want := []string{""}
if !reflect.DeepEqual(got, want) {
t.Fatalf("parseJSONAddresses() = %v, want %v", got, want)
}
}