[FIX] Fix REST spotlight to allow searches with # and @ (#10410)
[FIX] REST spotlight API wasn't allowing searches with # and @pull/10532/head
parent
2d123a8be7
commit
fe663cf674
@ -1,27 +0,0 @@ |
|||||||
/** |
|
||||||
This API returns the result of a query of rooms |
|
||||||
and users, using Meteor's Spotlight method. |
|
||||||
|
|
||||||
Method: GET |
|
||||||
Route: api/v1/spotlight |
|
||||||
Query params: |
|
||||||
- query: The term to be searched. |
|
||||||
*/ |
|
||||||
RocketChat.API.v1.addRoute('spotlight', { authRequired: true }, { |
|
||||||
get() { |
|
||||||
check(this.queryParams, { |
|
||||||
query: String |
|
||||||
}); |
|
||||||
|
|
||||||
const { query } = this.queryParams; |
|
||||||
|
|
||||||
const result = Meteor.runAsUser(this.userId, () => |
|
||||||
Meteor.call('spotlight', query, null, { |
|
||||||
rooms: true, |
|
||||||
users: true |
|
||||||
}) |
|
||||||
); |
|
||||||
|
|
||||||
return RocketChat.API.v1.success(result); |
|
||||||
} |
|
||||||
}); |
|
@ -1,40 +0,0 @@ |
|||||||
/* eslint-env mocha */ |
|
||||||
/* globals expect */ |
|
||||||
|
|
||||||
import {getCredentials, api, request, credentials } from '../../data/api-data.js'; |
|
||||||
|
|
||||||
describe('[Spotlight]', function() { |
|
||||||
this.retries(0); |
|
||||||
|
|
||||||
before(done => getCredentials(done)); |
|
||||||
|
|
||||||
describe('[/spotlight]', () => { |
|
||||||
it('should fail when does not have query param', (done) => { |
|
||||||
request.get(api('spotlight')) |
|
||||||
.set(credentials) |
|
||||||
.expect('Content-Type', 'application/json') |
|
||||||
.expect(400) |
|
||||||
.expect((res) => { |
|
||||||
expect(res.body).to.have.property('success', false); |
|
||||||
expect(res.body).to.have.property('error'); |
|
||||||
}) |
|
||||||
.end(done); |
|
||||||
}); |
|
||||||
|
|
||||||
it('should return objects for a valid query param', (done) => { |
|
||||||
request.get(api('spotlight')) |
|
||||||
.query({ |
|
||||||
query: 'foobar' |
|
||||||
}) |
|
||||||
.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('users').that.have.lengthOf(0); |
|
||||||
expect(res.body).to.have.property('rooms').that.have.lengthOf(0); |
|
||||||
}) |
|
||||||
.end(done); |
|
||||||
}); |
|
||||||
}); |
|
||||||
}); |
|
Loading…
Reference in new issue