1
0
mirror of https://github.com/matrix-org/matrix-js-sdk.git synced 2026-01-03 23:22:30 +03:00

Add integration tests for read receipts

This commit is contained in:
Kegan Dougal
2015-10-16 13:51:44 +01:00
parent a52f92830a
commit a101857cb6
2 changed files with 117 additions and 1 deletions

View File

@@ -2,6 +2,7 @@
var sdk = require("../..");
var HttpBackend = require("../mock-request");
var utils = require("../test-utils");
var MatrixEvent = sdk.MatrixEvent;
describe("MatrixClient syncing", function() {
var baseUrl = "http://localhost.or.something";
@@ -270,6 +271,122 @@ describe("MatrixClient syncing", function() {
});
});
describe("receipts", function() {
var roomOne = "!foo:localhost";
var initialSync = {
end: "s_5_3",
presence: [],
receipts: [],
rooms: [{
membership: "join",
room_id: roomOne,
messages: {
start: "f_1_1",
end: "f_2_2",
chunk: [
utils.mkMessage({
room: roomOne, user: otherUserId, msg: "hello"
})
]
},
state: [
utils.mkEvent({
type: "m.room.name", room: roomOne, user: otherUserId,
content: {
name: "Old room name"
}
}),
utils.mkMembership({
room: roomOne, mship: "join", user: otherUserId
}),
utils.mkMembership({
room: roomOne, mship: "join", user: selfUserId
}),
utils.mkEvent({
type: "m.room.create", room: roomOne, user: selfUserId,
content: {
creator: selfUserId
}
})
]
}]
};
var eventData = {
start: "s_5_3",
end: "e_6_7",
chunk: []
};
beforeEach(function() {
eventData.chunk = [];
initialSync.receipts = [];
});
it("should sync receipts from /initialSync.", function(done) {
var ackEvent = initialSync.rooms[0].messages.chunk[0];
var receipt = {};
receipt[ackEvent.event_id] = {
"m.read": {}
};
receipt[ackEvent.event_id]["m.read"][otherUserId] = {
ts: 176592842636
};
initialSync.receipts = [{
content: receipt,
room_id: roomOne,
type: "m.receipt"
}];
httpBackend.when("GET", "/initialSync").respond(200, initialSync);
httpBackend.when("GET", "/events").respond(200, eventData);
client.startClient();
httpBackend.flush().done(function() {
var room = client.getRoom(roomOne);
expect(room.getReceiptsForEvent(new MatrixEvent(ackEvent))).toEqual([{
type: "m.read",
userId: otherUserId,
data: {
ts: 176592842636
}
}]);
done();
});
});
it("should sync receipts from /events.", function(done) {
var ackEvent = initialSync.rooms[0].messages.chunk[0];
var receipt = {};
receipt[ackEvent.event_id] = {
"m.read": {}
};
receipt[ackEvent.event_id]["m.read"][otherUserId] = {
ts: 176592842636
};
eventData.chunk = [{
content: receipt,
room_id: roomOne,
type: "m.receipt"
}];
httpBackend.when("GET", "/initialSync").respond(200, initialSync);
httpBackend.when("GET", "/events").respond(200, eventData);
client.startClient();
httpBackend.flush().done(function() {
var room = client.getRoom(roomOne);
expect(room.getReceiptsForEvent(new MatrixEvent(ackEvent))).toEqual([{
type: "m.read",
userId: otherUserId,
data: {
ts: 176592842636
}
}]);
done();
});
});
});
describe("of a room", function() {
xit("should sync when a join event (which changes state) for the user" +
" arrives down the event stream (e.g. join from another device)", function() {