Skip to content

Commit

Permalink
Add tests for setting and getting account data (#575)
Browse files Browse the repository at this point in the history
Signed-off-by: Sumner Evans <sumner@beeper.com>
  • Loading branch information
sumnerevans authored Feb 7, 2023
1 parent 95c3ba6 commit f4a938e
Showing 1 changed file with 67 additions and 0 deletions.
67 changes: 67 additions & 0 deletions tests/csapi/account_data_test.go
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"),
},
})
})
}

0 comments on commit f4a938e

Please sign in to comment.