Skip to content

Commit f767037

Browse files
committed
Add tests for rich topic handling (previously MSC3765)
Signed-off-by: Johannes Marbach <n0-0ne+github@mailbox.org>
1 parent 5da410e commit f767037

1 file changed

Lines changed: 66 additions & 0 deletions

File tree

tests/csapi/apidoc_room_create_test.go

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,72 @@ func TestRoomCreate(t *testing.T) {
6161
})
6262
content := alice.MustGetStateEventContent(t, roomID, "m.room.topic", "")
6363
must.MatchGJSON(t, content, match.JSONKeyEqual("topic", "Test Room"))
64+
65+
// The plain text topic is duplicated into m.topic
66+
must.MatchGJSON(t, content,
67+
match.JSONKeyArrayOfSize("m\\.topic.m\\.text", 1),
68+
match.JSONKeyPresent("m\\.topic.m\\.text.0.body"),
69+
match.JSONKeyEqual("m\\.topic.m\\.text.0.body", "Test Room"))
70+
71+
// The mime type must be unset or text/plain
72+
mime := content.Get("m\\.topic.m\\.text.0.mimetype")
73+
if mime.Exists() {
74+
must.Equal(t, mime.String(), "text/plain", "no m.topic content block")
75+
}
76+
})
77+
// POST /createRoom makes a room with a topic via initial_state
78+
t.Run("POST /createRoom makes a room with a topic via initial_state", func(t *testing.T) {
79+
t.Parallel()
80+
81+
roomID := alice.MustCreateRoom(t, map[string]interface{}{
82+
"initial_state": []map[string]interface{}{
83+
{
84+
"content": map[string]interface{}{
85+
"topic": "Test Room",
86+
},
87+
"type": "m.room.topic",
88+
"state_key": "",
89+
},
90+
},
91+
"preset": "public_chat",
92+
})
93+
content := alice.MustGetStateEventContent(t, roomID, "m.room.topic", "")
94+
must.MatchGJSON(t, content, match.JSONKeyEqual("topic", "Test Room"))
95+
96+
// There is no m.topic property
97+
must.MatchGJSON(t, content, match.JSONKeyMissing("m\\.topic"))
98+
})
99+
// POST /createRoom makes a room with a topic via initial_state overwritten by topic
100+
t.Run("POST /createRoom makes a room with a topic via initial_state overwritten by topic", func(t *testing.T) {
101+
t.Parallel()
102+
103+
roomID := alice.MustCreateRoom(t, map[string]interface{}{
104+
"topic": "Test Room",
105+
"initial_state": []map[string]interface{}{
106+
{
107+
"content": map[string]interface{}{
108+
"topic": "Shenanigans",
109+
},
110+
"type": "m.room.topic",
111+
"state_key": "",
112+
},
113+
},
114+
"preset": "public_chat",
115+
})
116+
content := alice.MustGetStateEventContent(t, roomID, "m.room.topic", "")
117+
must.MatchGJSON(t, content, match.JSONKeyEqual("topic", "Test Room"))
118+
119+
// The plain text topic is duplicated into m.topic
120+
must.MatchGJSON(t, content,
121+
match.JSONKeyArrayOfSize("m\\.topic.m\\.text", 1),
122+
match.JSONKeyPresent("m\\.topic.m\\.text.0.body"),
123+
match.JSONKeyEqual("m\\.topic.m\\.text.0.body", "Test Room"))
124+
125+
// The mime type must be unset or text/plain
126+
mime := content.Get("m\\.topic.m\\.text.0.mimetype")
127+
if mime.Exists() {
128+
must.Equal(t, mime.String(), "text/plain", "no m.topic content block")
129+
}
64130
})
65131
// sytest: POST /createRoom makes a room with a name
66132
t.Run("POST /createRoom makes a room with a name", func(t *testing.T) {

0 commit comments

Comments
 (0)