Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add tests for MSC3874, filtering messages by relation type #547

Merged
merged 3 commits into from
Nov 1, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ jobs:
matrix:
include:
- homeserver: Synapse
tags: synapse_blacklist msc3083 msc3787 faster_joins
tags: synapse_blacklist msc3083 msc3787 msc3874 faster_joins
env: "COMPLEMENT_SHARE_ENV_PREFIX=PASS_ PASS_SYNAPSE_COMPLEMENT_DATABASE=sqlite"
timeout: 20m

Expand Down
172 changes: 172 additions & 0 deletions tests/csapi/room_messages_relation_filter_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,172 @@
//go:build msc3874
// +build msc3874

package csapi_tests

import (
"net/http"
"net/url"
"testing"

"github.com/tidwall/gjson"

"github.com/matrix-org/complement/internal/b"
"github.com/matrix-org/complement/internal/client"
"github.com/matrix-org/complement/internal/match"
"github.com/matrix-org/complement/internal/must"
"github.com/matrix-org/complement/runtime"
)

func TestFilterMessagesByRelType(t *testing.T) {
runtime.SkipIf(t, runtime.Dendrite) // flakey
deployment := Deploy(t, b.BlueprintAlice)
defer deployment.Destroy(t)

alice := deployment.Client(t, "hs1", "@alice:hs1")

roomID := alice.CreateRoom(t, map[string]interface{}{"preset": "public_chat"})

// A token which only has the messages of interest after it.
beforeToken := alice.MustSyncUntil(t, client.SyncReq{})

// Send messages with different relations.
res := alice.MustDoFunc(t, "PUT", []string{"_matrix", "client", "v3", "rooms", roomID, "send", "m.room.message", "txn-1"}, client.WithJSONBody(t, map[string]interface{}{
"msgtype": "m.text",
"body": "Message without a relation",
}))
rootEventID := client.GetJSONFieldStr(t, client.ParseJSON(t, res), "event_id")

res = alice.MustDoFunc(t, "PUT", []string{"_matrix", "client", "v3", "rooms", roomID, "send", "m.room.message", "txn-2"}, client.WithJSONBody(t, map[string]interface{}{
"msgtype": "m.text",
"body": "Threaded Reply",
"m.relates_to": map[string]interface{}{
"event_id": rootEventID,
"rel_type": "m.thread",
},
}))
threadEventID := client.GetJSONFieldStr(t, client.ParseJSON(t, res), "event_id")

res = alice.MustDoFunc(t, "PUT", []string{"_matrix", "client", "v3", "rooms", roomID, "send", "m.room.message", "txn-3"}, client.WithJSONBody(t, map[string]interface{}{
"msgtype": "m.text",
"body": "Reference Reply",
"m.relates_to": map[string]interface{}{
"event_id": rootEventID,
"rel_type": "m.reference",
},
}))
referenceEventID := client.GetJSONFieldStr(t, client.ParseJSON(t, res), "event_id")

// sync until the server has processed it
alice.MustSyncUntil(t, client.SyncReq{Since: beforeToken}, client.SyncTimelineHas(roomID, func(r gjson.Result) bool {
return r.Get("type").Str == "m.room.message" && r.Get("event_id").Str == referenceEventID
}))

// Filter to only threaded events.
queryParams := url.Values{}
queryParams.Set("dir", "f")
queryParams.Set("from", beforeToken)
queryParams.Set("filter", `{ "org.matrix.msc3874.rel_types" : ["m.thread"] }`)
res = alice.MustDoFunc(t, "GET", []string{"_matrix", "client", "v3", "rooms", roomID, "messages"}, client.WithQueries(queryParams))
must.MatchResponse(t, res, match.HTTPResponse{
StatusCode: http.StatusOK,
JSON: []match.JSON{
match.JSONCheckOff("chunk", []interface{}{
threadEventID,
}, func(r gjson.Result) interface{} {
return r.Get("event_id").Str
}, nil,
),
},
})

// Filtering to only references.
queryParams = url.Values{}
queryParams.Set("dir", "f")
queryParams.Set("from", beforeToken)
queryParams.Set("filter", `{ "org.matrix.msc3874.rel_types" : ["m.reference"] }`)
res = alice.MustDoFunc(t, "GET", []string{"_matrix", "client", "v3", "rooms", roomID, "messages"}, client.WithQueries(queryParams))
must.MatchResponse(t, res, match.HTTPResponse{
StatusCode: http.StatusOK,
JSON: []match.JSON{
match.JSONCheckOff("chunk", []interface{}{
referenceEventID,
}, func(r gjson.Result) interface{} {
return r.Get("event_id").Str
}, nil,
),
},
})

// Filter to references or threads.
queryParams = url.Values{}
queryParams.Set("dir", "f")
queryParams.Set("from", beforeToken)
queryParams.Set("filter", `{ "org.matrix.msc3874.rel_types" : ["m.thread", "m.reference"] }`)
res = alice.MustDoFunc(t, "GET", []string{"_matrix", "client", "v3", "rooms", roomID, "messages"}, client.WithQueries(queryParams))
must.MatchResponse(t, res, match.HTTPResponse{
StatusCode: http.StatusOK,
JSON: []match.JSON{
match.JSONCheckOff("chunk", []interface{}{
threadEventID, referenceEventID,
}, func(r gjson.Result) interface{} {
return r.Get("event_id").Str
}, nil,
),
},
})

// Filter to not threaded events.
queryParams = url.Values{}
queryParams.Set("dir", "f")
queryParams.Set("from", beforeToken)
queryParams.Set("filter", `{ "org.matrix.msc3874.not_rel_types" : ["m.thread"] }`)
res = alice.MustDoFunc(t, "GET", []string{"_matrix", "client", "v3", "rooms", roomID, "messages"}, client.WithQueries(queryParams))
must.MatchResponse(t, res, match.HTTPResponse{
StatusCode: http.StatusOK,
JSON: []match.JSON{
match.JSONCheckOff("chunk", []interface{}{
rootEventID, referenceEventID,
}, func(r gjson.Result) interface{} {
return r.Get("event_id").Str
}, nil,
),
},
})

// Filtering to not references.
queryParams = url.Values{}
queryParams.Set("dir", "f")
queryParams.Set("from", beforeToken)
queryParams.Set("filter", `{ "org.matrix.msc3874.not_rel_types" : ["m.reference"] }`)
res = alice.MustDoFunc(t, "GET", []string{"_matrix", "client", "v3", "rooms", roomID, "messages"}, client.WithQueries(queryParams))
must.MatchResponse(t, res, match.HTTPResponse{
StatusCode: http.StatusOK,
JSON: []match.JSON{
match.JSONCheckOff("chunk", []interface{}{
rootEventID, threadEventID,
}, func(r gjson.Result) interface{} {
return r.Get("event_id").Str
}, nil,
),
},
})

// Filter to not references or threads.
queryParams = url.Values{}
queryParams.Set("dir", "f")
queryParams.Set("from", beforeToken)
queryParams.Set("filter", `{ "org.matrix.msc3874.not_rel_types" : ["m.thread", "m.reference"] }`)
res = alice.MustDoFunc(t, "GET", []string{"_matrix", "client", "v3", "rooms", roomID, "messages"}, client.WithQueries(queryParams))
must.MatchResponse(t, res, match.HTTPResponse{
StatusCode: http.StatusOK,
JSON: []match.JSON{
match.JSONCheckOff("chunk", []interface{}{
rootEventID,
}, func(r gjson.Result) interface{} {
return r.Get("event_id").Str
}, nil,
),
},
})

}