Skip to content
Merged
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
129 changes: 121 additions & 8 deletions tests/msc2946_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,17 @@ import (
"github.com/tidwall/gjson"
)

var (
spaceChildEventType = "org.matrix.msc1772.space.child"
spaceParentEventType = "org.matrix.msc1772.space.parent"
)

// the API doesn't return event IDs so we need to key off the
// 3-uple of room ID, event type and state key
func eventKey(srcRoomID, dstRoomID, evType string) string {
return srcRoomID + "|" + dstRoomID + "|" + evType
}

// Tests that the CS API for MSC2946 works correctly. Creates a space directory like:
// Root
// |
Expand Down Expand Up @@ -39,8 +50,6 @@ import (
// - Events are returned correctly.
// - Redacting links works correctly.
func TestClientSpacesSummary(t *testing.T) {
spaceChildEventType := "org.matrix.msc1772.space.child"
spaceParentEventType := "org.matrix.msc1772.space.parent"
deployment := Deploy(t, "msc2946", b.BlueprintOneToOneRoom)
defer deployment.Destroy(t)

Expand Down Expand Up @@ -91,12 +100,6 @@ func TestClientSpacesSummary(t *testing.T) {
},
})

// the API doesn't return event IDs so we need to key off the
// 3-uple of room ID, event type and state key
eventKey := func(srcRoomID, dstRoomID, evType string) string {
return srcRoomID + "|" + dstRoomID + "|" + evType
}

// create the links
rootToR1 := eventKey(root, r1, spaceChildEventType)
alice.SendEventSynced(t, root, b.Event{
Expand Down Expand Up @@ -281,3 +284,113 @@ func TestClientSpacesSummary(t *testing.T) {
})
})
}

// Tests that MSC2946 works over federation. Creates a space directory like:
// ROOT
// |
// _____|________
// | | |
// R1 SS1 r2
// |________
// | |
// ss2 r3
// |
// R4
//
// Where R/SS = on hs1, and r/ss = on hs2. Links are space children state events only.
// Tests that:
// - Querying from root returns the entire graph
func TestFederatedClientSpaces(t *testing.T) {
deployment := Deploy(t, "msc2946", b.BlueprintFederationOneToOneRoom)
defer deployment.Destroy(t)

worldReadable := map[string]interface{}{
"preset": "public_chat",
"initial_state": []map[string]interface{}{
{
"type": "m.room.history_visibility",
"state_key": "",
"content": map[string]string{
"history_visibility": "world_readable",
},
},
},
}
// create the rooms
alice := deployment.Client(t, "hs1", "@alice:hs1")
root := alice.CreateRoom(t, worldReadable)
r1 := alice.CreateRoom(t, worldReadable)
ss1 := alice.CreateRoom(t, worldReadable)
r4 := alice.CreateRoom(t, worldReadable)
bob := deployment.Client(t, "hs2", "@bob:hs2")
r2 := bob.CreateRoom(t, worldReadable)
ss2 := bob.CreateRoom(t, worldReadable)
r3 := bob.CreateRoom(t, worldReadable)

// create the links
rootToR1 := eventKey(root, r1, spaceChildEventType)
alice.SendEventSynced(t, root, b.Event{
Type: spaceChildEventType,
StateKey: &r1,
Content: map[string]interface{}{
"via": []string{"hs1"},
},
})
rootToSS1 := eventKey(root, ss1, spaceChildEventType)
alice.SendEventSynced(t, root, b.Event{
Type: spaceChildEventType,
StateKey: &ss1,
Content: map[string]interface{}{
"via": []string{"hs1"},
},
})
rootToR2 := eventKey(root, r2, spaceChildEventType)
alice.SendEventSynced(t, root, b.Event{
Type: spaceChildEventType,
StateKey: &r2,
Content: map[string]interface{}{
"via": []string{"hs2"},
},
})
ss1ToSS2 := eventKey(ss1, ss2, spaceChildEventType)
alice.SendEventSynced(t, ss1, b.Event{
Type: spaceChildEventType,
StateKey: &ss2,
Content: map[string]interface{}{
"via": []string{"hs2"},
},
})
ss1ToR3 := eventKey(ss1, r3, spaceChildEventType)
alice.SendEventSynced(t, ss1, b.Event{
Type: spaceChildEventType,
StateKey: &r3,
Content: map[string]interface{}{
"via": []string{"hs2"},
},
})
ss2ToR4 := eventKey(ss2, r4, spaceChildEventType)
bob.SendEventSynced(t, ss2, b.Event{
Type: spaceChildEventType,
StateKey: &r4,
Content: map[string]interface{}{
"via": []string{"hs1"},
},
})
allEvents := []string{
rootToR1, rootToR2, rootToSS1,
ss1ToR3, ss1ToSS2,
ss2ToR4,
}
t.Logf("rooms: %v", allEvents)

res := alice.MustDo(t, "POST", []string{"_matrix", "client", "unstable", "rooms", root, "spaces"}, map[string]interface{}{})
must.MatchResponse(t, res, match.HTTPResponse{
JSON: []match.JSON{
match.JSONCheckOff("rooms", []interface{}{
root, r1, r2, r3, r4, ss1, ss2,
}, func(r gjson.Result) interface{} {
return r.Get("room_id").Str
}, nil),
},
})
}