Skip to content

Commit ea084df

Browse files
committed
test: add end-to-end tests for inviting user from a remote server to a room and verifying member list
1 parent a7d8424 commit ea084df

File tree

2 files changed

+69
-3
lines changed

2 files changed

+69
-3
lines changed

ee/packages/federation-matrix/tests/end-to-end/room.spec.ts

Lines changed: 48 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import {
99
addUserToRoomSlashCommand,
1010
acceptRoomInvite,
1111
rejectRoomInvite,
12+
getRoomMembers,
1213
} from '../../../../../apps/meteor/tests/data/rooms.helper';
1314
import { type IRequestConfig, getRequestConfig, createUser, deleteUser } from '../../../../../apps/meteor/tests/data/users.helper';
1415
import { IS_EE } from '../../../../../apps/meteor/tests/e2e/config/constants';
@@ -1563,14 +1564,59 @@ import { SynapseClient } from '../helper/synapse-client';
15631564
// RC view: Admin tries to accept rc1User1's invitation
15641565
const response = await acceptRoomInvite(federatedChannel._id, rc1AdminRequestConfig);
15651566
expect(response.success).toBe(false);
1566-
expect(response.error).toBe('Failed to handle invite: No subscription found or user does not have permission to accept or reject this invite');
1567+
expect(response.error).toBe(
1568+
'Failed to handle invite: No subscription found or user does not have permission to accept or reject this invite',
1569+
);
15671570
});
15681571

15691572
it('It should not allow admin to reject invitation on behalf of another user', async () => {
15701573
// RC view: Admin tries to reject rc1User1's invitation
15711574
const response = await rejectRoomInvite(federatedChannel._id, rc1AdminRequestConfig);
15721575
expect(response.success).toBe(false);
1573-
expect(response.error).toBe('Failed to handle invite: No subscription found or user does not have permission to accept or reject this invite');
1576+
expect(response.error).toBe(
1577+
'Failed to handle invite: No subscription found or user does not have permission to accept or reject this invite',
1578+
);
1579+
});
1580+
});
1581+
});
1582+
1583+
describe('Inviting a RC user from Synapse', () => {
1584+
describe('Room that already contains previous events', () => {
1585+
it('It should reflect all the members and messagens on the rocket.chat side', async () => {
1586+
let roomId: string;
1587+
let channelName: string;
1588+
1589+
beforeAll(async () => {
1590+
channelName = `federated-channel-invite-single-${Date.now()}`;
1591+
roomId = await hs1AdminApp.createRoom(channelName);
1592+
1593+
await hs1AdminApp.sendTextMessage(roomId, 'Message from admin');
1594+
await hs1AdminApp.inviteUserToRoom(roomId, federationConfig.rc1.additionalUser1.matrixUserId);
1595+
await hs1User1App.acceptInvitationForRoomName(channelName);
1596+
await hs1User1App.sendTextMessage(roomId, 'Message from user1');
1597+
1598+
await hs1AdminApp.inviteUserToRoom(roomId, federationConfig.rc1.adminUser);
1599+
1600+
await acceptRoomInvite(roomId, rc1User1RequestConfig);
1601+
}, 15000);
1602+
1603+
it('It should show all the three users in the members list', async () => {
1604+
const members = await getRoomMembers(roomId, rc1AdminRequestConfig);
1605+
expect(members.members.length).toBe(3);
1606+
expect(members.members.find((member: IUser) => member.username === federationConfig.rc1.adminUser)).not.toBeNull();
1607+
expect(
1608+
members.members.find((member: IUser) => member.username === federationConfig.rc1.additionalUser1.username),
1609+
).not.toBeNull();
1610+
expect(members.members.find((member: IUser) => member.username === federationConfig.hs1.adminMatrixUserId)).not.toBeNull();
1611+
// RC view: Check in RC
1612+
const rc1AdminUserInRC = await findRoomMember(roomId, federationConfig.rc1.adminUser, {}, rc1AdminRequestConfig);
1613+
const rc1User1InRC = await findRoomMember(roomId, federationConfig.rc1.additionalUser1.username, {}, rc1AdminRequestConfig);
1614+
const hs1AdminUserInRC = await findRoomMember(roomId, federationConfig.hs1.adminMatrixUserId, {}, rc1AdminRequestConfig);
1615+
1616+
expect(rc1AdminUserInRC).not.toBeNull();
1617+
expect(rc1User1InRC).not.toBeNull();
1618+
expect(hs1AdminUserInRC).not.toBeNull();
1619+
});
15741620
});
15751621
});
15761622
});

ee/packages/federation-matrix/tests/helper/synapse-client.ts

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
import * as fs from 'fs';
88
import * as path from 'path';
99

10-
import { createClient, type MatrixClient, KnownMembership, type Room, type RoomMember } from 'matrix-js-sdk';
10+
import { createClient, type MatrixClient, KnownMembership, type Room, type RoomMember, Visibility } from 'matrix-js-sdk';
1111

1212
/**
1313
* Creates a promise that resolves after the specified delay.
@@ -132,6 +132,26 @@ export class SynapseClient {
132132
throw new Error(`No room found with name ${roomName}`);
133133
}
134134

135+
async createRoom(roomName: string, visibility: Visibility = Visibility.Private): Promise<string> {
136+
if (!this.matrixClient) {
137+
throw new Error('Matrix client is not initialized');
138+
}
139+
140+
const room = await this.matrixClient.createRoom({
141+
name: roomName,
142+
visibility,
143+
});
144+
145+
return room.room_id;
146+
}
147+
148+
async inviteUserToRoom(roomId: string, userId: string): Promise<void> {
149+
if (!this.matrixClient) {
150+
throw new Error('Matrix client is not initialized');
151+
}
152+
await this.matrixClient.invite(userId, roomId);
153+
}
154+
135155
/**
136156
* Finds a room by name and membership status.
137157
*

0 commit comments

Comments
 (0)