matrix-public-archive/test/e2e-tests.js

98 lines
2.8 KiB
JavaScript
Raw Normal View History

2022-02-22 15:06:29 -07:00
'use strict';
const assert = require('assert');
const urlJoin = require('url-join');
const { MatrixAuth } = require('matrix-bot-sdk');
const fetchEndpoint = require('../server/lib/fetch-endpoint');
2022-02-22 15:06:29 -07:00
const config = require('../config');
assert(config.testMatrixServerUrl1);
assert(config.testMatrixServerUrl2);
async function getTestClientForHs(testMatrixServerUrl) {
const auth = new MatrixAuth(testMatrixServerUrl);
const client = await auth.passwordRegister(
`user-${Math.floor(Math.random() * 1000000000)}`,
'password'
);
return client;
}
2022-02-22 19:55:42 -07:00
async function createMessagesInRoom(client, roomId, numMessages, prefix) {
let eventIds = [];
2022-02-22 19:55:42 -07:00
for (let i = 0; i < numMessages; i++) {
const eventId = await client.sendMessage(roomId, {
msgtype: 'm.text',
2022-02-22 19:55:42 -07:00
body: `${prefix} - message${i}`,
});
eventIds.push(eventId);
}
2022-02-22 19:55:42 -07:00
return eventIds;
}
async function createTestRoom(client) {
const roomId = await client.createRoom({
preset: 'public_chat',
name: 'the hangout spot',
});
return roomId;
}
2022-02-22 15:06:29 -07:00
describe('matrix-public-archive', () => {
2022-02-22 19:55:42 -07:00
it('Test federation between fixture homeservers', async () => {
const hs1Client = await getTestClientForHs(config.testMatrixServerUrl1);
const hs2Client = await getTestClientForHs(config.testMatrixServerUrl2);
2022-02-22 19:55:42 -07:00
// Create a room on hs2
const hs2RoomId = await createTestRoom(hs2Client);
const room2EventIds = await createMessagesInRoom(
hs2Client,
hs2RoomId,
10,
hs2Client.homeserverUrl
);
2022-02-22 19:55:42 -07:00
// Join hs1 to a room on hs2 (federation)
await hs1Client.joinRoom(hs2RoomId, 'hs2');
2022-02-22 19:55:42 -07:00
// From, hs1, make sure we can fetch messages from hs2
const messagesEndpoint = urlJoin(
hs1Client.homeserverUrl,
2022-02-22 19:55:42 -07:00
`_matrix/client/r0/rooms/${hs2RoomId}/messages?limit=5&dir=b&filter={"types":["m.room.message"]}`
);
const messageResData = await fetchEndpoint(messagesEndpoint, {
accessToken: hs1Client.accessToken,
});
2022-02-22 19:55:42 -07:00
// Make sure it returned some messages
assert.strictEqual(messageResData.chunk.length, 5);
// Make sure all of the messages belong to the room
messageResData.chunk.map((event) => {
const isEventInRoomFromHs2 = room2EventIds.some((room2EventId) => {
return room2EventId === event.event_id;
});
// Make sure the message belongs to the room on hs2
assert.strictEqual(
isEventInRoomFromHs2,
true,
`Expected ${event.event_id} (${event.type}: "${
event.content.body
}") to be in room on hs2=${JSON.stringify(room2EventIds)}`
);
});
2022-02-22 15:06:29 -07:00
});
2022-02-22 19:55:42 -07:00
it('can render diverse messages');
it(`can render day back in time from room on remote homeserver we haven't backfilled from`);
it(`will redirect to hour pagination when there are too many messages`);
2022-02-22 15:06:29 -07:00
});