ultisuite-backend/internal/api/mail/folders_test.go
R3D347HR4Y 95196f7777 Add mail attachment and draft management features
- Introduced new functionality for managing email attachments and drafts in the mail API.
- Added handlers for listing, uploading, and downloading message attachments in `internal/api/mail/handlers_attachments.go`.
- Implemented draft management endpoints for creating, updating, and deleting drafts in `internal/api/mail/handlers_drafts.go`.
- Created new service methods for handling draft and attachment operations in `internal/api/mail/drafts.go` and `internal/api/mail/storage.go`.
- Added validation and error handling for draft and attachment operations.
- Included unit tests for draft and folder functionalities in `internal/api/mail/drafts_test.go` and `internal/api/mail/folders_test.go`.
- Updated API routes to support new draft and attachment features, enhancing overall mail management capabilities.
2026-05-22 17:14:36 +02:00

65 lines
1.8 KiB
Go

package mail
import (
"net/http"
"net/http/httptest"
"testing"
"github.com/go-chi/chi/v5"
"github.com/ultisuite/ulti-backend/internal/api/middleware"
"github.com/ultisuite/ulti-backend/internal/auth"
)
func TestValidateCreateFolder(t *testing.T) {
t.Run("invalid folder_type", func(t *testing.T) {
req := &createFolderRequest{
AccountID: "acc-1",
Name: "Work",
FolderType: "bogus",
}
if verr := validateCreateFolder(req); verr == nil {
t.Fatal("expected validation error for folder_type")
}
})
t.Run("missing account_id", func(t *testing.T) {
req := &createFolderRequest{Name: "Work"}
if verr := validateCreateFolder(req); verr == nil {
t.Fatal("expected validation error for account_id")
}
})
}
func TestListFoldersRequiresAccountID(t *testing.T) {
svc := newFakeMailService()
h := NewHandlerWithService(svc)
r := chi.NewRouter()
r.Use(middleware.WithTestClaims(&auth.Claims{Sub: testExternalID, Email: "user@example.com"}))
r.Mount("/", h.FolderLabelRoutes())
req := httptest.NewRequest(http.MethodGet, "/folders", nil)
rec := httptest.NewRecorder()
r.ServeHTTP(rec, req)
if rec.Code != http.StatusBadRequest {
t.Fatalf("status = %d, want %d; body = %s", rec.Code, http.StatusBadRequest, rec.Body.String())
}
}
func TestListFoldersWithAccountID(t *testing.T) {
svc := newFakeMailService()
h := NewHandlerWithService(svc)
r := chi.NewRouter()
r.Use(middleware.WithTestClaims(&auth.Claims{Sub: testExternalID, Email: "user@example.com"}))
r.Mount("/", h.FolderLabelRoutes())
req := httptest.NewRequest(http.MethodGet, "/folders?account_id=acc-1", nil)
rec := httptest.NewRecorder()
r.ServeHTTP(rec, req)
if rec.Code != http.StatusOK {
t.Fatalf("status = %d, want %d; body = %s", rec.Code, http.StatusOK, rec.Body.String())
}
}