diff options
author | Bob Van Landuyt <bob@vanlanduyt.co> | 2018-07-13 18:52:31 +0300 |
---|---|---|
committer | Bob Van Landuyt <bob@vanlanduyt.co> | 2018-07-30 16:01:26 +0300 |
commit | b4c4b48a8c0258ff266c523488aa169a1b5ea0f3 (patch) | |
tree | 7b2c5a6b1f3bc7e672cb3e64600e6bd2403d8748 /spec/services | |
parent | 812bfb158b70b09cfd438379a4b9446aa85b52ec (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/services')
-rw-r--r-- | spec/services/users/set_status_service_spec.rb | 58 | ||||
-rw-r--r-- | spec/services/users/update_service_spec.rb | 21 |
2 files changed, 79 insertions, 0 deletions
diff --git a/spec/services/users/set_status_service_spec.rb b/spec/services/users/set_status_service_spec.rb new file mode 100644 index 00000000000..8a8458ab9de --- /dev/null +++ b/spec/services/users/set_status_service_spec.rb @@ -0,0 +1,58 @@ +# 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 diff --git a/spec/services/users/update_service_spec.rb b/spec/services/users/update_service_spec.rb index a4b7fe4674f..529c8485202 100644 --- a/spec/services/users/update_service_spec.rb +++ b/spec/services/users/update_service_spec.rb @@ -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 |