Skip to content
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
75 changes: 75 additions & 0 deletions tests/csapi/public_rooms_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
package csapi_tests

import (
"net/http"
"testing"
"time"

"github.com/tidwall/gjson"

"github.com/matrix-org/complement"
"github.com/matrix-org/complement/client"
"github.com/matrix-org/complement/helpers"
"github.com/matrix-org/complement/match"
"github.com/matrix-org/complement/must"
)

func TestPublicRooms(t *testing.T) {
deployment := complement.Deploy(t, 1)
defer deployment.Destroy(t)

t.Run("parallel", func(t *testing.T) {
// sytest: Can search public room list
t.Run("Can search public room list", func(t *testing.T) {
t.Parallel()
authedClient := deployment.Register(t, "hs1", helpers.RegistrationOpts{})

roomID := authedClient.MustCreateRoom(t, map[string]any{
"visibility": "public",
"name": "Test Name",
"topic": "Test Topic Wombles",
})

authedClient.MustDo(
t,
"POST",
[]string{"_matrix", "client", "v3", "publicRooms"},
client.WithJSONBody(t, map[string]any{
"filter": map[string]any{
"generic_search_term": "wombles",
},
}),
client.WithRetryUntil(15*time.Second, func(res *http.Response) bool {
body := must.ParseJSON(t, res.Body)

must.MatchGJSON(
t,
body,
match.JSONKeyPresent("chunk"),
match.JSONKeyTypeEqual("chunk", gjson.JSON),
)

chunk := body.Get("chunk")
if !chunk.IsArray() {
t.Logf("chunk is not an array")
return false
}

results := chunk.Array()
if len(results) != 1 {
t.Logf("expected a single search result, got %d", len(results))
return false
}

foundRoomID := results[0].Get("room_id").Str
if foundRoomID != roomID {
t.Logf("expected room_id %s in search results, got %s", roomID, foundRoomID)
return false
}

return true
}),
)
})
})
}
12 changes: 1 addition & 11 deletions tests/restricted_rooms_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -326,17 +326,7 @@ func doTestRestrictedRoomsRemoteJoinLocalUser(t *testing.T, roomVersion string,
charlie.MustLeaveRoom(t, room)

// Ensure the events have synced to hs1.
alice.MustSyncUntil(t, client.SyncReq{}, client.SyncTimelineHas(
room,
func(ev gjson.Result) bool {
if ev.Get("type").Str != "m.room.member" || ev.Get("state_key").Str != charlie.UserID {
return false
}
must.Equal(t, ev.Get("content").Get("membership").Str, "leave", "Charlie failed to leave the room")

return true
},
))
alice.MustSyncUntil(t, client.SyncReq{}, client.SyncLeftFrom(charlie.UserID, room))

// Have bob leave and rejoin. This should still work even though hs2 isn't in
// the room anymore!
Expand Down
Loading