Skip to content

Commit

Permalink
fix: no sorting by status
Browse files Browse the repository at this point in the history
Signed-off-by: Abhinav Kumar <abhinav@avitechlab.com>
  • Loading branch information
abhinavkrin committed Jan 22, 2025
1 parent 5a5ffb0 commit e37af2b
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 2 deletions.
2 changes: 1 addition & 1 deletion apps/meteor/server/lib/findUsersOfRoomOrderedByRole.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ export async function findUsersOfRoomOrderedByRole({

const sortCriteria = {
rolePriority: rolePrioritySort ?? 1,
statusConnection: -1,
status: -1,
...(usernameSort
? { username: usernameSort }
: {
Expand Down
43 changes: 42 additions & 1 deletion apps/meteor/tests/end-to-end/api/rooms.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3648,6 +3648,8 @@ describe('[Rooms]', () => {
let customRole: IRole;

let ownerCredentials: { 'X-Auth-Token': string; 'X-User-Id': string };
let memberUser1Credentials: { 'X-Auth-Token': string; 'X-User-Id': string };
let memberUser2Credentials: { 'X-Auth-Token': string; 'X-User-Id': string };

before(async () => {
[ownerUser, moderatorUser, memberUser1, memberUser2] = await Promise.all([
Expand All @@ -3657,7 +3659,11 @@ describe('[Rooms]', () => {
createUser({ username: `d_${Random.id()}` }),
]);

ownerCredentials = await login(ownerUser.username, password);
[ownerCredentials, memberUser1Credentials, memberUser2Credentials] = await Promise.all([
login(ownerUser.username, password),
login(memberUser1.username, password),
login(memberUser2.username, password),
]);

customRole = await createCustomRole({
name: `customRole.${Random.id()}`,
Expand Down Expand Up @@ -3848,6 +3854,41 @@ describe('[Rooms]', () => {
expect(fourth.username).to.equal(memberUser2.username);
});

describe('Sort by user status', () => {
before(async () => {
await request.post(api('settings/Accounts_AllowUserStatusMessageChange')).set(credentials).send({ value: true }).expect(200);

await Promise.all([
request.post(api('users.setStatus')).set(memberUser1Credentials).send({ status: 'offline', userId: memberUser1._id }).expect(200),
request.post(api('users.setStatus')).set(memberUser2Credentials).send({ status: 'online', userId: memberUser2._id }).expect(200),
]);
});

// Skipping resetting setting Accounts_AllowUserStatusMessageChange as default value is true
after(() =>
request.post(api('users.setStatus')).set(memberUser2Credentials).send({ status: 'offline', userId: memberUser2._id }).expect(200),
);

it('should sort by user status after user role', async () => {
const response = await request
.get(api('rooms.membersOrderedByRole'))
.set(credentials)
.query({
roomId: testChannel._id,
})
.expect('Content-Type', 'application/json')
.expect(200);

expect(response.body).to.have.property('success', true);
const [first, second, third, fourth] = response.body.members;

expect(first.username).to.equal(ownerUser.username); // since owner
expect(second.username).to.equal(moderatorUser.username); // siince moderator
expect(third.username).to.equal(memberUser2.username); // since online
expect(fourth.username).to.equal(memberUser1.username); // since offline
});
});

describe('Additional Visibility Tests', () => {
let outsiderUser: IUser;
let insideUser: IUser;
Expand Down

0 comments on commit e37af2b

Please sign in to comment.