61 lines
2.6 KiB
Go
61 lines
2.6 KiB
Go
package api
|
|
|
|
import (
|
|
"net/http"
|
|
"net/http/httptest"
|
|
"strings"
|
|
"testing"
|
|
|
|
"github.com/gofiber/fiber/v3"
|
|
)
|
|
|
|
func TestCreatorWriteRoutesRejectMalformedInputBeforeStoreAccess(t *testing.T) {
|
|
app := fiber.New()
|
|
registerCreatorWithServices(app, nil, nil, nil, nil, nil, nil)
|
|
routes := []struct {
|
|
method string
|
|
path string
|
|
}{
|
|
{method: http.MethodPut, path: "/api/creator/settings"},
|
|
{method: http.MethodPut, path: "/api/creator/accounts/account-1/profile"},
|
|
{method: http.MethodPut, path: "/api/creator/accounts/account-1/tags"},
|
|
{method: http.MethodPost, path: "/api/creator/accounts/account-1/login-result"},
|
|
{method: http.MethodPost, path: "/api/creator/accounts/account-1/big-account"},
|
|
{method: http.MethodPost, path: "/api/creator/relations"},
|
|
{method: http.MethodPost, path: "/api/creator/accounts/account-1/strategies"},
|
|
{method: http.MethodPut, path: "/api/creator/strategies/strategy-1"},
|
|
{method: http.MethodPost, path: "/api/creator/competitors/preview"},
|
|
{method: http.MethodPost, path: "/api/creator/competitors"},
|
|
{method: http.MethodPut, path: "/api/creator/competitors/competitor-1"},
|
|
{method: http.MethodPost, path: "/api/creator/competitors/competitor-1/sync"},
|
|
{method: http.MethodPost, path: "/api/creator/xiaohongshu/search"},
|
|
{method: http.MethodPost, path: "/api/creator/xiaohongshu/detail"},
|
|
{method: http.MethodPost, path: "/api/creator/test/works"},
|
|
{method: http.MethodPost, path: "/api/creator/works/work-1/metrics"},
|
|
{method: http.MethodPost, path: "/api/creator/works/work-1/material/rewrite/confirm"},
|
|
{method: http.MethodPut, path: "/api/creator/works/work-1/material/rewrite"},
|
|
{method: http.MethodPost, path: "/api/creator/test/comments"},
|
|
{method: http.MethodPost, path: "/api/creator/rules"},
|
|
{method: http.MethodPut, path: "/api/creator/rules/rule-1"},
|
|
{method: http.MethodPost, path: "/api/creator/comments/analyze"},
|
|
{method: http.MethodPost, path: "/api/creator/comments/comment-1/analyze"},
|
|
{method: http.MethodPost, path: "/api/creator/test/events"},
|
|
{method: http.MethodPost, path: "/api/creator/events/process"},
|
|
{method: http.MethodPost, path: "/api/creator/messages"},
|
|
}
|
|
for _, route := range routes {
|
|
route := route
|
|
t.Run(route.method+" "+route.path, func(t *testing.T) {
|
|
request := httptest.NewRequest(route.method, route.path, strings.NewReader("{"))
|
|
request.Header.Set("Content-Type", "application/json")
|
|
response, err := app.Test(request)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if response.StatusCode != http.StatusBadRequest && response.StatusCode != http.StatusConflict {
|
|
t.Fatalf("malformed request status = %d", response.StatusCode)
|
|
}
|
|
})
|
|
}
|
|
}
|