Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 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
78 changes: 78 additions & 0 deletions tests/csapi/apidoc_room_create_rich_topic_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
//go:build !dendrite_blacklist
// +build !dendrite_blacklist
Comment thread
Johennes marked this conversation as resolved.
Outdated

package csapi_tests

import (
"testing"

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

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

alice := deployment.Register(t, "hs1", helpers.RegistrationOpts{})

t.Run("Parallel", func(t *testing.T) {
// POST /createRoom sets m.topic when the topic parameter is supplied
t.Run("POST /createRoom sets m.topic when the topic parameter is supplied", func(t *testing.T) {
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"))

// 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", "no m.topic content block")
}
})
// POST /createRoom makes sets m.topic when the topic parameter is supplied in addition to initial_state
t.Run("POST /createRoom makes sets m.topic when the topic parameter is supplied in addition to initial_state", func(t *testing.T) {
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", "no m.topic content block")
}
})
})
}
42 changes: 42 additions & 0 deletions tests/csapi/apidoc_room_create_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,48 @@ func TestRoomCreate(t *testing.T) {
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.
// 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
Contributor

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).
[...]

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"))
})
// 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