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

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

110 lines
3.7 KiB
Ruby
Raw Permalink Normal View History

2019-12-26 22:10:19 +05:30
# frozen_string_literal: true
2018-11-08 19:23:39 +05:30
require 'spec_helper'
2023-04-23 21:23:45 +05:30
RSpec.describe API::Avatar, feature_category: :user_profile do
2018-11-08 19:23:39 +05:30
let(:gravatar_service) { double('GravatarService') }
describe 'GET /avatar' do
context 'avatar uploaded to GitLab' do
context 'user with matching public email address' do
let(:user) { create(:user, :with_avatar, email: 'public@example.com', public_email: 'public@example.com') }
before do
user
end
it 'returns the avatar url' do
2019-02-15 15:39:39 +05:30
get api('/avatar'), params: { email: 'public@example.com' }
2018-11-08 19:23:39 +05:30
2020-04-22 19:07:51 +05:30
expect(response).to have_gitlab_http_status(:ok)
2018-11-08 19:23:39 +05:30
expect(json_response['avatar_url']).to eql("#{::Settings.gitlab.base_url}#{user.avatar.local_url}")
2023-05-27 22:25:52 +05:30
is_expected.to have_request_urgency(:medium)
2018-11-08 19:23:39 +05:30
end
end
context 'no user with matching public email address' do
before do
expect(GravatarService).to receive(:new).and_return(gravatar_service)
expect(gravatar_service).to(
receive(:execute)
.with('private@example.com', nil, 2, { username: nil })
.and_return('https://gravatar'))
end
it 'returns the avatar url from Gravatar' do
2019-02-15 15:39:39 +05:30
get api('/avatar'), params: { email: 'private@example.com' }
2018-11-08 19:23:39 +05:30
2020-04-22 19:07:51 +05:30
expect(response).to have_gitlab_http_status(:ok)
2018-11-08 19:23:39 +05:30
expect(json_response['avatar_url']).to eq('https://gravatar')
end
end
end
context 'avatar uploaded to Gravatar' do
context 'user with matching public email address' do
let(:user) { create(:user, email: 'public@example.com', public_email: 'public@example.com') }
before do
user
expect(GravatarService).to receive(:new).and_return(gravatar_service)
expect(gravatar_service).to(
receive(:execute)
.with('public@example.com', nil, 2, { username: user.username })
.and_return('https://gravatar'))
end
it 'returns the avatar url from Gravatar' do
2019-02-15 15:39:39 +05:30
get api('/avatar'), params: { email: 'public@example.com' }
2018-11-08 19:23:39 +05:30
2020-04-22 19:07:51 +05:30
expect(response).to have_gitlab_http_status(:ok)
2018-11-08 19:23:39 +05:30
expect(json_response['avatar_url']).to eq('https://gravatar')
end
end
context 'no user with matching public email address' do
before do
expect(GravatarService).to receive(:new).and_return(gravatar_service)
expect(gravatar_service).to(
receive(:execute)
2019-03-02 22:35:43 +05:30
.with('private@example.com', nil, 2, { username: nil })
2018-11-08 19:23:39 +05:30
.and_return('https://gravatar'))
end
it 'returns the avatar url from Gravatar' do
2019-02-15 15:39:39 +05:30
get api('/avatar'), params: { email: 'private@example.com' }
2018-11-08 19:23:39 +05:30
2020-04-22 19:07:51 +05:30
expect(response).to have_gitlab_http_status(:ok)
2018-11-08 19:23:39 +05:30
expect(json_response['avatar_url']).to eq('https://gravatar')
end
end
context 'public visibility level restricted' do
let(:user) { create(:user, :with_avatar, email: 'public@example.com', public_email: 'public@example.com') }
before do
user
stub_application_setting(restricted_visibility_levels: [Gitlab::VisibilityLevel::PUBLIC])
end
context 'when authenticated' do
it 'returns the avatar url' do
2019-02-15 15:39:39 +05:30
get api('/avatar', user), params: { email: 'public@example.com' }
2018-11-08 19:23:39 +05:30
2020-04-22 19:07:51 +05:30
expect(response).to have_gitlab_http_status(:ok)
2018-11-08 19:23:39 +05:30
expect(json_response['avatar_url']).to eql("#{::Settings.gitlab.base_url}#{user.avatar.local_url}")
end
end
context 'when unauthenticated' do
it_behaves_like '403 response' do
2019-02-15 15:39:39 +05:30
let(:request) { get api('/avatar'), params: { email: 'public@example.com' } }
2018-11-08 19:23:39 +05:30
end
end
end
end
end
end