Skip to content
Snippets Groups Projects
Commit 83a0db0c authored by Rémy Coutable's avatar Rémy Coutable
Browse files

Merge branch 'bvl-user-status-message-35463' into 'master'

Allow users to set a status

Closes #35463

See merge request gitlab-org/gitlab-ce!20614
parents ea6fc714 12095251
No related branches found
No related tags found
1 merge request!10495Merge Requests - Assignee
Loading
Loading
@@ -13,6 +13,27 @@ 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['message_html']).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
Loading
Loading
@@ -310,6 +331,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
Loading
Loading
@@ -1774,6 +1809,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) }
Loading
Loading
# frozen_string_literal: true
require 'spec_helper'
describe Users::SetStatusService do
let(:current_user) { create(:user) }
subject(:service) { described_class.new(current_user, params) }
describe '#execute' do
context 'when when params are set' do
let(:params) { { emoji: 'taurus', message: 'a random status' } }
it 'creates a status' do
service.execute
expect(current_user.status.emoji).to eq('taurus')
expect(current_user.status.message).to eq('a random status')
end
it 'updates a status if it already existed' do
create(:user_status, user: current_user)
expect { service.execute }.not_to change { UserStatus.count }
expect(current_user.status.message).to eq('a random status')
end
context 'for another user' do
let(:target_user) { create(:user) }
let(:params) do
{ emoji: 'taurus', message: 'a random status', user: target_user }
end
context 'the current user is admin' do
let(:current_user) { create(:admin) }
it 'changes the status when the current user is allowed to do that' do
expect { service.execute }.to change { target_user.status }
end
end
it 'does not update the status if the current user is not allowed' do
expect { service.execute }.not_to change { target_user.status }
end
end
end
context 'without params' do
let(:params) { {} }
it 'deletes the status' do
status = create(:user_status, user: current_user)
expect { service.execute }
.to change { current_user.reload.status }.from(status).to(nil)
end
end
end
end
Loading
Loading
@@ -30,6 +30,27 @@ describe Users::UpdateService do
expect(result[:message]).to eq('Username has already been taken')
end
 
it 'updates the status if status params were given' do
update_user(user, status: { message: "On a call" })
expect(user.status.message).to eq("On a call")
end
it 'does not delete the status if no status param was passed' do
create(:user_status, user: user, message: 'Busy!')
update_user(user, name: 'New name')
expect(user.status.message).to eq('Busy!')
end
it 'includes status error messages' do
result = update_user(user, status: { emoji: "Moo!" })
expect(result[:status]).to eq(:error)
expect(result[:message]).to eq("Emoji is not included in the list")
end
def update_user(user, opts)
described_class.new(user, opts.merge(user: user)).execute
end
Loading
Loading
# frozen_string_literal: true
RSpec::Matchers.define :show_user_status do |status|
match do |page|
expect(page).to have_selector(".user-status-emoji[title='#{status.message}']")
# The same user status might be displayed multiple times on the page
emoji_span = page.first(".user-status-emoji[title='#{status.message}']")
page.within(emoji_span) do
expect(page).to have_emoji(status.emoji)
end
end
end
# frozen_string_literal: true
shared_examples 'showing user status' do
let!(:status) { create(:user_status, user: user_with_status, emoji: 'smirk', message: 'Authoring this object') }
it 'shows the status' do
subject
expect(page).to show_user_status(status)
end
end
Loading
Loading
@@ -17,6 +17,13 @@ describe 'projects/merge_requests/show.html.haml' do
author: user)
end
 
def preload_view_requirements
# This will load the status fields of the author of the note and merge request
# to avoid queries in when rendering the view being tested.
closed_merge_request.author.status
note.author.status
end
before do
assign(:project, project)
assign(:merge_request, closed_merge_request)
Loading
Loading
@@ -26,6 +33,8 @@ describe 'projects/merge_requests/show.html.haml' do
assign(:notes, [])
assign(:pipelines, Ci::Pipeline.none)
 
preload_view_requirements
allow(view).to receive_messages(current_user: user,
can?: true,
current_application_settings: Gitlab::CurrentSettings.current_application_settings)
Loading
Loading
@@ -42,6 +51,7 @@ describe 'projects/merge_requests/show.html.haml' do
it 'does not show the "Reopen" button when the source project does not exist' do
unlink_project.execute
closed_merge_request.reload
preload_view_requirements
 
render
 
Loading
Loading
@@ -56,6 +66,7 @@ describe 'projects/merge_requests/show.html.haml' do
forked_project.destroy
# Reload merge request so MergeRequest#source_project turns to `nil`
closed_merge_request.reload
preload_view_requirements
 
render
 
Loading
Loading
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment