ultisuite-backend/internal/mail/webhooks/executor_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

59 lines
1.4 KiB
Go

package webhooks
import "testing"
func TestInterpolate(t *testing.T) {
ctx := &MessageContext{
SenderName: "Alice Example",
SenderEmail: "alice@example.com",
Subject: "Hello World",
BodyText: "Plain body",
BodyHTML: "<p>HTML body</p>",
Date: "2026-05-22T10:00:00Z",
Recipients: "bob@example.com",
HasAttachment: true,
MessageID: "msg-123",
}
template := `{
"from": "$sender.name <$sender.email>",
"subject": "$subject",
"text": "$body.textContent",
"html": "$body.htmlContent",
"date": "$date",
"to": "$recipients.to",
"id": "$message_id"
}`
want := `{
"from": "Alice Example <alice@example.com>",
"subject": "Hello World",
"text": "Plain body",
"html": "<p>HTML body</p>",
"date": "2026-05-22T10:00:00Z",
"to": "bob@example.com",
"id": "msg-123"
}`
if got := interpolate(template, ctx); got != want {
t.Fatalf("interpolate() =\n%s\nwant\n%s", got, want)
}
}
func TestInterpolate_unknownVariablesUnchanged(t *testing.T) {
ctx := &MessageContext{Subject: "Test"}
got := interpolate("Subject: $subject, Extra: $unknown.var", ctx)
want := "Subject: Test, Extra: $unknown.var"
if got != want {
t.Fatalf("interpolate() = %q, want %q", got, want)
}
}
func TestInterpolate_emptyContext(t *testing.T) {
got := interpolate("$sender.email $subject", &MessageContext{})
want := " "
if got != want {
t.Fatalf("interpolate() = %q, want %q", got, want)
}
}