summaryrefslogtreecommitdiff
path: root/spec/requests/users/group_callouts_spec.rb
blob: a8680c3add4e53a8738d8d524702530bd3519582 (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
# frozen_string_literal: true

require 'spec_helper'

RSpec.describe 'Group callouts' do
  let_it_be(:user) { create(:user) }
  let_it_be(:group) { create(:group) }

  before do
    sign_in(user)
  end

  describe 'POST /-/users/group_callouts' do
    let(:params) { { feature_name: feature_name, group_id: group.id } }

    subject { post group_callouts_path, params: params, headers: { 'ACCEPT' => 'application/json' } }

    context 'with valid feature name and group' do
      let(:feature_name) { Users::GroupCallout.feature_names.each_key.first }

      context 'when callout entry does not exist' do
        it 'creates a callout entry with dismissed state' do
          expect { subject }.to change { Users::GroupCallout.count }.by(1)
        end

        it 'returns success' do
          subject

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

      context 'when callout entry already exists' do
        let!(:callout) do
          create(:group_callout,
                 feature_name: Users::GroupCallout.feature_names.each_key.first,
                 user: user,
                 group: group)
        end

        it 'returns success', :aggregate_failures do
          expect { subject }.not_to change { Users::GroupCallout.count }
          expect(response).to have_gitlab_http_status(:ok)
        end
      end
    end

    context 'with invalid feature name' do
      let(:feature_name) { 'bogus_feature_name' }

      it 'returns bad request' do
        subject

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