Skip to content
Snippets Groups Projects
Commit 3e419e02 authored by Marcos Spessatto Defendi's avatar Marcos Spessatto Defendi Committed by Diego Sampaio
Browse files

[FIX] Change pagination field to `count` on /chat.search REST endpoint #11340

parent aee5d309
No related branches found
No related tags found
No related merge requests found
......@@ -123,7 +123,8 @@ RocketChat.API.v1.addRoute('chat.postMessage', { authRequired: true }, {
RocketChat.API.v1.addRoute('chat.search', { authRequired: true }, {
get() {
const { roomId, searchText, limit } = this.queryParams;
const { roomId, searchText } = this.queryParams;
const { count } = this.getPaginationItems();
if (!roomId) {
throw new Meteor.Error('error-roomId-param-not-provided', 'The required "roomId" query param is missing.');
......@@ -133,12 +134,8 @@ RocketChat.API.v1.addRoute('chat.search', { authRequired: true }, {
throw new Meteor.Error('error-searchText-param-not-provided', 'The required "searchText" query param is missing.');
}
if (limit && (typeof limit !== 'number' || isNaN(limit) || limit <= 0)) {
throw new Meteor.Error('error-limit-param-invalid', 'The "limit" query parameter must be a valid number and be greater than 0.');
}
let result;
Meteor.runAsUser(this.userId, () => result = Meteor.call('messageSearch', searchText, roomId, limit).message.docs);
Meteor.runAsUser(this.userId, () => result = Meteor.call('messageSearch', searchText, roomId, count).message.docs);
return RocketChat.API.v1.success({
messages: result
......
......@@ -362,6 +362,22 @@ describe('[Chat]', function() {
})
.end(done);
});
it('should return a list of messages 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',
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');
})
.end(done);
});
});
describe('[/chat.react]', () => {
it('should return statusCode: 200 and success when try unreact a message that\'s no reacted yet', (done) => {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment