mirror of
https://github.com/superseriousbusiness/gotosocial
synced 2025-06-05 21:59:39 +02:00
[chore] The Big Middleware and API Refactor (tm) (#1250)
* interim commit: start refactoring middlewares into package under router * another interim commit, this is becoming a big job * another fucking massive interim commit * refactor bookmarks to new style * ambassador, wiz zeze commits you are spoiling uz * she compiles, we're getting there * we're just normal men; we're just innocent men * apiutil * whoopsie * i'm glad noone reads commit msgs haha :blob_sweat: * use that weirdo go-bytesize library for maxMultipartMemory * fix media module paths
This commit is contained in:
@@ -30,10 +30,9 @@ import (
|
||||
"net/http/httptest"
|
||||
"testing"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
"github.com/stretchr/testify/suite"
|
||||
mediamodule "github.com/superseriousbusiness/gotosocial/internal/api/client/media"
|
||||
"github.com/superseriousbusiness/gotosocial/internal/api/model"
|
||||
apimodel "github.com/superseriousbusiness/gotosocial/internal/api/model"
|
||||
"github.com/superseriousbusiness/gotosocial/internal/concurrency"
|
||||
"github.com/superseriousbusiness/gotosocial/internal/config"
|
||||
"github.com/superseriousbusiness/gotosocial/internal/db"
|
||||
@@ -96,7 +95,7 @@ func (suite *MediaCreateTestSuite) SetupSuite() {
|
||||
suite.processor = testrig.NewTestProcessor(suite.db, suite.storage, suite.federator, suite.emailSender, suite.mediaManager, clientWorker, fedWorker)
|
||||
|
||||
// setup module being tested
|
||||
suite.mediaModule = mediamodule.New(suite.processor).(*mediamodule.Module)
|
||||
suite.mediaModule = mediamodule.New(suite.processor)
|
||||
}
|
||||
|
||||
func (suite *MediaCreateTestSuite) TearDownSuite() {
|
||||
@@ -158,12 +157,7 @@ func (suite *MediaCreateTestSuite) TestMediaCreateSuccessful() {
|
||||
ctx.Request = httptest.NewRequest(http.MethodPost, "http://localhost:8080/api/v1/media", bytes.NewReader(buf.Bytes())) // the endpoint we're hitting
|
||||
ctx.Request.Header.Set("Content-Type", w.FormDataContentType())
|
||||
ctx.Request.Header.Set("accept", "application/json")
|
||||
ctx.Params = gin.Params{
|
||||
gin.Param{
|
||||
Key: mediamodule.APIVersionKey,
|
||||
Value: "v1",
|
||||
},
|
||||
}
|
||||
ctx.AddParam(mediamodule.APIVersionKey, mediamodule.APIv1)
|
||||
|
||||
// do the actual request
|
||||
suite.mediaModule.MediaCreatePOSTHandler(ctx)
|
||||
@@ -188,26 +182,26 @@ func (suite *MediaCreateTestSuite) TestMediaCreateSuccessful() {
|
||||
suite.NoError(err)
|
||||
fmt.Println(string(b))
|
||||
|
||||
attachmentReply := &model.Attachment{}
|
||||
attachmentReply := &apimodel.Attachment{}
|
||||
err = json.Unmarshal(b, attachmentReply)
|
||||
suite.NoError(err)
|
||||
|
||||
suite.Equal("this is a test image -- a cool background from somewhere", *attachmentReply.Description)
|
||||
suite.Equal("image", attachmentReply.Type)
|
||||
suite.EqualValues(model.MediaMeta{
|
||||
Original: model.MediaDimensions{
|
||||
suite.EqualValues(apimodel.MediaMeta{
|
||||
Original: apimodel.MediaDimensions{
|
||||
Width: 1920,
|
||||
Height: 1080,
|
||||
Size: "1920x1080",
|
||||
Aspect: 1.7777778,
|
||||
},
|
||||
Small: model.MediaDimensions{
|
||||
Small: apimodel.MediaDimensions{
|
||||
Width: 512,
|
||||
Height: 288,
|
||||
Size: "512x288",
|
||||
Aspect: 1.7777778,
|
||||
},
|
||||
Focus: model.MediaFocus{
|
||||
Focus: apimodel.MediaFocus{
|
||||
X: -0.5,
|
||||
Y: 0.5,
|
||||
},
|
||||
@@ -252,12 +246,7 @@ func (suite *MediaCreateTestSuite) TestMediaCreateSuccessfulV2() {
|
||||
ctx.Request = httptest.NewRequest(http.MethodPost, "http://localhost:8080/api/v2/media", bytes.NewReader(buf.Bytes())) // the endpoint we're hitting
|
||||
ctx.Request.Header.Set("Content-Type", w.FormDataContentType())
|
||||
ctx.Request.Header.Set("accept", "application/json")
|
||||
ctx.Params = gin.Params{
|
||||
gin.Param{
|
||||
Key: mediamodule.APIVersionKey,
|
||||
Value: "v2",
|
||||
},
|
||||
}
|
||||
ctx.AddParam(mediamodule.APIVersionKey, mediamodule.APIv2)
|
||||
|
||||
// do the actual request
|
||||
suite.mediaModule.MediaCreatePOSTHandler(ctx)
|
||||
@@ -282,26 +271,26 @@ func (suite *MediaCreateTestSuite) TestMediaCreateSuccessfulV2() {
|
||||
suite.NoError(err)
|
||||
fmt.Println(string(b))
|
||||
|
||||
attachmentReply := &model.Attachment{}
|
||||
attachmentReply := &apimodel.Attachment{}
|
||||
err = json.Unmarshal(b, attachmentReply)
|
||||
suite.NoError(err)
|
||||
|
||||
suite.Equal("this is a test image -- a cool background from somewhere", *attachmentReply.Description)
|
||||
suite.Equal("image", attachmentReply.Type)
|
||||
suite.EqualValues(model.MediaMeta{
|
||||
Original: model.MediaDimensions{
|
||||
suite.EqualValues(apimodel.MediaMeta{
|
||||
Original: apimodel.MediaDimensions{
|
||||
Width: 1920,
|
||||
Height: 1080,
|
||||
Size: "1920x1080",
|
||||
Aspect: 1.7777778,
|
||||
},
|
||||
Small: model.MediaDimensions{
|
||||
Small: apimodel.MediaDimensions{
|
||||
Width: 512,
|
||||
Height: 288,
|
||||
Size: "512x288",
|
||||
Aspect: 1.7777778,
|
||||
},
|
||||
Focus: model.MediaFocus{
|
||||
Focus: apimodel.MediaFocus{
|
||||
X: -0.5,
|
||||
Y: 0.5,
|
||||
},
|
||||
@@ -342,12 +331,7 @@ func (suite *MediaCreateTestSuite) TestMediaCreateLongDescription() {
|
||||
ctx.Request = httptest.NewRequest(http.MethodPost, "http://localhost:8080/api/v1/media", bytes.NewReader(buf.Bytes())) // the endpoint we're hitting
|
||||
ctx.Request.Header.Set("Content-Type", w.FormDataContentType())
|
||||
ctx.Request.Header.Set("accept", "application/json")
|
||||
ctx.Params = gin.Params{
|
||||
gin.Param{
|
||||
Key: mediamodule.APIVersionKey,
|
||||
Value: "v1",
|
||||
},
|
||||
}
|
||||
ctx.AddParam(mediamodule.APIVersionKey, mediamodule.APIv1)
|
||||
|
||||
// do the actual request
|
||||
suite.mediaModule.MediaCreatePOSTHandler(ctx)
|
||||
@@ -388,12 +372,7 @@ func (suite *MediaCreateTestSuite) TestMediaCreateTooShortDescription() {
|
||||
ctx.Request = httptest.NewRequest(http.MethodPost, "http://localhost:8080/api/v1/media", bytes.NewReader(buf.Bytes())) // the endpoint we're hitting
|
||||
ctx.Request.Header.Set("Content-Type", w.FormDataContentType())
|
||||
ctx.Request.Header.Set("accept", "application/json")
|
||||
ctx.Params = gin.Params{
|
||||
gin.Param{
|
||||
Key: mediamodule.APIVersionKey,
|
||||
Value: "v1",
|
||||
},
|
||||
}
|
||||
ctx.AddParam(mediamodule.APIVersionKey, mediamodule.APIv1)
|
||||
|
||||
// do the actual request
|
||||
suite.mediaModule.MediaCreatePOSTHandler(ctx)
|
||||
|
Reference in New Issue
Block a user