-
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.
account data: add test for setting and getting
Signed-off-by: Sumner Evans <sumner@beeper.com>
- Loading branch information
1 parent
46f8e84
commit c6337a0
Showing
2 changed files
with
91 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
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,83 @@ | ||
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 | ||
resp := alice.SetGlobalAccountData(t, "com.beeper.test", map[string]interface{}{"value": "first"}) | ||
must.MatchResponse(t, resp, match.HTTPResponse{ | ||
StatusCode: 200, | ||
}) | ||
|
||
// check that getting the account data returns the correct value | ||
must.MatchResponse(t, alice.GetGlobalAccountData(t, "com.beeper.test"), match.HTTPResponse{ | ||
StatusCode: 200, | ||
JSON: []match.JSON{ | ||
match.JSONKeyEqual("value", "first"), | ||
}, | ||
}) | ||
|
||
// Set it to something else | ||
resp = alice.SetGlobalAccountData(t, "com.beeper.test", map[string]interface{}{"value": "second"}) | ||
must.MatchResponse(t, resp, match.HTTPResponse{ | ||
StatusCode: 200, | ||
}) | ||
|
||
// check that getting the account data returns the updated value | ||
must.MatchResponse(t, alice.GetGlobalAccountData(t, "com.beeper.test"), match.HTTPResponse{ | ||
StatusCode: 200, | ||
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 | ||
resp := alice.SetRoomAccountData(t, roomID, "com.beeper.test", map[string]interface{}{"value": "room first"}) | ||
must.MatchResponse(t, resp, match.HTTPResponse{ | ||
StatusCode: 200, | ||
}) | ||
|
||
// check that getting the account data returns the correct value | ||
must.MatchResponse(t, alice.GetRoomAccountData(t, roomID, "com.beeper.test"), match.HTTPResponse{ | ||
StatusCode: 200, | ||
JSON: []match.JSON{ | ||
match.JSONKeyEqual("value", "room first"), | ||
}, | ||
}) | ||
|
||
// Set it to something else | ||
resp = alice.SetRoomAccountData(t, roomID, "com.beeper.test", map[string]interface{}{"value": "room second"}) | ||
must.MatchResponse(t, resp, match.HTTPResponse{ | ||
StatusCode: 200, | ||
}) | ||
|
||
// check that getting the account data returns the updated value | ||
must.MatchResponse(t, alice.GetRoomAccountData(t, roomID, "com.beeper.test"), match.HTTPResponse{ | ||
StatusCode: 200, | ||
JSON: []match.JSON{ | ||
match.JSONKeyEqual("value", "room second"), | ||
}, | ||
}) | ||
}) | ||
} |