File: user_interacts_with_deploy_keys_spec.rb

package info (click to toggle)
gitlab 17.6.5-19
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 629,368 kB
  • sloc: ruby: 1,915,304; javascript: 557,307; sql: 60,639; xml: 6,509; sh: 4,567; makefile: 1,239; python: 406
file content (155 lines) | stat: -rw-r--r-- 4,114 bytes parent folder | download
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
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
# frozen_string_literal: true

require 'spec_helper'

RSpec.describe "User interacts with deploy keys", :js, feature_category: :continuous_delivery do
  let(:project) { create(:project, :repository) }
  let(:user) { project.first_owner }

  before do
    sign_in(user)
  end

  shared_examples 'attaches a key' do
    it 'attaches key' do
      visit(project_deploy_keys_path(project))

      page.within('.deploy-keys') do
        click_link(scope)

        click_button('Enable')

        expect(page).not_to have_selector('.gl-spinner')
        expect(page).to have_current_path(project_settings_repository_path(project), ignore_query: true)

        click_link('Enabled deploy keys')

        expect(page).to have_content(deploy_key.title)
      end
    end
  end

  context 'viewing deploy keys' do
    let(:deploy_key) { create(:deploy_key) }

    context 'when project has keys' do
      before do
        create(:deploy_keys_project, project: project, deploy_key: deploy_key)
      end

      it 'shows deploy keys' do
        visit(project_deploy_keys_path(project))

        page.within('.deploy-keys') do
          expect(page).to have_content(deploy_key.title)
        end
      end
    end

    context 'when the project has many deploy keys' do
      before do
        create(:deploy_keys_project, project: project, deploy_key: deploy_key)
        create_list(:deploy_keys_project, 5, project: project)
      end

      it 'shows pagination' do
        visit(project_deploy_keys_path(project))

        page.within('.deploy-keys') do
          expect(page).to have_link('Next')
          expect(page).to have_link('2')
        end
      end
    end

    context 'when another project has keys' do
      let(:another_project) { create(:project) }

      before do
        create(:deploy_keys_project, project: another_project, deploy_key: deploy_key)

        another_project.add_maintainer(user)
      end

      it 'shows deploy keys' do
        visit(project_deploy_keys_path(project))

        page.within('.deploy-keys') do
          click_link('Privately accessible deploy keys')

          expect(page).to have_content(deploy_key.title)
        end
      end
    end

    context 'when there are public deploy keys' do
      let!(:deploy_key) { create(:deploy_key, public: true) }

      it 'shows public deploy keys' do
        visit(project_deploy_keys_path(project))

        page.within('.deploy-keys') do
          click_link('Publicly accessible deploy keys')

          expect(page).to have_content(deploy_key.title)
        end
      end
    end
  end

  context 'adding deploy keys' do
    before do
      visit(project_deploy_keys_path(project))
    end

    it 'adds new key' do
      deploy_key_title = attributes_for(:key)[:title]
      deploy_key_body  = attributes_for(:key)[:key]

      click_button('Add new key')
      fill_in('deploy_key_title', with: deploy_key_title)
      fill_in('deploy_key_key',   with: deploy_key_body)

      click_button('Add key')

      expect(page).to have_current_path(project_settings_repository_path(project), ignore_query: true)

      page.within('.deploy-keys') do
        expect(page).to have_content(deploy_key_title)
      end
    end

    it 'click on cancel hides the form' do
      click_button('Add new key')

      expect(page).to have_css('[data-testid="crud-form"]')

      click_button('Cancel')

      expect(page).not_to have_css('[data-testid="crud-form"]')
    end
  end

  context 'attaching existing keys' do
    context 'from another project' do
      let(:another_project) { create(:project) }
      let(:deploy_key) { create(:deploy_key) }
      let(:scope) { 'Privately accessible deploy keys' }

      before do
        create(:deploy_keys_project, project: another_project, deploy_key: deploy_key)

        another_project.add_maintainer(user)
      end

      it_behaves_like 'attaches a key'
    end

    context 'when keys are public' do
      let!(:deploy_key) { create(:deploy_key, public: true) }
      let(:scope) { 'Publicly accessible deploy keys' }

      it_behaves_like 'attaches a key'
    end
  end
end