From 57a4fc5233614c85bd161ce9a879c672bf285aa9 Mon Sep 17 00:00:00 2001 From: Marcos Vinicius Spessatto Defendi Date: Thu, 19 Apr 2018 10:28:39 -0300 Subject: [PATCH] Correct logic, and add one more test case in REST directory endpoint --- packages/rocketchat-api/server/v1/misc.js | 6 ++--- tests/end-to-end/api/00-miscellaneous.js | 28 +++++++++++++++++++---- 2 files changed, 26 insertions(+), 8 deletions(-) diff --git a/packages/rocketchat-api/server/v1/misc.js b/packages/rocketchat-api/server/v1/misc.js index c3178c70cc15..72e2cd4483bb 100644 --- a/packages/rocketchat-api/server/v1/misc.js +++ b/packages/rocketchat-api/server/v1/misc.js @@ -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 }); } }); diff --git a/tests/end-to-end/api/00-miscellaneous.js b/tests/end-to-end/api/00-miscellaneous.js index a02931f5c33a..000bb6c10b08 100644 --- a/tests/end-to-end/api/00-miscellaneous.js +++ b/tests/end-to-end/api/00-miscellaneous.js @@ -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() { @@ -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(); @@ -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({ @@ -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({ @@ -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); + }); + }); });