Skip to content

Commit

Permalink
Merge branch 'develop' into fix/login-services-button-props
Browse files Browse the repository at this point in the history
  • Loading branch information
yash-rajpal authored Jul 8, 2024
2 parents 0f9eeb6 + b0f182e commit 74315c4
Show file tree
Hide file tree
Showing 10 changed files with 447 additions and 533 deletions.
696 changes: 298 additions & 398 deletions apps/meteor/app/lib/server/lib/notifyListener.ts

Large diffs are not rendered by default.

7 changes: 5 additions & 2 deletions apps/meteor/tests/data/uploads.helper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { createVisitor } from './livechat/rooms';
import { updateSetting } from './permissions.helper';
import { createRoom, deleteRoom } from './rooms.helper';
import { password } from './user';
import { createUser, login } from './users.helper';
import { createUser, login, deleteUser } from './users.helper';

export async function testFileUploads(
filesEndpoint: 'channels.files' | 'groups.files' | 'im.files',
Expand All @@ -22,14 +22,16 @@ export async function testFileUploads(
p: 'group',
d: 'room',
};
let user: any;

before(async () => {
await Promise.all([updateSetting('VoIP_Enabled', true), updateSetting('Message_KeepHistory', true)]);
user = await createUser();

testRoom = (
await createRoom({
type: roomType,
...(roomType === 'd' ? { username: 'rocket.cat' } : { name: `channel-files-${Date.now()}` }),
...(roomType === 'd' ? { username: user.username } : { name: `channel-files-${Date.now()}` }),
} as any)
).body[propertyMap[roomType]];
});
Expand All @@ -39,6 +41,7 @@ export async function testFileUploads(
deleteRoom({ type: 'c' as const, roomId: testRoom._id }),
updateSetting('VoIP_Enabled', false),
updateSetting('Message_KeepHistory', false),
deleteUser(user),
]),
);

Expand Down
11 changes: 7 additions & 4 deletions apps/meteor/tests/end-to-end/api/01-users.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { assert, expect } from 'chai';
import { after, afterEach, before, beforeEach, describe, it } from 'mocha';
import { MongoClient } from 'mongodb';

import { getCredentials, api, request, credentials, apiEmail, apiUsername, log, wait, reservedWords } from '../../data/api-data';
import { getCredentials, api, request, credentials, apiEmail, apiUsername, wait, reservedWords } from '../../data/api-data';
import { imgURL } from '../../data/interactions';
import { createAgent, makeAgentAvailable } from '../../data/livechat/rooms';
import { removeAgent, getAgent } from '../../data/livechat/users';
Expand Down Expand Up @@ -1091,16 +1091,18 @@ describe('[Users]', () => {
.end(done);
});

