-
Notifications
You must be signed in to change notification settings - Fork 10.1k
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 endpoint /directory
#10442
Changes from 2 commits
5476bc2
b29bc8d
7535f24
57a4fc5
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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} 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() { | ||
|
@@ -12,7 +12,7 @@ describe('miscellaneous', function() { | |
before(done => getCredentials(done)); | ||
|
||
describe('API default', () => { | ||
// Required by mobile apps | ||
// Required by mobile apps | ||
it('/info', (done) => { | ||
request.get('/api/info') | ||
.expect('Content-Type', 'application/json') | ||
|
@@ -98,4 +98,93 @@ describe('miscellaneous', function() { | |
}); | ||
}); | ||
|
||
describe('/directory', () => { | ||
let user; | ||
let testChannel; | ||
before((done) => { | ||
const username = `user.test.${ Date.now() }`; | ||
const email = `${ username }@rocket.chat`; | ||
request.post(api('users.create')) | ||
.set(credentials) | ||
.send({ email, name: username, username, password}) | ||
.end((err, res) => { | ||
user = res.body.user; | ||
done(); | ||
}); | ||
}); | ||
after(done => { | ||
request.post(api('users.delete')).set(credentials).send({ | ||
userId: user._id | ||
}).end(done); | ||
user = undefined; | ||
}); | ||
it('create an channel', (done) => { | ||
request.post(api('channels.create')) | ||
.set(credentials) | ||
.send({ | ||
name: `channel.test.${ Date.now() }` | ||
}) | ||
.end((err, res) => { | ||
testChannel = res.body.channel; | ||
done(); | ||
}); | ||
}); | ||
it('should have return an array(result) when search by user and execute succesfully', (done) => { | ||
request.get(api('directory')) | ||
.set(credentials) | ||
.query({ | ||
query: JSON.stringify({ | ||
text: user.username, | ||
type: 'users' | ||
}) | ||
}) | ||
.expect('Content-Type', 'application/json') | ||
.expect(200) | ||
.expect((res) => { | ||
expect(res.body).to.have.property('success', true); | ||
expect(res.body).to.have.property('result').and.to.be.an('array'); | ||
expect(res.body.result[0]).to.have.property('_id'); | ||
expect(res.body.result[0]).to.have.property('createdAt'); | ||
expect(res.body.result[0]).to.have.property('username'); | ||
expect(res.body.result[0]).to.have.property('emails').and.to.be.an('array'); | ||
expect(res.body.result[0]).to.have.property('name'); | ||
}) | ||
.end(done); | ||
}); | ||
it('should have return an array(result) when search by channel and execute succesfully', (done) => { | ||
request.get(api('directory')) | ||
.set(credentials) | ||
.query({ | ||
query: JSON.stringify({ | ||
text: testChannel.name, | ||
type: 'channels' | ||
}) | ||
}) | ||
.expect('Content-Type', 'application/json') | ||
.expect(200) | ||
.expect((res) => { | ||
expect(res.body).to.have.property('success', true); | ||
expect(res.body).to.have.property('result').and.to.be.an('array'); | ||
expect(res.body.result[0]).to.have.property('_id'); | ||
expect(res.body.result[0]).to.have.property('name'); | ||
expect(res.body.result[0]).to.have.property('usernames').and.to.be.an('array'); | ||
expect(res.body.result[0]).to.have.property('ts'); | ||
}) | ||
.end(done); | ||
}); | ||
}); | ||
|
||
describe('/settings.oauth', () => { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Shouldn't this be moved to the settings one and not the miscellaneous one? 🤔 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. oops.. looks it's duplicated of this one. @MarcosSpessatto can you please remove this test from here? |
||
it('should have return list of available oauth services when user is logged', (done) => { | ||
request.get(api('settings.oauth')) | ||
.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('services').and.to.be.an('array'); | ||
}) | ||
.end(done); | ||
}); | ||
}); | ||
}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think as a good practice, the unexpected condition should be treated specially and not the successful one.
so I will ask you to change this here, so the
if
will trigger the failure.