summaryrefslogtreecommitdiff
path: root/internal/api/activitypub/users/outboxget_test.go
diff options
context:
space:
mode:
Diffstat (limited to 'internal/api/activitypub/users/outboxget_test.go')
-rw-r--r--internal/api/activitypub/users/outboxget_test.go48
1 files changed, 32 insertions, 16 deletions
diff --git a/internal/api/activitypub/users/outboxget_test.go b/internal/api/activitypub/users/outboxget_test.go
index 1abe31ef6..4829a8946 100644
--- a/internal/api/activitypub/users/outboxget_test.go
+++ b/internal/api/activitypub/users/outboxget_test.go
@@ -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
+}