Skip to content

Commit 7dc7d5f

Browse files
committed
Verify that we can resolve member avatar/displayname state for historical messages
Part of testing https://gitlab.com/gitterHQ/webapp/-/merge_requests/2229#note_654645018
1 parent 97183bf commit 7dc7d5f

File tree

1 file changed

+77
-0
lines changed

1 file changed

+77
-0
lines changed

tests/msc2716_test.go

+77
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import (
1515
"testing"
1616
"time"
1717

18+
"github.com/sirupsen/logrus"
1819
"github.com/tidwall/gjson"
1920

2021
"github.com/matrix-org/complement/internal/b"
@@ -457,6 +458,82 @@ func TestBackfillingHistory(t *testing.T) {
457458
// TODO: Try adding avatar and displayName and see if historical messages get this info
458459
})
459460

461+
t.Run("should resolve member state events for historical events", func(t *testing.T) {
462+
t.Parallel()
463+
464+
roomID := as.CreateRoom(t, createPublicRoomOpts)
465+
alice.JoinRoom(t, roomID, nil)
466+
467+
// Create the "live" event we are going to insert our backfilled events next to
468+
eventIDsBefore := createMessagesInRoom(t, alice, roomID, 1)
469+
eventIdBefore := eventIDsBefore[0]
470+
timeAfterEventBefore := time.Now()
471+
472+
// eventIDsAfter
473+
createMessagesInRoom(t, alice, roomID, 2)
474+
475+
// Insert a backfilled event
476+
batchSendRes := batchSendHistoricalMessages(
477+
t,
478+
as,
479+
roomID,
480+
eventIdBefore,
481+
"",
482+
createJoinStateEventsForBackfillRequest([]string{virtualUserID}, timeAfterEventBefore),
483+
createMessageEventsForBackfillRequest([]string{virtualUserID}, timeAfterEventBefore, 3),
484+
// Status
485+
200,
486+
)
487+
batchSendResBody0 := client.ParseJSON(t, batchSendRes)
488+
historicalEventIDs0 := client.GetJSONFieldStringArray(t, batchSendResBody0, "event_ids")
489+
nextBatchID0 := client.GetJSONFieldStr(t, batchSendResBody0, "next_batch_id")
490+
491+
contextRes0 := alice.MustDoFunc(t, "GET", []string{"_matrix", "client", "r0", "rooms", roomID, "context", historicalEventIDs0[1]}, client.WithContentType("application/json"))
492+
contextResBody0 := client.ParseJSON(t, contextRes0)
493+
stateJsonResult0 := gjson.GetBytes(contextResBody0, "state")
494+
stateFromContext0 := stateJsonResult0.Array()
495+
496+
logrus.WithFields(logrus.Fields{
497+
"stateFromContext": stateFromContext0,
498+
"len": len(stateFromContext0),
499+
}).Error("gaweegegegwegawagewg 0")
500+
501+
if len(stateFromContext0) == 0 {
502+
t.Fatalf("Expected some state events in the context response for historical event in first batch but saw %d: %s", len(stateFromContext0), stateFromContext0)
503+
}
504+
505+
// Insert another older batch of backfilled history from the same user.
506+
// Make sure the meta data and joins still work on the subsequent batch
507+
insertTime1 := timeAfterEventBefore
508+
batchSendRes1 := batchSendHistoricalMessages(
509+
t,
510+
as,
511+
roomID,
512+
eventIdBefore,
513+
nextBatchID0,
514+
createJoinStateEventsForBackfillRequest([]string{virtualUserID}, insertTime1),
515+
createMessageEventsForBackfillRequest([]string{virtualUserID}, insertTime1, 3),
516+
// Status
517+
200,
518+
)
519+
batchSendResBody1 := client.ParseJSON(t, batchSendRes1)
520+
historicalEventIDs1 := client.GetJSONFieldStringArray(t, batchSendResBody1, "event_ids")
521+
522+
contextRes1 := alice.MustDoFunc(t, "GET", []string{"_matrix", "client", "r0", "rooms", roomID, "context", historicalEventIDs1[1]}, client.WithContentType("application/json"))
523+
contextResBody1 := client.ParseJSON(t, contextRes1)
524+
stateJsonResult1 := gjson.GetBytes(contextResBody1, "state")
525+
stateFromContext1 := stateJsonResult1.Array()
526+
527+
logrus.WithFields(logrus.Fields{
528+
"stateFromContext": stateFromContext1,
529+
"len": len(stateFromContext1),
530+
}).Error("gaweegegegwegawagewg 1")
531+
532+
if len(stateFromContext1) == 0 {
533+
t.Fatalf("Expected some state events in the context response for historical event in second batch but saw %d: %s", len(stateFromContext1), stateFromContext1)
534+
}
535+
})
536+
460537
t.Run("TODO: What happens when you point multiple batches at the same insertion event?", func(t *testing.T) {
461538
t.Skip("Skipping until implemented")
462539
})

0 commit comments

Comments
 (0)