[feature] add support for polls + receiving federated status edits (#2330)

This commit is contained in:
kim
2023-11-08 14:32:17 +00:00
committed by GitHub
parent 7204ccedc3
commit e9e5dc5a40
84 changed files with 3992 additions and 570 deletions

View File

@ -25,6 +25,7 @@ import (
"net/http"
"net/http/httptest"
"testing"
"time"
"github.com/gin-gonic/gin"
"github.com/stretchr/testify/suite"
@ -101,12 +102,6 @@ func (suite *OutboxGetTestSuite) TestGetOutboxFirstPage() {
signedRequest := derefRequests["foss_satan_dereference_zork_outbox_first"]
targetAccount := suite.testAccounts["local_account_1"]
tc := testrig.NewTestTransportController(&suite.state, testrig.NewMockHTTPClient(nil, "../../../../testrig/media"))
federator := testrig.NewTestFederator(&suite.state, tc, suite.mediaManager)
emailSender := testrig.NewEmailSender("../../../../web/template/", nil)
processor := testrig.NewTestProcessor(&suite.state, federator, emailSender, suite.mediaManager)
userModule := users.New(processor)
// setup request
recorder := httptest.NewRecorder()
ctx, _ := testrig.CreateGinTestContext(recorder, nil)
@ -128,7 +123,7 @@ func (suite *OutboxGetTestSuite) TestGetOutboxFirstPage() {
}
// trigger the function being tested
userModule.OutboxGETHandler(ctx)
suite.userModule.OutboxGETHandler(ctx)
// check response
suite.EqualValues(http.StatusOK, recorder.Code)
@ -137,6 +132,7 @@ func (suite *OutboxGetTestSuite) TestGetOutboxFirstPage() {
defer result.Body.Close()
b, err := ioutil.ReadAll(result.Body)
suite.NoError(err)
b = checkDropPublished(suite.T(), b, "orderedItems")
dst := new(bytes.Buffer)
err = json.Indent(dst, b, "", " ")
suite.NoError(err)
@ -147,9 +143,8 @@ func (suite *OutboxGetTestSuite) TestGetOutboxFirstPage() {
"orderedItems": {
"actor": "http://localhost:8080/users/the_mighty_zork",
"cc": "http://localhost:8080/users/the_mighty_zork/followers",
"id": "http://localhost:8080/users/the_mighty_zork/statuses/01F8MHAMCHF6Y650WCRSCP4WMY/activity",
"id": "http://localhost:8080/users/the_mighty_zork/statuses/01F8MHAMCHF6Y650WCRSCP4WMY/activity#Create",
"object": "http://localhost:8080/users/the_mighty_zork/statuses/01F8MHAMCHF6Y650WCRSCP4WMY",
"published": "2021-10-20T10:40:37Z",
"to": "https://www.w3.org/ns/activitystreams#Public",
"type": "Create"
},
@ -175,12 +170,6 @@ func (suite *OutboxGetTestSuite) TestGetOutboxNextPage() {
signedRequest := derefRequests["foss_satan_dereference_zork_outbox_next"]
targetAccount := suite.testAccounts["local_account_1"]
tc := testrig.NewTestTransportController(&suite.state, testrig.NewMockHTTPClient(nil, "../../../../testrig/media"))
federator := testrig.NewTestFederator(&suite.state, tc, suite.mediaManager)
emailSender := testrig.NewEmailSender("../../../../web/template/", nil)
processor := testrig.NewTestProcessor(&suite.state, federator, emailSender, suite.mediaManager)
userModule := users.New(processor)
// setup request
recorder := httptest.NewRecorder()
ctx, _ := testrig.CreateGinTestContext(recorder, nil)
@ -206,7 +195,7 @@ func (suite *OutboxGetTestSuite) TestGetOutboxNextPage() {
}
// trigger the function being tested
userModule.OutboxGETHandler(ctx)
suite.userModule.OutboxGETHandler(ctx)
// check response
suite.EqualValues(http.StatusOK, recorder.Code)
@ -240,3 +229,30 @@ func (suite *OutboxGetTestSuite) TestGetOutboxNextPage() {
func TestOutboxGetTestSuite(t *testing.T) {
suite.Run(t, new(OutboxGetTestSuite))
}
// checkDropPublished checks the published field at given key position for formatting, and drops from the JSON.
// This is useful because the published property is usually set to the current time string (which is difficult to test).
func checkDropPublished(t *testing.T, b []byte, at ...string) []byte {
m := make(map[string]any)
if err := json.Unmarshal(b, &m); err != nil {
t.Fatalf("error unmarshaling json into map: %v", err)
}
mm := m
for _, key := range at {
switch vt := mm[key].(type) {
case map[string]any:
mm = vt
}
}
if s, ok := mm["published"].(string); !ok {
t.Fatal("missing published data on json")
} else if _, err := time.Parse(time.RFC3339, s); err != nil {
t.Fatalf("error parsing published time: %v", err)
}
delete(mm, "published")
b, err := json.Marshal(m)
if err != nil {
t.Fatalf("error remarshaling json: %v", err)
}
return b
}