@@ -396,12 +396,18 @@ func (c *CSAPI) GetDefaultRoomVersion(t ct.TestLike) gomatrixserverlib.RoomVersi
396396 return gomatrixserverlib .RoomVersion (defaultVersion .Str )
397397}
398398
399+ // MustUploadKeys uploads device and/or one time keys to the server, returning the current OTK counts.
400+ // Both device keys and one time keys are optional. Fails the test if the upload fails.
399401func (c * CSAPI ) MustUploadKeys (t ct.TestLike , deviceKeys map [string ]interface {}, oneTimeKeys map [string ]interface {}) (otkCounts map [string ]int ) {
400402 t .Helper ()
401- res := c .MustDo (t , "POST" , []string {"_matrix" , "client" , "v3" , "keys" , "upload" }, WithJSONBody (t , map [string ]interface {}{
402- "device_keys" : deviceKeys ,
403- "one_time_keys" : oneTimeKeys ,
404- }))
403+ reqBody := make (map [string ]interface {})
404+ if deviceKeys != nil {
405+ reqBody ["device_keys" ] = deviceKeys
406+ }
407+ if oneTimeKeys != nil {
408+ reqBody ["one_time_keys" ] = oneTimeKeys
409+ }
410+ res := c .MustDo (t , "POST" , []string {"_matrix" , "client" , "v3" , "keys" , "upload" }, WithJSONBody (t , reqBody ))
405411 bodyBytes := ParseJSON (t , res )
406412 s := struct {
407413 OTKCounts map [string ]int `json:"one_time_key_counts"`
@@ -492,6 +498,20 @@ func (c *CSAPI) MustGenerateOneTimeKeys(t ct.TestLike, otkCount uint) (deviceKey
492498 return deviceKeys , oneTimeKeys
493499}
494500
501+ // MustSetDisplayName sets the global display name for this account or fails the test.
502+ func (c * CSAPI ) MustSetDisplayName (t ct.TestLike , displayname string ) {
503+ c .MustDo (t , "PUT" , []string {"_matrix" , "client" , "v3" , "profile" , c .UserID , "displayname" }, WithJSONBody (t , map [string ]any {
504+ "displayname" : displayname ,
505+ }))
506+ }
507+
508+ // MustGetDisplayName returns the global display name for this user or fails the test.
509+ func (c * CSAPI ) MustGetDisplayName (t ct.TestLike , userID string ) string {
510+ res := c .MustDo (t , "GET" , []string {"_matrix" , "client" , "v3" , "profile" , userID , "displayname" })
511+ body := ParseJSON (t , res )
512+ return GetJSONFieldStr (t , body , "displayname" )
513+ }
514+
495515// WithRawBody sets the HTTP request body to `body`
496516func WithRawBody (body []byte ) RequestOpt {
497517 return func (req * http.Request ) {
0 commit comments