-
Notifications
You must be signed in to change notification settings - Fork 52
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add tests for setting and getting account data (#575)
Signed-off-by: Sumner Evans <sumner@beeper.com>
- Loading branch information
1 parent
95c3ba6
commit f4a938e
Showing
1 changed file
with
67 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
package csapi_tests | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/matrix-org/complement/internal/b" | ||
"github.com/matrix-org/complement/internal/match" | ||
"github.com/matrix-org/complement/internal/must" | ||
) | ||
|
||
func TestAddAccountData(t *testing.T) { | ||
deployment := Deploy(t, b.BlueprintOneToOneRoom) | ||
defer deployment.Destroy(t) | ||
|
||
alice := deployment.Client(t, "hs1", "@alice:hs1") | ||
|
||
// 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.SetGlobalAccountData(t, "test.key", map[string]interface{}{"value": "first"}) | ||
|
||
// check that getting the account data returns the correct value | ||
must.MatchResponse(t, alice.GetGlobalAccountData(t, "test.key"), match.HTTPResponse{ | ||
JSON: []match.JSON{ | ||
match.JSONKeyEqual("value", "first"), | ||
}, | ||
}) | ||
|
||
// Set it to something else | ||
alice.SetGlobalAccountData(t, "test.key", map[string]interface{}{"value": "second"}) | ||
|
||
// check that getting the account data returns the updated value | ||
must.MatchResponse(t, alice.GetGlobalAccountData(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.CreateRoom(t, map[string]interface{}{}) | ||
|
||
// Set the room account data entry | ||
alice.SetRoomAccountData(t, roomID, "test.key", map[string]interface{}{"value": "room first"}) | ||
|
||
// check that getting the account data returns the correct value | ||
must.MatchResponse(t, alice.GetRoomAccountData(t, roomID, "test.key"), match.HTTPResponse{ | ||
JSON: []match.JSON{ | ||
match.JSONKeyEqual("value", "room first"), | ||
}, | ||
}) | ||
|
||
// Set it to something else | ||
alice.SetRoomAccountData(t, roomID, "test.key", map[string]interface{}{"value": "room second"}) | ||
|
||
// check that getting the account data returns the updated value | ||
must.MatchResponse(t, alice.GetRoomAccountData(t, roomID, "test.key"), match.HTTPResponse{ | ||
JSON: []match.JSON{ | ||
match.JSONKeyEqual("value", "room second"), | ||
}, | ||
}) | ||
}) | ||
} |