Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

account data: add test for setting and getting #575

Merged
merged 1 commit into from
Feb 7, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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"),
},
})
})
}