it.skip('should query all users in the system by name', (done) => {
it('should query all users in the system by name', (done) => {
// filtering user list
void request
.get(api('users.list'))
.set(credentials)
.query({
name: { $regex: 'g' },
sort: JSON.stringify({
createdAt: -1,
}),
})
.field('username', 1)
.expect(log)
.expect('Content-Type', 'application/json')
.expect(200)
.expect((res) => {
Expand Down Expand Up @@ -4146,6 +4148,7 @@ describe('[Users]', () => {
it('should list all users', async () => {
await request
.get(api('users.listByStatus'))
.query({ searchTerm: user.name })
.set(credentials)
.expect('Content-Type', 'application/json')
.expect(200)
Expand All @@ -4165,7 +4168,7 @@ describe('[Users]', () => {
await request
.get(api('users.listByStatus'))
.set(credentials)
.query({ hasLoggedIn: true, status: 'active' })
.query({ hasLoggedIn: true, status: 'active', searchTerm: user.name })
.expect('Content-Type', 'application/json')
.expect(200)
.expect((res) => {
Expand Down
16 changes: 8 additions & 8 deletions apps/meteor/tests/end-to-end/api/02-channels.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2189,21 +2189,21 @@ describe('[Channels]', () => {
]);
});

it('/channels.list', (done) => {
it('should return the last message user real name', (done) => {
void request
.get(api('channels.list'))
.get(api('channels.info'))
.query({
roomId: testChannel._id,
})
.set(credentials)
.expect('Content-Type', 'application/json')
.expect(200)
.expect((res) => {
expect(res.body).to.have.property('success', true);
expect(res.body).to.have.property('count');
expect(res.body).to.have.property('total');
expect(res.body).to.have.property('channels').and.to.be.an('array');

const retChannel = (res.body.channels as IRoom[]).find(({ _id }) => _id === testChannel._id);
const { channel } = res.body;

expect(retChannel).to.have.nested.property('lastMessage.u.name', 'RocketChat Internal Admin Test');
expect(channel._id).to.be.equal(testChannel._id);
expect(channel).to.have.nested.property('lastMessage.u.name', 'RocketChat Internal Admin Test');
})
.end(done);
});
Expand Down
38 changes: 10 additions & 28 deletions apps/meteor/tests/end-to-end/api/03-groups.ts
Original file line number Diff line number Diff line change
Expand Up @@ -646,7 +646,7 @@ describe('[Groups]', () => {
})
.expect('Content-Type', 'application/json')
.expect(200),
// updatePermission('kick-user-from-any-p-room', []),
updatePermission('kick-user-from-any-p-room', []),
updatePermission('remove-user', ['admin', 'owner', 'moderator']),
deleteUser(testUserModerator),
deleteUser(testUserOwner),
Expand All @@ -655,6 +655,7 @@ describe('[Groups]', () => {
});

it("should return an error when user is not a member of the group and doesn't have permission", async () => {
await updatePermission('kick-user-from-any-p-room', []);
await request
.post(api('groups.kick'))
.set(credentials)
Expand Down Expand Up @@ -698,7 +699,7 @@ describe('[Groups]', () => {
.expect(200);
});

it.skip('should kick user from group if not a member of the room but has the required permission', async () => {
it('should kick user from group if not a member of the room but has the required permission', async () => {
await updatePermission('kick-user-from-any-p-room', ['admin']);
await inviteUser(testUserMember._id);

Expand Down Expand Up @@ -2080,40 +2081,21 @@ describe('[Groups]', () => {
});
});

it('/groups.list', (done) => {
it('should return the last message user real name', (done) => {
void request
.get(api('groups.list'))
.set(credentials)
.expect('Content-Type', 'application/json')
.expect(200)
.expect((res) => {
expect(res.body).to.have.property('success', true);
expect(res.body).to.have.property('count');
expect(res.body).to.have.property('total');
expect(res.body).to.have.property('groups').and.to.be.an('array');

const retGroup = (res.body.groups as IRoom[]).find(({ _id }) => _id === realNameGroup._id);

expect(retGroup).to.have.nested.property('lastMessage.u.name', 'RocketChat Internal Admin Test');
.get(api('groups.info'))
.query({
roomId: realNameGroup._id,
})
.end(done);
});

it('/groups.listAll', (done) => {
void request
.get(api('groups.listAll'))
.set(credentials)
.expect('Content-Type', 'application/json')
.expect(200)
.expect((res) => {
expect(res.body).to.have.property('success', true);
expect(res.body).to.have.property('count');
expect(res.body).to.have.property('total');
expect(res.body).to.have.property('groups').and.to.be.an('array');

const retGroup = (res.body.groups as IRoom[]).find(({ _id }) => _id === realNameGroup._id);
const { group } = res.body;

expect(retGroup).to.have.nested.property('lastMessage.u.name', 'RocketChat Internal Admin Test');
expect(group._id).to.be.equal(realNameGroup._id);
expect(group).to.have.nested.property('lastMessage.u.name', 'RocketChat Internal Admin Test');
})
.end(done);
});
Expand Down
77 changes: 42 additions & 35 deletions apps/meteor/tests/end-to-end/api/04-direct-message.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,19 +9,38 @@ import { deleteRoom } from '../../data/rooms.helper';
import { testFileUploads } from '../../data/uploads.helper';
import { password, adminUsername } from '../../data/user';
import type { TestUser } from '../../data/users.helper';
import { createUser, deleteUser, login } from '../../data/users.helper';
import { createUser, deleteUser, login, setUserStatus } from '../../data/users.helper';

describe('[Direct Messages]', () => {
let testDM: IRoom & { rid: IRoom['_id'] };
let user: TestUser<IUser>;
let directMessage: { _id: IRoom['_id'] };

before((done) => getCredentials(done));

before(async () => {
user = await createUser();
const cred = await login(user.username, password);
await setUserStatus(cred);
await request
.post(api('im.create'))
.set(credentials)
.send({
username: user.username,
})
.expect('Content-Type', 'application/json')
.expect(200)
.expect((res) => {
testDM = res.body.room;
});
});

before('/chat.postMessage', (done) => {
void request
.post(api('chat.postMessage'))
.set(credentials)
.send({
channel: 'rocket.cat',
roomId: testDM.rid,
text: 'This message was sent using the API',
})
.expect('Content-Type', 'application/json')
Expand All @@ -35,20 +54,22 @@ describe('[Direct Messages]', () => {
.end(done);
});

after(() => deleteUser(user));

describe('/im.setTopic', () => {
it('should set the topic of the DM with a string', (done) => {
void request
.post(api('im.setTopic'))
.set(credentials)
.send({
roomId: directMessage._id,
topic: 'a direct message with rocket.cat',
topic: `a direct message with ${user.username}`,
})
.expect('Content-Type', 'application/json')
.expect(200)
.expect((res) => {
expect(res.body).to.have.property('success', true);
expect(res.body).to.have.nested.property('topic', 'a direct message with rocket.cat');
expect(res.body).to.have.nested.property('topic', `a direct message with ${user.username}`);
})
.end(done);
});
Expand All @@ -71,22 +92,8 @@ describe('[Direct Messages]', () => {
});

describe('Testing DM info', () => {
let testDM: IRoom;
let dmMessage: IMessage;
it('creating new DM...', (done) => {
void request
.post(api('im.create'))
.set(credentials)
.send({
username: 'rocket.cat',
})
.expect('Content-Type', 'application/json')
.expect(200)
.expect((res) => {
testDM = res.body.room;
})
.end(done);
});

it('sending a message...', (done) => {
void request
.post(api('chat.sendMessage'))
Expand Down Expand Up @@ -193,10 +200,10 @@ describe('[Direct Messages]', () => {
.expect(200)
.expect((res) => {
expect(res.body).to.have.property('success', true);
expect(res.body).to.have.property('count', 1);
expect(res.body).to.have.property('total', 1);
expect(res.body).to.have.property('count');
expect(res.body).to.have.property('total');
expect(res.body).to.have.property('ims').and.to.be.an('array');
const im = res.body.ims[0];
const im = (res.body.ims as IRoom[]).find((dm) => dm._id === testDM._id);
expect(im).to.have.property('_id');
expect(im).to.have.property('t').and.to.be.eq('d');
expect(im).to.have.property('msgs').and.to.be.a('number');
Expand All @@ -217,10 +224,10 @@ describe('[Direct Messages]', () => {
.expect(200)
.expect((res) => {
expect(res.body).to.have.property('success', true);
expect(res.body).to.have.property('count', 1);
expect(res.body).to.have.property('total', 1);
expect(res.body).to.have.property('count');
expect(res.body).to.have.property('total');
expect(res.body).to.have.property('ims').and.to.be.an('array');
const im = res.body.ims[0];
const im = (res.body.ims as IRoom[]).find((dm) => dm._id === testDM._id);
expect(im).to.have.property('_id');
expect(im).to.have.property('t').and.to.be.eq('d');
expect(im).to.have.property('msgs').and.to.be.a('number');
Expand All @@ -246,11 +253,11 @@ describe('[Direct Messages]', () => {
.expect(200)
.expect((res) => {
expect(res.body).to.have.property('success', true);
expect(res.body).to.have.property('count', 1);
expect(res.body).to.have.property('total', 1);
expect(res.body).to.have.property('count');
expect(res.body).to.have.property('total');
expect(res.body).to.have.property('ims').and.to.be.an('array');

const im = res.body.ims[0];
const im = (res.body.ims as IRoom[]).find((dm) => dm._id === testDM._id) as IRoom;

expect(im).to.have.property('_id');
expect(im).to.have.property('t').and.to.be.eq('d');
Expand All @@ -276,10 +283,10 @@ describe('[Direct Messages]', () => {
.expect(200)
.expect((res) => {
expect(res.body).to.have.property('success', true);
expect(res.body).to.have.property('count', 1);
expect(res.body).to.have.property('total', 1);
expect(res.body).to.have.property('count');
expect(res.body).to.have.property('total');
expect(res.body).to.have.property('ims').and.to.be.an('array');
const im = res.body.ims[0];
const im = (res.body.ims as IRoom[]).find((dm) => dm._id === testDM._id) as IRoom;
expect(im).to.have.property('_id');
expect(im).to.have.property('t').and.to.be.eq('d');
expect(im).to.have.property('msgs').and.to.be.a('number');
Expand Down Expand Up @@ -424,7 +431,7 @@ describe('[Direct Messages]', () => {
.set(credentials)
.send({
roomId: directMessage._id,
userId: 'rocket.cat',
userId: user._id,
})
.expect('Content-Type', 'application/json')
.expect(200)
Expand Down Expand Up @@ -560,7 +567,7 @@ describe('[Direct Messages]', () => {
.get(api('im.members'))
.set(credentials)
.query({
username: 'rocket.cat',
username: user.username,
})
.expect('Content-Type', 'application/json')
.expect(200)
Expand Down Expand Up @@ -791,7 +798,7 @@ describe('[Direct Messages]', () => {
.post(api('im.create'))
.set(credentials)
.send({
username: 'rocket.cat',
username: user.username,
})
.expect(200)
.expect('Content-Type', 'application/json')
Expand All @@ -806,7 +813,7 @@ describe('[Direct Messages]', () => {
.post(api('im.delete'))
.set(credentials)
.send({
username: 'rocket.cat',
username: user.username,
})
.expect(200)
.expect('Content-Type', 'application/json')
Expand Down
Loading

0 comments on commit 74315c4

Please sign in to comment.