diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2021-04-21 02:50:22 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2021-04-21 02:50:22 +0300 |
commit | 9dc93a4519d9d5d7be48ff274127136236a3adb3 (patch) | |
tree | 70467ae3692a0e35e5ea56bcb803eb512a10bedb /spec/requests/api/users_preferences_spec.rb | |
parent | 4b0f34b6d759d6299322b3a54453e930c6121ff0 (diff) |
Add latest changes from gitlab-org/gitlab@13-11-stable-eev13.11.0-rc43
Diffstat (limited to 'spec/requests/api/users_preferences_spec.rb')
-rw-r--r-- | spec/requests/api/users_preferences_spec.rb | 65 |
1 files changed, 65 insertions, 0 deletions
diff --git a/spec/requests/api/users_preferences_spec.rb b/spec/requests/api/users_preferences_spec.rb new file mode 100644 index 00000000000..db03786ed2a --- /dev/null +++ b/spec/requests/api/users_preferences_spec.rb @@ -0,0 +1,65 @@ +# frozen_string_literal: true + +require 'spec_helper' + +RSpec.describe API::Users do + let_it_be(:user) { create(:user) } + + describe 'PUT /user/preferences/' do + context "with correct attributes and a logged in user" do + it 'returns a success status and the value has been changed' do + put api("/user/preferences", user), params: { view_diffs_file_by_file: true } + + expect(response).to have_gitlab_http_status(:ok) + expect(json_response['view_diffs_file_by_file']).to eq(true) + expect(user.reload.view_diffs_file_by_file).to be_truthy + end + end + + context "missing a preference" do + it 'returns a bad request status' do + put api("/user/preferences", user), params: {} + + expect(response).to have_gitlab_http_status(:bad_request) + end + end + + context "without a logged in user" do + it 'returns an unauthorized status' do + put api("/user/preferences"), params: { view_diffs_file_by_file: true } + + expect(response).to have_gitlab_http_status(:unauthorized) + end + end + + context "with an unsupported preference" do + it 'returns a bad parameter' do + put api("/user/preferences", user), params: { jawn: true } + + expect(response).to have_gitlab_http_status(:bad_request) + end + end + + context "with an unsupported value" do + it 'returns a bad parameter' do + put api("/user/preferences", user), params: { view_diffs_file_by_file: 3 } + + expect(response).to have_gitlab_http_status(:bad_request) + end + end + + context "with an update service failure" do + it 'returns a bad request' do + bad_service = double("Failed Service", success?: false) + + allow_next_instance_of(::UserPreferences::UpdateService) do |instance| + allow(instance).to receive(:execute).and_return(bad_service) + end + + put api("/user/preferences", user), params: { view_diffs_file_by_file: true } + + expect(response).to have_gitlab_http_status(:bad_request) + end + end + end +end |