Skip to content

Commit 466137a

Browse files
authored
test(federation): fix test to assert better subscription names when invite comes from Rocket.Chat (#37969)
1 parent 30575e7 commit 466137a

File tree

1 file changed

+45
-37
lines changed
  • ee/packages/federation-matrix/tests/end-to-end

1 file changed

+45
-37
lines changed

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

Lines changed: 45 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -861,55 +861,63 @@ const waitForRoomEvent = async (
861861
let rcRoom: IRoomNativeFederated;
862862
let hs1Room1: Room;
863863

864-
let rcUser1: TestUser<IUser>;
865-
let rcUserConfig1: IRequestConfig;
866-
867-
let rcUser2: TestUser<IUser>;
868-
let rcUserConfig2: IRequestConfig;
869-
870-
const rcUserName1 = `dm-rc-multi-user1-${Date.now()}`;
871-
const rcUserFullName1 = `DM RC Multi User1 ${Date.now()}`;
864+
const rcUser1 = {
865+
username: `dm-rc-multi-user1-${Date.now()}`,
866+
fullName: `DM RC Multi User1 ${Date.now()}`,
867+
get matrixId() {
868+
return `@${this.username}:${federationConfig.rc1.domain}`;
869+
},
870+
config: {} as IRequestConfig,
871+
user: {} as TestUser<IUser>,
872+
};
872873

873-
const rcUserName2 = `dm-rc-multi-user2-${Date.now()}`;
874-
const rcUserFullName2 = `DM RC Multi User2 ${Date.now()}`;
874+
const rcUser2 = {
875+
username: `dm-rc-multi-user2-${Date.now()}`,
876+
fullName: `DM RC Multi User2 ${Date.now()}`,
877+
get matrixId() {
878+
return `@${this.username}:${federationConfig.rc1.domain}`;
879+
},
880+
config: {} as IRequestConfig,
881+
user: {} as TestUser<IUser>,
882+
};
875883

876884
beforeAll(async () => {
877885
// Create RC user
878-
rcUser1 = await createUser(
886+
rcUser1.user = await createUser(
879887
{
880-
username: rcUserName1,
888+
username: rcUser1.username,
881889
password: 'random',
882-
email: `${rcUserName1}@rocket.chat`,
883-
name: rcUserFullName1,
890+
email: `${rcUser1.username}@rocket.chat`,
891+
name: rcUser1.fullName,
884892
},
885893
rc1AdminRequestConfig,
886894
);
887895

888-
rcUserConfig1 = await getRequestConfig(federationConfig.rc1.url, rcUser1.username, 'random');
896+
rcUser1.config = await getRequestConfig(federationConfig.rc1.url, rcUser1.username, 'random');
889897

890-
rcUser2 = await createUser(
898+
rcUser2.user = await createUser(
891899
{
892-
username: rcUserName2,
900+
username: rcUser2.username,
893901
password: 'random',
894-
email: `${rcUserName2}@rocket.chat`,
895-
name: rcUserFullName2,
902+
email: `${rcUser2.username}@rocket.chat`,
903+
name: rcUser2.fullName,
896904
},
897905
rc1AdminRequestConfig,
898906
);
899907

900-
rcUserConfig2 = await getRequestConfig(federationConfig.rc1.url, rcUser2.username, 'random');
908+
rcUser2.config = await getRequestConfig(federationConfig.rc1.url, rcUser2.username, 'random');
901909
});
902910

903911
afterAll(async () => {
904-
await deleteUser(rcUser1, {}, rc1AdminRequestConfig);
905-
await deleteUser(rcUser2, {}, rc1AdminRequestConfig);
912+
await deleteUser(rcUser1.user, {}, rc1AdminRequestConfig);
913+
await deleteUser(rcUser2.user, {}, rc1AdminRequestConfig);
906914
});
907915

908916
it('should create a group DM with a Synapse and Rocket.Chat user', async () => {
909917
// Create group DM from RC user to two Synapse users
910-
const response = await rcUserConfig1.request
918+
const response = await rcUser1.config.request
911919
.post(api('dm.create'))
912-
.set(rcUserConfig1.credentials)
920+
.set(rcUser1.config.credentials)
913921
.send({
914922
usernames: [federationConfig.hs1.adminMatrixUserId, rcUser2.username].join(','),
915923
})
@@ -918,7 +926,7 @@ const waitForRoomEvent = async (
918926
expect(response.body).toHaveProperty('success', true);
919927
expect(response.body).toHaveProperty('room');
920928

921-
const roomInfo = await getRoomInfo(response.body.room._id, rcUserConfig1);
929+
const roomInfo = await getRoomInfo(response.body.room._id, rcUser1.config);
922930

923931
expect(roomInfo).toHaveProperty('room');
924932

@@ -943,19 +951,19 @@ const waitForRoomEvent = async (
943951

944952
it('should display the fname containing the two invited users for the inviter', async () => {
945953
// Check the subscription for the inviter
946-
const sub = await getSubscriptionByRoomId(rcRoom._id, rcUserConfig1.credentials, rcUserConfig1.request);
954+
const sub = await getSubscriptionByRoomId(rcRoom._id, rcUser1.config.credentials, rcUser1.config.request);
947955

948956
// Should contain both invited users in the name
949957
expect(sub).toHaveProperty('name', `${federationConfig.hs1.adminMatrixUserId}, ${rcUser2.username}`);
950-
expect(sub).toHaveProperty('fname', `${federationConfig.hs1.adminMatrixUserId}, ${rcUser2.name}`);
958+
expect(sub).toHaveProperty('fname', `${federationConfig.hs1.adminMatrixUserId}, ${rcUser2.fullName}`);
951959
});
952960

953-
it.failing("should display only the inviter's username for the invited user on Rocket.Chat", async () => {
954-
const sub = await getSubscriptionByRoomId(rcRoom._id, rcUserConfig2.credentials, rcUserConfig2.request);
961+
it("should display only the inviter's username for the invited user on Rocket.Chat", async () => {
962+
const sub = await getSubscriptionByRoomId(rcRoom._id, rcUser2.config.credentials, rcUser2.config.request);
955963

956964
expect(sub).toHaveProperty('status', 'INVITED');
957-
expect(sub).toHaveProperty('name', rcUser1.name);
958-
expect(sub).toHaveProperty('fname', rcUser1.username);
965+
expect(sub).toHaveProperty('name', `${federationConfig.hs1.adminMatrixUserId}, ${rcUser1.username}`);
966+
expect(sub).toHaveProperty('fname', `${federationConfig.hs1.adminMatrixUserId}, ${rcUser1.fullName}`);
959967
});
960968

961969
it('should accept the invitation on Synapse', async () => {
@@ -974,15 +982,15 @@ const waitForRoomEvent = async (
974982
expect(hs1Room1.name).toBe(`${rcUser1.username} and ${rcUser2.username}`);
975983
});
976984

977-
it.failing('should keep the fname to the RC invited user when the Synapse invited user accepts the DM', async () => {
985+
it('should keep the fname to the RC invited user when the Synapse invited user accepts the DM', async () => {
978986
await retry(
979987
'this is an async operation, so we need to wait for the event to be processed',
980988
async () => {
981-
const sub = await getSubscriptionByRoomId(rcRoom._id, rcUserConfig2.credentials, rcUserConfig2.request);
989+
const sub = await getSubscriptionByRoomId(rcRoom._id, rcUser2.config.credentials, rcUser2.config.request);
982990

983991
expect(sub).toHaveProperty('status', 'INVITED');
984-
expect(sub).toHaveProperty('name', rcUser1.name);
985-
expect(sub).toHaveProperty('fname', rcUser1.username);
992+
expect(sub).toHaveProperty('name', `${federationConfig.hs1.adminMatrixUserId}, ${rcUser1.username}`);
993+
expect(sub).toHaveProperty('fname', `${federationConfig.hs1.adminMatrixUserId}, ${rcUser1.fullName}`);
986994
},
987995
{ delayMs: 100 },
988996
);
@@ -994,10 +1002,10 @@ const waitForRoomEvent = async (
9941002
await retry(
9951003
'this is an async operation, so we need to wait for the event to be processed',
9961004
async () => {
997-
const sub = await getSubscriptionByRoomId(rcRoom._id, rcUserConfig1.credentials, rcUserConfig1.request);
1005+
const sub = await getSubscriptionByRoomId(rcRoom._id, rcUser1.config.credentials, rcUser1.config.request);
9981006

9991007
expect(sub).toHaveProperty('name', rcUser2.username);
1000-
expect(sub).toHaveProperty('fname', rcUser2.name);
1008+
expect(sub).toHaveProperty('fname', rcUser2.fullName);
10011009
},
10021010
{ delayMs: 100 },
10031011
);

0 commit comments

Comments
 (0)