|  | 
|  | 1 | +// +build msc2716 | 
|  | 2 | + | 
|  | 3 | +// This file contains tests for incrementally importing history to an existing room, | 
|  | 4 | +// a currently experimental feature defined by MSC2716, which you can read here: | 
|  | 5 | +// https://github.com/matrix-org/matrix-doc/pull/2716 | 
|  | 6 | + | 
|  | 7 | +package tests | 
|  | 8 | + | 
|  | 9 | +import ( | 
|  | 10 | +	"testing" | 
|  | 11 | + | 
|  | 12 | +	"github.com/matrix-org/complement/internal/b" | 
|  | 13 | +	"github.com/matrix-org/complement/internal/must" | 
|  | 14 | +	"github.com/tidwall/gjson" | 
|  | 15 | +) | 
|  | 16 | + | 
|  | 17 | +// Test that the m.room.create and m.room.member events for a room we created comes down /sync | 
|  | 18 | +func TestBackfillingHistory(t *testing.T) { | 
|  | 19 | +	deployment := Deploy(t, "rooms_state", b.BlueprintAlice) | 
|  | 20 | +	defer deployment.Destroy(t) | 
|  | 21 | + | 
|  | 22 | +	userID := "@alice:hs1" | 
|  | 23 | +	alice := deployment.Client(t, "hs1", userID) | 
|  | 24 | +	roomID := alice.CreateRoom(t, struct{}{}) | 
|  | 25 | + | 
|  | 26 | +	// eventA | 
|  | 27 | +	eventA := alice.SendEventSynced(t, roomID, b.Event{ | 
|  | 28 | +		Type: "m.room.message", | 
|  | 29 | +		Content: map[string]interface{}{ | 
|  | 30 | +			"msgtype": "m.text", | 
|  | 31 | +			"body":    "Message A", | 
|  | 32 | +		}, | 
|  | 33 | +	}) | 
|  | 34 | +	// eventB | 
|  | 35 | +	alice.SendEventSynced(t, roomID, b.Event{ | 
|  | 36 | +		Type: "m.room.message", | 
|  | 37 | +		Content: map[string]interface{}{ | 
|  | 38 | +			"msgtype": "m.text", | 
|  | 39 | +			"body":    "Message B", | 
|  | 40 | +		}, | 
|  | 41 | +	}) | 
|  | 42 | +	// eventC | 
|  | 43 | +	alice.SendEventSynced(t, roomID, b.Event{ | 
|  | 44 | +		Type: "m.room.message", | 
|  | 45 | +		Content: map[string]interface{}{ | 
|  | 46 | +			"msgtype": "m.text", | 
|  | 47 | +			"body":    "Message C", | 
|  | 48 | +		}, | 
|  | 49 | +	}) | 
|  | 50 | + | 
|  | 51 | +	// event1 | 
|  | 52 | +	alice.SendEventSynced(t, roomID, b.Event{ | 
|  | 53 | +		Type: "m.room.message", | 
|  | 54 | +		PrevEvents: []string{ | 
|  | 55 | +			eventA, | 
|  | 56 | +		}, | 
|  | 57 | +		Content: map[string]interface{}{ | 
|  | 58 | +			"msgtype": "m.text", | 
|  | 59 | +			"body":    "Message 1", | 
|  | 60 | +		}, | 
|  | 61 | +	}) | 
|  | 62 | + | 
|  | 63 | +	t.Run("parallel", func(t *testing.T) { | 
|  | 64 | +		// sytest: Room creation reports m.room.create to myself | 
|  | 65 | +		t.Run("Room creation reports m.room.create to myself", func(t *testing.T) { | 
|  | 66 | +			t.Parallel() | 
|  | 67 | +			alice := deployment.Client(t, "hs1", userID) | 
|  | 68 | +			alice.SyncUntilTimelineHas(t, roomID, func(ev gjson.Result) bool { | 
|  | 69 | +				if ev.Get("type").Str != "m.room.create" { | 
|  | 70 | +					return false | 
|  | 71 | +				} | 
|  | 72 | +				must.EqualStr(t, ev.Get("sender").Str, userID, "wrong sender") | 
|  | 73 | +				must.EqualStr(t, ev.Get("content").Get("creator").Str, userID, "wrong content.creator") | 
|  | 74 | +				return true | 
|  | 75 | +			}) | 
|  | 76 | +		}) | 
|  | 77 | +	}) | 
|  | 78 | +} | 
0 commit comments