admin_hooks_spec.rb 2.05 KB
Newer Older
Valeriy Sizov's avatar
Valeriy Sizov committed
1 2
require 'spec_helper'

3
describe 'Admin::Hooks' do
Valeriy Sizov's avatar
Valeriy Sizov committed
4
  before do
5
    @project = create(:project)
6
    sign_in(create(:admin))
Valeriy Sizov's avatar
Valeriy Sizov committed
7

8
    @system_hook = create(:system_hook)
Valeriy Sizov's avatar
Valeriy Sizov committed
9 10
  end

11 12
  describe 'GET /admin/hooks' do
    it 'is ok' do
Valeriy Sizov's avatar
Valeriy Sizov committed
13
      visit admin_root_path
Dmitriy Zaporozhets's avatar
Dmitriy Zaporozhets committed
14

15 16
      page.within '.layout-nav' do
        click_on 'Hooks'
Valeriy Sizov's avatar
Valeriy Sizov committed
17
      end
Dmitriy Zaporozhets's avatar
Dmitriy Zaporozhets committed
18

19
      expect(current_path).to eq(admin_hooks_path)
Valeriy Sizov's avatar
Valeriy Sizov committed
20 21
    end

22
    it 'has hooks list' do
Valeriy Sizov's avatar
Valeriy Sizov committed
23
      visit admin_hooks_path
24
      expect(page).to have_content(@system_hook.url)
Valeriy Sizov's avatar
Valeriy Sizov committed
25 26 27
    end
  end

28
  describe 'New Hook' do
29
    let(:url) { generate(:url) }
30 31

    it 'adds new hook' do
Valeriy Sizov's avatar
Valeriy Sizov committed
32
      visit admin_hooks_path
33 34
      fill_in 'hook_url', with: url
      check 'Enable SSL verification'
Valeriy Sizov's avatar
Valeriy Sizov committed
35

36
      expect { click_button 'Add system hook' }.to change(SystemHook, :count).by(1)
37
      expect(page).to have_content 'SSL Verification: enabled'
38
      expect(current_path).to eq(admin_hooks_path)
39
      expect(page).to have_content(url)
Valeriy Sizov's avatar
Valeriy Sizov committed
40 41 42
    end
  end

43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60
  describe 'Update existing hook' do
    let(:new_url) { generate(:url) }

    it 'updates existing hook' do
      visit admin_hooks_path

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

      expect(page).to have_content 'SSL Verification: enabled'
      expect(current_path).to eq(admin_hooks_path)
      expect(page).to have_content(new_url)
    end
  end

  describe 'Remove existing hook' do
Alexander Randa's avatar
Alexander Randa committed
61 62 63 64 65 66
    context 'removes existing hook' do
      it 'from hooks list page' do
        visit admin_hooks_path

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

Alexander Randa's avatar
Alexander Randa committed
68 69 70 71 72 73
      it 'from hook edit page' do
        visit admin_hooks_path
        click_link 'Edit'

        expect { click_link 'Remove' }.to change(SystemHook, :count).by(-1)
      end
74 75 76
    end
  end

77
  describe 'Test', js: true do
Valeriy Sizov's avatar
Valeriy Sizov committed
78 79 80
    before do
      WebMock.stub_request(:post, @system_hook.url)
      visit admin_hooks_path
81 82 83

      find('.hook-test-button.dropdown').click
      click_link 'Push events'
Valeriy Sizov's avatar
Valeriy Sizov committed
84 85
    end

86
    it { expect(current_path).to eq(admin_hooks_path) }
Valeriy Sizov's avatar
Valeriy Sizov committed
87 88
  end
end