complement/tests/csapi/account_data_test.go
kegsay a669c750c8
Remove Deployment.Client and change Deploy (#676)
* Remove Deployment.Client and change Deploy

- `Deployment.Client` was used to get pre-registered clients. Now we want tests to register new users for each test, for dirty runs. So swap for `Deployment.Register` everywhere.
- `Deploy` was used to deploy a blueprint. We don't want this to enable dirty runs. So replace it with the number of servers you need e.g `Deploy(t, 2)`.

* Fix up more broken refactoring

* unbreak tests; make user localpart look nicer

* Alice and bob must share a room for presence

* Fix user directory test

* Fix race condition caused by making the room later than before
2023-10-17 18:07:43 +01:00

68 lines
2.2 KiB
Go

package csapi_tests
import (
"testing"
"github.com/matrix-org/complement"
"github.com/matrix-org/complement/helpers"
"github.com/matrix-org/complement/match"
"github.com/matrix-org/complement/must"
)
func TestAddAccountData(t *testing.T) {
deployment := complement.Deploy(t, 1)
defer deployment.Destroy(t)
alice := deployment.Register(t, "hs1", helpers.RegistrationOpts{})
// sytest: Can add account data
// sytest: Can get account data without syncing
t.Run("Can add global account data", func(t *testing.T) {
// Set the account data entry
alice.MustSetGlobalAccountData(t, "test.key", map[string]interface{}{"value": "first"})
// check that getting the account data returns the correct value
must.MatchResponse(t, alice.MustGetGlobalAccountData(t, "test.key"), match.HTTPResponse{
JSON: []match.JSON{
match.JSONKeyEqual("value", "first"),
},
})
// Set it to something else
alice.MustSetGlobalAccountData(t, "test.key", map[string]interface{}{"value": "second"})
// check that getting the account data returns the updated value
must.MatchResponse(t, alice.MustGetGlobalAccountData(t, "test.key"), match.HTTPResponse{
JSON: []match.JSON{
match.JSONKeyEqual("value", "second"),
},
})
})
// sytest: Can add account data to room
// sytest: Can get room account data without syncing
t.Run("Can add room account data", func(t *testing.T) {
// Create a room
roomID := alice.MustCreateRoom(t, map[string]interface{}{})
// Set the room account data entry
alice.MustSetRoomAccountData(t, roomID, "test.key", map[string]interface{}{"value": "room first"})
// check that getting the account data returns the correct value
must.MatchResponse(t, alice.MustGetRoomAccountData(t, roomID, "test.key"), match.HTTPResponse{
JSON: []match.JSON{
match.JSONKeyEqual("value", "room first"),
},
})
// Set it to something else
alice.MustSetRoomAccountData(t, roomID, "test.key", map[string]interface{}{"value": "room second"})
// check that getting the account data returns the updated value
must.MatchResponse(t, alice.MustGetRoomAccountData(t, roomID, "test.key"), match.HTTPResponse{
JSON: []match.JSON{
match.JSONKeyEqual("value", "room second"),
},
})
})
}