summaryrefslogtreecommitdiff
path: root/spec/features/projects/settings/integration_settings_spec.rb
blob: a59374b37eab7d5c1e00ba228db986ac78fcb00d (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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
require 'spec_helper'

feature 'Integration settings', feature: true do
  let(:project) { create(:empty_project) }
  let(:user) { create(:user) }
  let(:role) { :developer }
  let(:integrations_path) { namespace_project_settings_integrations_path(project.namespace, project) }

  background do
    gitlab_sign_in(user)
    project.team << [user, role]
  end

  context 'for developer' do
    given(:role) { :developer }

    scenario 'to be disallowed to view' do
      visit integrations_path

      expect(page.status_code).to eq(404)
    end
  end

  context 'for master' do
    given(:role) { :master }

    context 'Webhooks' do
      let(:hook) { create(:project_hook, :all_events_enabled, enable_ssl_verification: true, project: project) }
      let(:url) { generate(:url) }

      scenario 'show list of webhooks' do
        hook

        visit integrations_path

        expect(page.status_code).to eq(200)
        expect(page).to have_content(hook.url)
        expect(page).to have_content('SSL Verification: enabled')
        expect(page).to have_content('Push Events')
        expect(page).to have_content('Tag Push Events')
        expect(page).to have_content('Issues Events')
        expect(page).to have_content('Confidential Issues Events')
        expect(page).to have_content('Note Events')
        expect(page).to have_content('Merge Requests  Events')
        expect(page).to have_content('Pipeline Events')
        expect(page).to have_content('Wiki Page Events')
      end

      scenario 'create webhook' do
        visit integrations_path

        fill_in 'hook_url', with: url
        check 'Tag push events'
        check 'Enable SSL verification'
        check 'Job events'

        click_button 'Add webhook'

        expect(page).to have_content(url)
        expect(page).to have_content('SSL Verification: enabled')
        expect(page).to have_content('Push Events')
        expect(page).to have_content('Tag Push Events')
        expect(page).to have_content('Job events')
      end

      scenario 'edit existing webhook' do
        hook
        visit integrations_path

        click_link 'Edit'
        fill_in 'hook_url', with: url
        check 'Enable SSL verification'
        click_button 'Save changes'

        expect(page).to have_content 'SSL Verification: enabled'
        expect(page).to have_content(url)
      end

      scenario 'test existing webhook' do
        WebMock.stub_request(:post, hook.url)
        visit integrations_path

        click_link 'Test'

        expect(current_path).to eq(integrations_path)
      end

      context 'remove existing webhook' do
        scenario 'from webhooks list page' do
          hook
          visit integrations_path

          expect { click_link 'Remove' }.to change(ProjectHook, :count).by(-1)
        end

        scenario 'from webhook edit page' do
          hook
          visit integrations_path
          click_link 'Edit'

          expect { click_link 'Remove' }.to change(ProjectHook, :count).by(-1)
        end
      end
    end

    context 'Webhook logs' do
      let(:hook) { create(:project_hook, project: project) }
      let(:hook_log) { create(:web_hook_log, web_hook: hook, internal_error_message: 'some error') }

      scenario 'show list of hook logs' do
        hook_log
        visit edit_namespace_project_hook_path(project.namespace, project, hook)

        expect(page).to have_content('Recent Deliveries')
        expect(page).to have_content(hook_log.url)
      end

      scenario 'show hook log details' do
        hook_log
        visit edit_namespace_project_hook_path(project.namespace, project, hook)
        click_link 'View details'

        expect(page).to have_content("POST #{hook_log.url}")
        expect(page).to have_content(hook_log.internal_error_message)
        expect(page).to have_content('Resend Request')
      end

      scenario 'retry hook log' do
        WebMock.stub_request(:post, hook.url)

        hook_log
        visit edit_namespace_project_hook_path(project.namespace, project, hook)
        click_link 'View details'
        click_link 'Resend Request'

        expect(current_path).to eq(edit_namespace_project_hook_path(project.namespace, project, hook))
      end
    end
  end
end