Skip to content

Commit

Permalink
Correct logic, and add one more test case in REST directory endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
MarcosSpessatto committed Apr 19, 2018
1 parent 7535f24 commit 57a4fc5
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 8 deletions.
6 changes: 3 additions & 3 deletions packages/rocketchat-api/server/v1/misc.js
Original file line number Diff line number Diff line change
Expand Up @@ -185,9 +185,9 @@ RocketChat.API.v1.addRoute('directory', { authRequired: true }, {
limit: count
}));

if (result) {
return RocketChat.API.v1.success({ result });
if (!result) {
return RocketChat.API.v1.failure('Please verify the parameters');
}
return RocketChat.API.v1.failure('Please verify the parameters');
return RocketChat.API.v1.success({ result });
}
});
28 changes: 23 additions & 5 deletions tests/end-to-end/api/00-miscellaneous.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
/* globals expect */
/* eslint no-unused-vars: 0 */

import { getCredentials, api, login, request, credentials } from '../../data/api-data.js';
import { adminEmail, adminUsername, adminPassword, password } from '../../data/user.js';
import {getCredentials, api, login, request, credentials} from '../../data/api-data.js';
import {adminEmail, adminUsername, adminPassword, password} from '../../data/user.js';
import supertest from 'supertest';

describe('miscellaneous', function() {
Expand Down Expand Up @@ -106,7 +106,7 @@ describe('miscellaneous', function() {
const email = `${ username }@rocket.chat`;
request.post(api('users.create'))
.set(credentials)
.send({ email, name: username, username, password})
.send({email, name: username, username, password})
.end((err, res) => {
user = res.body.user;
done();
Expand All @@ -129,7 +129,7 @@ describe('miscellaneous', function() {
done();
});
});
it('should have return an array(result) when search by user and execute succesfully', (done) => {
it('should return an array(result) when search by user and execute succesfully', (done) => {
request.get(api('directory'))
.set(credentials)
.query({
Expand All @@ -151,7 +151,7 @@ describe('miscellaneous', function() {
})
.end(done);
});
it('should have return an array(result) when search by channel and execute succesfully', (done) => {
it('should return an array(result) when search by channel and execute succesfully', (done) => {
request.get(api('directory'))
.set(credentials)
.query({
Expand All @@ -172,5 +172,23 @@ describe('miscellaneous', function() {
})
.end(done);
});

it('should return an error when send invalid query', (done) => {
request.get(api('directory'))
.set(credentials)
.query({
query: JSON.stringify({
text: 'invalid channel',
type: 'invalid'
})
})
.expect('Content-Type', 'application/json')
.expect(400)
.expect((res) => {
expect(res.body).to.have.property('success', false);
})
.end(done);
});

});
});

0 comments on commit 57a4fc5

Please sign in to comment.