Skip to content

Commit bdeba28

Browse files
authored
Add tests for rich topic handling (previously MSC3765) (#788)
Rich topics landed with Matrix 1.15. These tests were broken out from https://github.com/element-hq/synapse/pull/18195/files#r2170245892. Signed-off-by: Johannes Marbach <n0-0ne+github@mailbox.org>
1 parent 5da410e commit bdeba28

File tree

1 file changed

+84
-0
lines changed

1 file changed

+84
-0
lines changed

tests/csapi/apidoc_room_create_test.go

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import (
1111
"github.com/matrix-org/complement/helpers"
1212
"github.com/matrix-org/complement/match"
1313
"github.com/matrix-org/complement/must"
14+
"github.com/matrix-org/complement/runtime"
1415
)
1516

1617
func TestRoomCreate(t *testing.T) {
@@ -62,6 +63,89 @@ func TestRoomCreate(t *testing.T) {
6263
content := alice.MustGetStateEventContent(t, roomID, "m.room.topic", "")
6364
must.MatchGJSON(t, content, match.JSONKeyEqual("topic", "Test Room"))
6465
})
66+
// POST /createRoom makes a room with a topic and writes rich topic representation
67+
t.Run("POST /createRoom makes a room with a topic and writes rich topic representation", func(t *testing.T) {
68+
// Rich topics not implemented yet on Dendrite
69+
runtime.SkipIf(t, runtime.Dendrite)
70+
71+
t.Parallel()
72+
73+
roomID := alice.MustCreateRoom(t, map[string]interface{}{
74+
"topic": "Test Room",
75+
"preset": "public_chat",
76+
})
77+
content := alice.MustGetStateEventContent(t, roomID, "m.room.topic", "")
78+
must.MatchGJSON(t, content, match.JSONKeyEqual("topic", "Test Room"))
79+
80+
// The plain text topic is duplicated into m.topic
81+
must.MatchGJSON(t, content,
82+
match.JSONKeyArrayOfSize("m\\.topic.m\\.text", 1),
83+
match.JSONKeyPresent("m\\.topic.m\\.text.0.body"),
84+
match.JSONKeyEqual("m\\.topic.m\\.text.0.body", "Test Room"))
85+
86+
// The mime type must be unset or text/plain
87+
mime := content.Get("m\\.topic.m\\.text.0.mimetype")
88+
if mime.Exists() {
89+
must.Equal(t, mime.String(), "text/plain", "expected rich topic mimetype to be unset (defaults to text/plain) or explicitly set as text/plain")
90+
}
91+
})
92+
// POST /createRoom makes a room with a topic via initial_state
93+
t.Run("POST /createRoom makes a room with a topic via initial_state", func(t *testing.T) {
94+
t.Parallel()
95+
96+
roomID := alice.MustCreateRoom(t, map[string]interface{}{
97+
"initial_state": []map[string]interface{}{
98+
{
99+
"content": map[string]interface{}{
100+
"topic": "Test Room",
101+
},
102+
"type": "m.room.topic",
103+
"state_key": "",
104+
},
105+
},
106+
"preset": "public_chat",
107+
})
108+
content := alice.MustGetStateEventContent(t, roomID, "m.room.topic", "")
109+
must.MatchGJSON(t, content, match.JSONKeyEqual("topic", "Test Room"))
110+
111+
// There is no m.topic property
112+
must.MatchGJSON(t, content, match.JSONKeyMissing("m\\.topic"))
113+
})
114+
// POST /createRoom makes a room with a topic via initial_state overwritten by topic
115+
t.Run("POST /createRoom makes a room with a topic via initial_state overwritten by topic", func(t *testing.T) {
116+
// Rich topics not implemented yet on Dendrite
117+
runtime.SkipIf(t, runtime.Dendrite)
118+
119+
t.Parallel()
120+
121+
roomID := alice.MustCreateRoom(t, map[string]interface{}{
122+
"topic": "Test Room",
123+
"initial_state": []map[string]interface{}{
124+
{
125+
"content": map[string]interface{}{
126+
"topic": "Shenanigans",
127+
},
128+
"type": "m.room.topic",
129+
"state_key": "",
130+
},
131+
},
132+
"preset": "public_chat",
133+
})
134+
content := alice.MustGetStateEventContent(t, roomID, "m.room.topic", "")
135+
must.MatchGJSON(t, content, match.JSONKeyEqual("topic", "Test Room"))
136+
137+
// The plain text topic is duplicated into m.topic
138+
must.MatchGJSON(t, content,
139+
match.JSONKeyArrayOfSize("m\\.topic.m\\.text", 1),
140+
match.JSONKeyPresent("m\\.topic.m\\.text.0.body"),
141+
match.JSONKeyEqual("m\\.topic.m\\.text.0.body", "Test Room"))
142+
143+
// The mime type must be unset or text/plain
144+
mime := content.Get("m\\.topic.m\\.text.0.mimetype")
145+
if mime.Exists() {
146+
must.Equal(t, mime.String(), "text/plain", "expected rich topic mimetype to be unset (defaults to text/plain) or explicitly set as text/plain")
147+
}
148+
})
65149
// sytest: POST /createRoom makes a room with a name
66150
t.Run("POST /createRoom makes a room with a name", func(t *testing.T) {
67151
t.Parallel()

0 commit comments

Comments
 (0)