Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBob Van Landuyt <bob@vanlanduyt.co>2018-07-13 18:52:31 +0300
committerBob Van Landuyt <bob@vanlanduyt.co>2018-07-30 16:01:26 +0300
commitb4c4b48a8c0258ff266c523488aa169a1b5ea0f3 (patch)
tree7b2c5a6b1f3bc7e672cb3e64600e6bd2403d8748 /spec/requests
parent812bfb158b70b09cfd438379a4b9446aa85b52ec (diff)
Allow users to set a status
This can be done trough the API for the current user, or on the profile page.
Diffstat (limited to 'spec/requests')
-rw-r--r--spec/requests/api/users_spec.rb62
1 files changed, 62 insertions, 0 deletions
diff --git a/spec/requests/api/users_spec.rb b/spec/requests/api/users_spec.rb
index 6a051f865aa..da503897760 100644
--- a/spec/requests/api/users_spec.rb
+++ b/spec/requests/api/users_spec.rb
@@ -13,6 +13,26 @@ describe API::Users do
let(:not_existing_pat_id) { (PersonalAccessToken.maximum('id') || 0 ) + 10 }
let(:private_user) { create(:user, private_profile: true) }
+ shared_examples 'rendering user status' do
+ it 'returns the status if there was one' do
+ create(:user_status, user: user)
+
+ get api(path, user)
+
+ expect(response).to have_gitlab_http_status(:success)
+ expect(json_response['message']).to be_present
+ expect(json_response['emoji']).to be_present
+ end
+
+ it 'returns an empty response if there was no status' do
+ get api(path, user)
+
+ expect(response).to have_gitlab_http_status(:success)
+ expect(json_response['message']).to be_nil
+ expect(json_response['emoji']).to be_nil
+ end
+ end
+
describe 'GET /users' do
context "when unauthenticated" do
it "returns authorization error when the `username` parameter is not passed" do
@@ -310,6 +330,20 @@ describe API::Users do
end
end
+ describe 'GET /users/:id_or_username/status' do
+ context 'when finding the user by id' do
+ it_behaves_like 'rendering user status' do
+ let(:path) { "/users/#{user.id}/status" }
+ end
+ end
+
+ context 'when finding the user by username' do
+ it_behaves_like 'rendering user status' do
+ let(:path) { "/users/#{user.username}/status" }
+ end
+ end
+ end
+
describe "POST /users" do
before do
admin
@@ -1774,6 +1808,34 @@ describe API::Users do
end
end
+ describe 'GET /user/status' do
+ let(:path) { '/user/status' }
+ it_behaves_like 'rendering user status'
+ end
+
+ describe 'PUT /user/status' do
+ it 'saves the status' do
+ put api('/user/status', user), { emoji: 'smirk', message: 'hello world' }
+
+ expect(response).to have_gitlab_http_status(:success)
+ expect(json_response['emoji']).to eq('smirk')
+ end
+
+ it 'renders errors when the status was invalid' do
+ put api('/user/status', user), { emoji: 'does not exist', message: 'hello world' }
+
+ expect(response).to have_gitlab_http_status(400)
+ expect(json_response['message']['emoji']).to be_present
+ end
+
+ it 'deletes the status when passing empty values' do
+ put api('/user/status', user)
+
+ expect(response).to have_gitlab_http_status(:success)
+ expect(user.reload.status).to be_nil
+ end
+ end
+
describe 'GET /users/:user_id/impersonation_tokens' do
let!(:active_personal_access_token) { create(:personal_access_token, user: user) }
let!(:revoked_personal_access_token) { create(:personal_access_token, :revoked, user: user) }