debian-mirror-gitlab/spec/requests/api/users_preferences_spec.rb

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

74 lines
2.2 KiB
Ruby
Raw Normal View History

2021-04-29 21:17:54 +05:30
# frozen_string_literal: true
require 'spec_helper'
2023-04-23 21:23:45 +05:30
RSpec.describe API::Users, feature_category: :user_profile do
2021-04-29 21:17:54 +05:30
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
2021-09-04 01:27:46 +05:30
put api("/user/preferences", user), params: {
view_diffs_file_by_file: true,
show_whitespace_in_diffs: true
}
2021-04-29 21:17:54 +05:30
expect(response).to have_gitlab_http_status(:ok)
expect(json_response['view_diffs_file_by_file']).to eq(true)
2021-09-04 01:27:46 +05:30
expect(json_response['show_whitespace_in_diffs']).to eq(true)
user.reload
expect(user.view_diffs_file_by_file).to be_truthy
expect(user.show_whitespace_in_diffs).to be_truthy
2021-04-29 21:17:54 +05:30
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