summaryrefslogtreecommitdiff
path: root/spec/requests/api/group_avatar_spec.rb
blob: be5cfbc234c7facdf66d0e0714ab2c9c1b7b8cef (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
# frozen_string_literal: true

require 'spec_helper'

RSpec.describe API::GroupAvatar do
  def avatar_path(group)
    "/groups/#{group.id}/avatar"
  end

  describe 'GET /groups/:id/avatar' do
    context 'when the group is public' do
      it 'retrieves the avatar successfully' do
        group = create(:group, :public, :with_avatar)

        get api(avatar_path(group))

        expect(response).to have_gitlab_http_status(:ok)
      end

      context 'when the group does not have avatar' do
        it 'returns :not_found' do
          group = create(:group, :public)

          get api(avatar_path(group))

          expect(response).to have_gitlab_http_status(:not_found)
        end
      end
    end

    context 'when the group is private' do
      let(:group) { create(:group, :private, :with_avatar) }

      context 'when the user is not authenticated' do
        it 'returns :not_found' do
          get api(avatar_path(group))

          expect(response).to have_gitlab_http_status(:not_found)
        end
      end

      context 'when the the group user is authenticated' do
        context 'and have access to the group' do
          it 'retrieves the avatar successfully' do
            owner = create(:user)
            group.add_owner(owner)

            get api(avatar_path(group), owner)

            expect(response).to have_gitlab_http_status(:ok)
          end
        end

        context 'and does not have access to the group' do
          it 'returns :not_found' do
            get api(avatar_path(group), create(:user))

            expect(response).to have_gitlab_http_status(:not_found)
          end
        end
      end
    end
  end
end