Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[NEW] REST API to use Spotlight #9509

Merged
merged 6 commits into from
Feb 15, 2018
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
1 change: 1 addition & 0 deletions packages/rocketchat-api/package.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,4 +44,5 @@ Package.onUse(function(api) {
api.addFiles('server/v1/settings.js', 'server');
api.addFiles('server/v1/stats.js', 'server');
api.addFiles('server/v1/users.js', 'server');
api.addFiles('server/v1/spotlight.js', 'server');
});
27 changes: 27 additions & 0 deletions packages/rocketchat-api/server/v1/spotlight.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/**
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);
}
});
40 changes: 40 additions & 0 deletions tests/end-to-end/api/11-spotlight.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
/* 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);
});
});
});