diff --git a/tests/csapi/apidoc_room_create_test.go b/tests/csapi/apidoc_room_create_test.go index 7abc9b51..1b5e63bb 100644 --- a/tests/csapi/apidoc_room_create_test.go +++ b/tests/csapi/apidoc_room_create_test.go @@ -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) { @@ -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")) + + // 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) { + // 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()