-
Notifications
You must be signed in to change notification settings - Fork 69
Add tests for rich topic handling (previously MSC3765) #788
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
f767037
07cf34e
019f7d9
6595ebb
e61bcb7
4bde43c
5549e10
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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) { | ||
|
Comment on lines
+114
to
+115
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. For my own reference, this behavior is spec'ed in the
|
||
| // 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() | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.