Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions app/api/server/v1/chat.js
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ API.v1.addRoute('chat.postMessage', { authRequired: true }, {
API.v1.addRoute('chat.search', { authRequired: true }, {
get() {
const { roomId, searchText } = this.queryParams;
const { count } = this.getPaginationItems();
const { offset, count } = this.getPaginationItems();

if (!roomId) {
throw new Meteor.Error('error-roomId-param-not-provided', 'The required "roomId" query param is missing.');
Expand All @@ -158,7 +158,7 @@ API.v1.addRoute('chat.search', { authRequired: true }, {
}

let result;
Meteor.runAsUser(this.userId, () => { result = Meteor.call('messageSearch', searchText, roomId, count).message.docs; });
Meteor.runAsUser(this.userId, () => { result = Meteor.call('messageSearch', searchText, roomId, count, offset).message.docs; });

return API.v1.success({
messages: normalizeMessagesForUser(result, this.userId),
Expand Down
4 changes: 3 additions & 1 deletion server/methods/messageSearch.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,11 @@ import { settings } from '../../app/settings';
import { readSecondaryPreferred } from '../database/readSecondaryPreferred';

Meteor.methods({
messageSearch(text, rid, limit) {
messageSearch(text, rid, limit, offset) {
check(text, String);
check(rid, Match.Maybe(String));
check(limit, Match.Optional(Number));
check(offset, Match.Optional(Number));

// TODO: Evaluate why we are returning `users` and `channels`, as the only thing that gets set is the `messages`.
const result = {
Expand Down Expand Up @@ -46,6 +47,7 @@ Meteor.methods({
sort: {
ts: -1,
},
skip: offset || 0,
limit: limit || 20,
};

Expand Down
61 changes: 58 additions & 3 deletions tests/end-to-end/api/05-chat.js
Original file line number Diff line number Diff line change
Expand Up @@ -1055,12 +1055,28 @@ describe('[Chat]', function() {
});

describe('/chat.search', () => {
beforeEach((done) => {
const sendMessage = (text) => {
request.post(api('chat.sendMessage'))
.set(credentials)
.send({
message: {
rid: 'GENERAL',
msg: text,
},
})
.end(() => {});
};
for (let i = 0; i < 5; i++) { sendMessage('msg1'); }
done();
});

it('should return a list of messages when execute successfully', (done) => {
request.get(api('chat.search'))
.set(credentials)
.query({
roomId: 'GENERAL',
searchText: 'This message was edited via API',
searchText: 'msg1',
})
.expect('Content-Type', 'application/json')
.expect(200)
Expand All @@ -1070,23 +1086,62 @@ describe('[Chat]', function() {
})
.end(done);
});
it('should return a list of messages when is provided "count" query parameter execute successfully', (done) => {
it('should return a list of messages(length=1) when is provided "count" query parameter execute successfully', (done) => {
request.get(api('chat.search'))
.set(credentials)
.query({
roomId: 'GENERAL',
searchText: 'This message was edited via API',
searchText: 'msg1',
count: 1,
})
.expect('Content-Type', 'application/json')
.expect(200)
.expect((res) => {
expect(res.body).to.have.property('success', true);
expect(res.body).to.have.property('messages');
expect(res.body.messages.length).to.equal(1);
})
.end(done);
});
it('should return a list of messages(length=3) when is provided "count" and "offset" query parameters are executed successfully', (done) => {
request.get(api('chat.search'))
.set(credentials)
.query({
roomId: 'GENERAL',
searchText: 'msg1',
offset: 1,
count: 3,
})
.expect('Content-Type', 'application/json')
.expect(200)
.expect((res) => {
expect(res.body).to.have.property('success', true);
expect(res.body).to.have.property('messages');
expect(res.body.messages.length).to.equal(3);
})
.end(done);
});

it('should return a empty list of messages when is provided a huge offset value', (done) => {
request.get(api('chat.search'))
.set(credentials)
.query({
roomId: 'GENERAL',
searchText: 'msg1',
offset: 9999,
count: 3,
})
.expect('Content-Type', 'application/json')
.expect(200)
.expect((res) => {
expect(res.body).to.have.property('success', true);
expect(res.body).to.have.property('messages');
expect(res.body.messages.length).to.equal(0);
})
.end(done);
});
});

describe('[/chat.react]', () => {
it('should return statusCode: 200 and success when try unreact a message that\'s no reacted yet', (done) => {
request.post(api('chat.react'))
Expand Down