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
84 changes: 84 additions & 0 deletions tests/csapi/apidoc_room_create_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"github.com/matrix-org/complement/helpers"
"github.com/matrix-org/complement/match"
"github.com/matrix-org/complement/must"
"github.com/matrix-org/complement/runtime"
)

func TestRoomCreate(t *testing.T) {
Expand Down Expand Up @@ -62,6 +63,89 @@ func TestRoomCreate(t *testing.T) {
content := alice.MustGetStateEventContent(t, roomID, "m.room.topic", "")
must.MatchGJSON(t, content, match.JSONKeyEqual("topic", "Test Room"))
})
// POST /createRoom makes a room with a topic and writes rich topic representation
t.Run("POST /createRoom makes a room with a topic and writes rich topic representation", func(t *testing.T) {
// Rich topics not implemented yet on Dendrite
runtime.SkipIf(t, runtime.Dendrite)

t.Parallel()

roomID := alice.MustCreateRoom(t, map[string]interface{}{
"topic": "Test Room",
"preset": "public_chat",
})
content := alice.MustGetStateEventContent(t, roomID, "m.room.topic", "")
must.MatchGJSON(t, content, match.JSONKeyEqual("topic", "Test Room"))

Comment thread
Johennes marked this conversation as resolved.
// The plain text topic is duplicated into m.topic
must.MatchGJSON(t, content,
match.JSONKeyArrayOfSize("m\\.topic.m\\.text", 1),
match.JSONKeyPresent("m\\.topic.m\\.text.0.body"),
match.JSONKeyEqual("m\\.topic.m\\.text.0.body", "Test Room"))

// The mime type must be unset or text/plain
mime := content.Get("m\\.topic.m\\.text.0.mimetype")
if mime.Exists() {
must.Equal(t, mime.String(), "text/plain", "expected rich topic mimetype to be unset (defaults to text/plain) or explicitly set as text/plain")
}
})
// POST /createRoom makes a room with a topic via initial_state
t.Run("POST /createRoom makes a room with a topic via initial_state", func(t *testing.T) {
t.Parallel()

roomID := alice.MustCreateRoom(t, map[string]interface{}{
"initial_state": []map[string]interface{}{
{
"content": map[string]interface{}{
"topic": "Test Room",
},
"type": "m.room.topic",
"state_key": "",
},
},
"preset": "public_chat",
})
content := alice.MustGetStateEventContent(t, roomID, "m.room.topic", "")
must.MatchGJSON(t, content, match.JSONKeyEqual("topic", "Test Room"))

// There is no m.topic property
must.MatchGJSON(t, content, match.JSONKeyMissing("m\\.topic"))
})
// POST /createRoom makes a room with a topic via initial_state overwritten by topic
t.Run("POST /createRoom makes a room with a topic via initial_state overwritten by topic", func(t *testing.T) {
Comment on lines +114 to +115
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For my own reference, this behavior is spec'ed in the /createRoom endpoint, https://spec.matrix.org/v1.14/client-server-api/#post_matrixclientv3createroom

The server MUST apply the normal state resolution rules when creating the new room, including checking power levels for each event. It MUST apply the events implied by the request in the following order:

[...]
6. Events listed in initial_state, in the order that they are listed.
7. Events implied by name and topic (m.room.name and m.room.topic state events).
[...]

// Rich topics not implemented yet on Dendrite
runtime.SkipIf(t, runtime.Dendrite)

t.Parallel()

roomID := alice.MustCreateRoom(t, map[string]interface{}{
"topic": "Test Room",
"initial_state": []map[string]interface{}{
{
"content": map[string]interface{}{
"topic": "Shenanigans",
},
"type": "m.room.topic",
"state_key": "",
},
},
"preset": "public_chat",
})
content := alice.MustGetStateEventContent(t, roomID, "m.room.topic", "")
must.MatchGJSON(t, content, match.JSONKeyEqual("topic", "Test Room"))

// The plain text topic is duplicated into m.topic
must.MatchGJSON(t, content,
match.JSONKeyArrayOfSize("m\\.topic.m\\.text", 1),
match.JSONKeyPresent("m\\.topic.m\\.text.0.body"),
match.JSONKeyEqual("m\\.topic.m\\.text.0.body", "Test Room"))

// The mime type must be unset or text/plain
mime := content.Get("m\\.topic.m\\.text.0.mimetype")
if mime.Exists() {
must.Equal(t, mime.String(), "text/plain", "expected rich topic mimetype to be unset (defaults to text/plain) or explicitly set as text/plain")
}
})
// sytest: POST /createRoom makes a room with a name
t.Run("POST /createRoom makes a room with a name", func(t *testing.T) {
t.Parallel()
Expand Down
Loading