mirror of
https://github.com/Rain-kl/OpenFlare.git
synced 2026-10-08 16:46:37 +08:00
feat(upload): mount existing my/update/download routes on user API
This commit is contained in:
@@ -126,6 +126,10 @@ func (p *Plugin) Apply(ctx *core.Context) error {
|
|||||||
uploadGroup.GET("", handler.ListFiles)
|
uploadGroup.GET("", handler.ListFiles)
|
||||||
uploadGroup.DELETE("/:id", handler.DeleteFile)
|
uploadGroup.DELETE("/:id", handler.DeleteFile)
|
||||||
uploadGroup.POST("/batch-download", handler.BatchDownloadFiles)
|
uploadGroup.POST("/batch-download", handler.BatchDownloadFiles)
|
||||||
|
uploadGroup.GET("/my", handler.ListMyFiles)
|
||||||
|
uploadGroup.PUT("/:id", handler.UpdateMyFile)
|
||||||
|
uploadGroup.GET("/download/:id", handler.DownloadFile)
|
||||||
|
uploadGroup.POST("/download/batch", handler.BatchDownloadFiles)
|
||||||
}
|
}
|
||||||
|
|
||||||
adminUploadGroup := ctx.Router().Group("/api/v1/admin/uploads", loginMW)
|
adminUploadGroup := ctx.Router().Group("/api/v1/admin/uploads", loginMW)
|
||||||
|
|||||||
@@ -0,0 +1,53 @@
|
|||||||
|
// Copyright 2026 Arctel.net
|
||||||
|
// SPDX-License-Identifier: Apache-2.0
|
||||||
|
|
||||||
|
package upload
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"testing"
|
||||||
|
|
||||||
|
"github.com/gin-gonic/gin"
|
||||||
|
|
||||||
|
"Wavelet/core"
|
||||||
|
"Wavelet/core/contracts"
|
||||||
|
)
|
||||||
|
|
||||||
|
type stubDBService struct{ contracts.DBService }
|
||||||
|
|
||||||
|
type stubStorageService struct{ contracts.StorageService }
|
||||||
|
|
||||||
|
type stubAuthService struct{ contracts.AuthService }
|
||||||
|
|
||||||
|
func (stubAuthService) RequireAuthMiddleware() any {
|
||||||
|
return gin.HandlerFunc(func(c *gin.Context) { c.Next() })
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestUserUploadRoutes(t *testing.T) {
|
||||||
|
gin.SetMode(gin.TestMode)
|
||||||
|
ctx := core.NewContext(context.Background())
|
||||||
|
core.Provide[contracts.DBService](ctx, stubDBService{})
|
||||||
|
core.Provide[contracts.StorageService](ctx, stubStorageService{})
|
||||||
|
core.Provide[contracts.AuthService](ctx, stubAuthService{})
|
||||||
|
if err := New().Apply(ctx); err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
want := []string{
|
||||||
|
"GET /api/v1/upload/my",
|
||||||
|
"PUT /api/v1/upload/:id",
|
||||||
|
"GET /api/v1/upload/download/:id",
|
||||||
|
"POST /api/v1/upload/download/batch",
|
||||||
|
"GET /api/v1/upload",
|
||||||
|
"POST /api/v1/upload/batch-download",
|
||||||
|
}
|
||||||
|
found := make(map[string]bool, len(want))
|
||||||
|
for _, rd := range ctx.Router().Routes() {
|
||||||
|
found[rd.Method+" "+rd.Path] = true
|
||||||
|
}
|
||||||
|
for _, key := range want {
|
||||||
|
if !found[key] {
|
||||||
|
t.Errorf("missing route %s", key)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user