Skip to content

Commit

Permalink
Add Rest endpoint to get username suggestion (#10702)
Browse files Browse the repository at this point in the history
  • Loading branch information
MarcosSpessatto authored and rodrigok committed May 18, 2018
1 parent e0f7684 commit 1e55207
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 0 deletions.
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 @@ -416,3 +416,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);
});

});
});

0 comments on commit 1e55207

Please sign in to comment.