Skip to content

Commit

Permalink
new test
Browse files Browse the repository at this point in the history
  • Loading branch information
David Robertson committed Jul 17, 2023
1 parent 9e99476 commit 432397a
Show file tree
Hide file tree
Showing 2 changed files with 71 additions and 2 deletions.
2 changes: 2 additions & 0 deletions tests-e2e/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,7 @@ type CSAPI struct {
Localpart string
AccessToken string
DeviceID string
AvatarURL string
BaseURL string
Client *http.Client
// how long are we willing to wait for MustSyncUntil.... calls
Expand Down Expand Up @@ -166,6 +167,7 @@ func (c *CSAPI) SetAvatar(t *testing.T, avatarURL string) {
"avatar_url": avatarURL,
}
c.MustDoFunc(t, "PUT", []string{"_matrix", "client", "v3", "profile", c.UserID, "avatar_url"}, WithJSONBody(t, reqBody))
c.AvatarURL = avatarURL
}

// DownloadContent downloads media from the server, returning the raw bytes and the Content-Type. Fails the test on error.
Expand Down
71 changes: 69 additions & 2 deletions tests-e2e/lists_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1600,7 +1600,74 @@ func TestAvatarFieldInRoomResponse(t *testing.T) {
res = alice.SlidingSyncUntil(t, res.Pos, sync3.Request{}, m.MatchRoomSubscription(dmChris, m.MatchRoomAvatar(chrisAvatar2)))
})

// TODO unset DM's avatar, then set a custom one in that room.
t.Run("Changing DM flag", func(t *testing.T) {
t.Log("Alice clears the DM flag on Bob's room.")
alice.SetGlobalAccountData(t, "m.direct", map[string]interface{}{
"content": map[string][]string{
bob.UserID: {}, // no dmBob here
chris.UserID: {dmChris, dmBobChris},
},
})

t.Log("Alice syncs until she sees a new set of account data.")
res = alice.SlidingSyncUntil(t, res.Pos, sync3.Request{
Extensions: extensions.Request{
AccountData: &extensions.AccountDataRequest{
extensions.Core{Enabled: &boolTrue},
},
},
}, func(response *sync3.Response) error {
if response.Extensions.AccountData == nil {
return fmt.Errorf("no account data yet")
}
if len(response.Extensions.AccountData.Global) == 0 {
return fmt.Errorf("no global account data yet")
}
return nil
})

t.Log("The DM with Bob should no longer be a DM and should no longer have an avatar.")
m.MatchResponse(t, res, m.MatchRoomSubscription(dmBob, func(r sync3.Room) error {
if r.IsDM {
return fmt.Errorf("dmBob is still a DM")
}
return m.MatchRoomUnsetAvatar()(r)
}))

t.Log("Alice sets the DM flag on Bob's room.")
alice.SetGlobalAccountData(t, "m.direct", map[string]interface{}{
"content": map[string][]string{
bob.UserID: {dmBob}, // dmBob reinstated
chris.UserID: {dmChris, dmBobChris},
},
})

t.Log("Alice syncs until she sees a new set of account data.")
res = alice.SlidingSyncUntil(t, res.Pos, sync3.Request{
Extensions: extensions.Request{
AccountData: &extensions.AccountDataRequest{
extensions.Core{Enabled: &boolTrue},
},
},
}, func(response *sync3.Response) error {
if response.Extensions.AccountData == nil {
return fmt.Errorf("no account data yet")
}
if len(response.Extensions.AccountData.Global) == 0 {
return fmt.Errorf("no global account data yet")
}
return nil
})

t.Log("The room should have Bob's avatar again.")
m.MatchResponse(t, res, m.MatchRoomSubscription(dmBob, func(r sync3.Room) error {
if !r.IsDM {
return fmt.Errorf("dmBob is still not a DM")
}
return m.MatchRoomAvatar(bob.AvatarURL)(r)
}))

})

// TODO when you're invited, you see the avatar
// TODO make a DM not a DM, loses its avatar; remake it a DM and it gains one.
}

0 comments on commit 432397a

Please sign in to comment.