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] Add REST API endpoint users.getUsernameSuggestion to get username suggestion #10702

Merged
merged 1 commit into from
May 18, 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
8 changes: 8 additions & 0 deletions packages/rocketchat-api/server/v1/users.js
Original file line number Diff line number Diff line change
Expand Up @@ -409,3 +409,11 @@ RocketChat.API.v1.addRoute('users.forgotPassword', { authRequired: false }, {
return RocketChat.API.v1.failure('User not found');
}
});

RocketChat.API.v1.addRoute('users.getUsernameSuggestion', { authRequired: true }, {
get() {
const result = Meteor.runAsUser(this.userId, () => Meteor.call('getUsernameSuggestion'));

return RocketChat.API.v1.success({ result });
}
});
50 changes: 50 additions & 0 deletions tests/end-to-end/api/01-users.js
Original file line number Diff line number Diff line change
Expand Up @@ -617,4 +617,54 @@ describe('[Users]', function() {
.end(done);
});
});

describe('[/users.getUsernameSuggestion]', () => {
const testUsername = `test${ +new Date() }`;
let targetUser;
let userCredentials;
it('register a new user...', (done) => {
request.post(api('users.register'))
.set(credentials)
.send({
email: `${ testUsername }.@teste.com`,
username: `${ testUsername }test`,
name: testUsername,
pass: password
})
.expect('Content-Type', 'application/json')
.expect(200)
.expect((res) => {
targetUser = res.body.user;
})
.end(done);
});
it('Login...', (done) => {
request.post(api('login'))
.send({
user: targetUser.username,
password
})
.expect('Content-Type', 'application/json')
.expect(200)
.expect((res) => {
userCredentials = {};
userCredentials['X-Auth-Token'] = res.body.data.authToken;
userCredentials['X-User-Id'] = res.body.data.userId;
})
.end(done);
});

it('should return an username suggestion', (done) => {
request.get(api('users.getUsernameSuggestion'))
.set(userCredentials)
.expect('Content-Type', 'application/json')
.expect(200)
.expect((res) => {
expect(res.body).to.have.property('success', true);
expect(res.body.result).to.be.equal(testUsername);
})
.end(done);
});

});
});