Skip to content

Commit

Permalink
Encapsulate test code in actual tests
Browse files Browse the repository at this point in the history
  • Loading branch information
anoadragon453 committed Feb 10, 2021
1 parent 50ee113 commit c35a2c7
Showing 1 changed file with 31 additions and 27 deletions.
58 changes: 31 additions & 27 deletions tests/msc2403_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -357,38 +357,42 @@ func knockRoomsInPublicRoomsDirectoryTest(t *testing.T) {
aliceUserID := "@alice:hs1"
alice := deployment.Client(t, "hs1", aliceUserID)

// Create an invite-only room with the knock room version
roomID := alice.CreateRoom(t, struct {
Preset string `json:"preset"`
RoomVersion string `json:"room_version"`
}{
"private_chat", // Set to private in order to get an invite-only room
knockUnstableIdentifier, // Room version required for knocking. TODO: Remove when knocking is in a stable room version
})
t.Run("Knock rooms can be added to and retrieved from the public room directory with a join_rule entry of '"+knockUnstableIdentifier+"'", func(t *testing.T) {
// Create an invite-only room with the knock room version
roomID := alice.CreateRoom(t, struct {
Preset string `json:"preset"`
RoomVersion string `json:"room_version"`
}{
"private_chat", // Set to private in order to get an invite-only room
knockUnstableIdentifier, // Room version required for knocking. TODO: Remove when knocking is in a stable room version
})

// Change the join_rule to allow knocking
emptyStateKey := ""
alice.SendEventSynced(t, roomID, b.Event{
Type: "m.room.join_rules",
Sender: alice.UserID,
StateKey: &emptyStateKey,
Content: map[string]interface{}{
"join_rule": knockUnstableIdentifier,
},
// Change the join_rule to allow knocking
emptyStateKey := ""
alice.SendEventSynced(t, roomID, b.Event{
Type: "m.room.join_rules",
Sender: alice.UserID,
StateKey: &emptyStateKey,
Content: map[string]interface{}{
"join_rule": knockUnstableIdentifier,
},
})

// Publish the room to the public room directory and check that the 'join_rule' key is knock
publishAndCheckRoomJoinRule(t, alice, roomID, knockUnstableIdentifier)
})

// Publish the room to the public room directory and check that the 'join_rule' key is knock
publishAndCheckRoomJoinRule(t, alice, roomID, knockUnstableIdentifier)
t.Run("Public rooms added to the public room directory have a join_rule entry of 'public'", func(t *testing.T) {
// Create a public room
roomID = alice.CreateRoom(t, struct {
Preset string `json:"preset"`
}{
"public_chat", // Set to public in order to get a public room
})

// Create a public room
roomID = alice.CreateRoom(t, struct {
Preset string `json:"preset"`
}{
"public_chat", // Set to public in order to get a public room
// Publish the room, and check that the public room directory presents a 'join_rule' key of public
publishAndCheckRoomJoinRule(t, alice, roomID, "public")
})

// Publish the room, and check that the public room directory presents a 'join_rule' key of public
publishAndCheckRoomJoinRule(t, alice, roomID, "public")
}

// publishAndCheckRoomJoinRule will publish a given room ID to the given user's public room directory.
Expand Down

0 comments on commit c35a2c7

Please sign in to comment.