Skip to content

Commit

Permalink
Remove duplicate test, update existing tests to check for "room_id" in (
Browse files Browse the repository at this point in the history
#548)

response
  • Loading branch information
S7evinK authored Nov 2, 2022
1 parent f533795 commit ec6e09c
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 58 deletions.
31 changes: 24 additions & 7 deletions tests/csapi/room_members_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import (
"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"
)

// Maps every object by extracting `type` and `state_key` into a "$type|$state_key" string.
Expand Down Expand Up @@ -43,6 +42,10 @@ func TestGetRoomMembers(t *testing.T) {

must.MatchResponse(t, resp, match.HTTPResponse{
JSON: []match.JSON{
match.JSONArrayEach("chunk.#.room_id", func(result gjson.Result) error {
must.EqualStr(t, result.Str, roomID, "unexpected roomID")
return nil
}),
match.JSONCheckOff("chunk",
[]interface{}{
"m.room.member|" + alice.UserID,
Expand All @@ -56,8 +59,6 @@ func TestGetRoomMembers(t *testing.T) {
// Utilize ?at= to get room members at a point in sync.
// sytest: Can get rooms/{roomId}/members at a given point
func TestGetRoomMembersAtPoint(t *testing.T) {
runtime.SkipIf(t, runtime.Dendrite) // FIXME: https://github.com/matrix-org/dendrite/issues/1308

deployment := Deploy(t, b.BlueprintOneToOneRoom)
defer deployment.Destroy(t)

Expand All @@ -76,10 +77,10 @@ func TestGetRoomMembersAtPoint(t *testing.T) {
},
})

_, since_token := alice.MustSync(t, client.SyncReq{TimeoutMillis: "0"})
syncResp, _ := alice.MustSync(t, client.SyncReq{TimeoutMillis: "0"})
sinceToken := syncResp.Get("rooms.join." + client.GjsonEscape(roomID) + ".timeline.prev_batch").Str

bob.JoinRoom(t, roomID, nil)

alice.MustSyncUntil(t, client.SyncReq{}, client.SyncJoinedTo(bob.UserID, roomID))

bob.SendEventSynced(t, roomID, b.Event{
Expand All @@ -95,24 +96,28 @@ func TestGetRoomMembersAtPoint(t *testing.T) {
"GET",
[]string{"_matrix", "client", "v3", "rooms", roomID, "members"},
client.WithQueries(url.Values{
"at": []string{since_token},
"at": []string{sinceToken},
}),
)

must.MatchResponse(t, resp, match.HTTPResponse{
JSON: []match.JSON{
match.JSONArrayEach("chunk.#.room_id", func(result gjson.Result) error {
must.EqualStr(t, result.Str, roomID, "unexpected roomID")
return nil
}),
match.JSONCheckOff("chunk",
[]interface{}{
"m.room.member|" + alice.UserID,
}, typeToStateKeyMapper, nil),
},

StatusCode: 200,
})
}

// sytest: Can filter rooms/{roomId}/members
func TestGetFilteredRoomMembers(t *testing.T) {
runtime.SkipIf(t, runtime.Dendrite) // FIXME: https://github.com/matrix-org/dendrite/issues/1308

deployment := Deploy(t, b.BlueprintOneToOneRoom)
defer deployment.Destroy(t)
Expand Down Expand Up @@ -144,6 +149,10 @@ func TestGetFilteredRoomMembers(t *testing.T) {

must.MatchResponse(t, resp, match.HTTPResponse{
JSON: []match.JSON{
match.JSONArrayEach("chunk.#.room_id", func(result gjson.Result) error {
must.EqualStr(t, result.Str, roomID, "unexpected roomID")
return nil
}),
match.JSONCheckOff("chunk",
[]interface{}{
"m.room.member|" + alice.UserID,
Expand All @@ -165,6 +174,10 @@ func TestGetFilteredRoomMembers(t *testing.T) {

must.MatchResponse(t, resp, match.HTTPResponse{
JSON: []match.JSON{
match.JSONArrayEach("chunk.#.room_id", func(result gjson.Result) error {
must.EqualStr(t, result.Str, roomID, "unexpected roomID")
return nil
}),
match.JSONCheckOff("chunk",
[]interface{}{
"m.room.member|" + bob.UserID,
Expand All @@ -186,6 +199,10 @@ func TestGetFilteredRoomMembers(t *testing.T) {

must.MatchResponse(t, resp, match.HTTPResponse{
JSON: []match.JSON{
match.JSONArrayEach("chunk.#.room_id", func(result gjson.Result) error {
must.EqualStr(t, result.Str, roomID, "unexpected roomID")
return nil
}),
match.JSONCheckOff("chunk",
[]interface{}{
"m.room.member|" + alice.UserID,
Expand Down
51 changes: 0 additions & 51 deletions tests/csapi/rooms_members_local_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,12 @@ package csapi_tests

import (
"fmt"
"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"
)

Expand Down Expand Up @@ -65,51 +62,3 @@ func TestMembersLocal(t *testing.T) {
})

}

// sytest: Can get rooms/{roomId}/members at a given point
func TestMembersAtAGivenPoint(t *testing.T) {
deplyoment := Deploy(t, b.BlueprintOneToOneRoom)
defer deplyoment.Destroy(t)

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

roomID := alice.CreateRoom(t, map[string]interface{}{
"preset": "public_chat",
})
alice.SendEventSynced(t, roomID, b.Event{
Type: "m.room.message",
Content: map[string]interface{}{
"msgtype": "m.text",
"body": "Hello World!",
},
})

resp, _ := alice.MustSync(t, client.SyncReq{})
prevBatch := resp.Get("rooms.join." + client.GjsonEscape(roomID) + ".timeline.prev_batch").Str

bob.JoinRoom(t, roomID, []string{})
alice.MustSyncUntil(t, client.SyncReq{}, client.SyncJoinedTo(bob.UserID, roomID))

alice.SendEventSynced(t, roomID, b.Event{
Type: "m.room.message",
Content: map[string]interface{}{
"msgtype": "m.text",
"body": "Hello back",
},
})

params := url.Values{}
params.Add("at", prevBatch)

roomsResp := alice.MustDoFunc(t, "GET", []string{"_matrix", "client", "v3", "rooms", roomID, "members"}, client.WithQueries(params))
must.MatchResponse(t, roomsResp, match.HTTPResponse{
JSON: []match.JSON{
match.JSONCheckOff("chunk", []interface{}{
alice.UserID,
}, func(r gjson.Result) interface{} {
return r.Get("state_key").Str
}, nil),
},
})
}

0 comments on commit ec6e09c

Please sign in to comment.