system_hook_spec.rb 3.09 KB
Newer Older
Dmitriy Zaporozhets's avatar
Dmitriy Zaporozhets committed
1 2 3 4
# == Schema Information
#
# Table name: web_hooks
#
Dmitriy Zaporozhets's avatar
Dmitriy Zaporozhets committed
5 6 7
#  id                    :integer          not null, primary key
#  url                   :string(255)
#  project_id            :integer
Dmitriy Zaporozhets's avatar
Dmitriy Zaporozhets committed
8 9
#  created_at            :datetime
#  updated_at            :datetime
Dmitriy Zaporozhets's avatar
Dmitriy Zaporozhets committed
10 11 12 13 14
#  type                  :string(255)      default("ProjectHook")
#  service_id            :integer
#  push_events           :boolean          default(TRUE), not null
#  issues_events         :boolean          default(FALSE), not null
#  merge_requests_events :boolean          default(FALSE), not null
Dmitriy Zaporozhets's avatar
Dmitriy Zaporozhets committed
15
#  tag_push_events       :boolean          default(FALSE)
Dmitriy Zaporozhets's avatar
Dmitriy Zaporozhets committed
16 17
#

Valeriy Sizov's avatar
Valeriy Sizov committed
18 19 20 21 22
require "spec_helper"

describe SystemHook do
  describe "execute" do
    before(:each) do
23
      @system_hook = create(:system_hook)
Valeriy Sizov's avatar
Valeriy Sizov committed
24 25 26 27
      WebMock.stub_request(:post, @system_hook.url)
    end

    it "project_create hook" do
28
      Projects::CreateService.new(create(:user), name: 'empty').execute
29
      expect(WebMock).to have_requested(:post, @system_hook.url).with(body: /project_create/).once
Valeriy Sizov's avatar
Valeriy Sizov committed
30
    end
31

Valeriy Sizov's avatar
Valeriy Sizov committed
32
    it "project_destroy hook" do
33 34 35
      user = create(:user)
      project = create(:empty_project, namespace: user.namespace)
      Projects::DestroyService.new(project, user, {}).execute
36
      expect(WebMock).to have_requested(:post, @system_hook.url).with(body: /project_destroy/).once
Valeriy Sizov's avatar
Valeriy Sizov committed
37 38 39
    end

    it "user_create hook" do
Dmitriy Zaporozhets's avatar
Dmitriy Zaporozhets committed
40
      create(:user)
41
      expect(WebMock).to have_requested(:post, @system_hook.url).with(body: /user_create/).once
Valeriy Sizov's avatar
Valeriy Sizov committed
42
    end
43

Valeriy Sizov's avatar
Valeriy Sizov committed
44
    it "user_destroy hook" do
45
      user = create(:user)
Dmitriy Zaporozhets's avatar
Dmitriy Zaporozhets committed
46
      user.destroy
47
      expect(WebMock).to have_requested(:post, @system_hook.url).with(body: /user_destroy/).once
Valeriy Sizov's avatar
Valeriy Sizov committed
48
    end
49

Valeriy Sizov's avatar
Valeriy Sizov committed
50
    it "project_create hook" do
51 52
      user = create(:user)
      project = create(:project)
Dmitriy Zaporozhets's avatar
Dmitriy Zaporozhets committed
53
      project.team << [user, :master]
54
      expect(WebMock).to have_requested(:post, @system_hook.url).with(body: /user_add_to_team/).once
Valeriy Sizov's avatar
Valeriy Sizov committed
55
    end
56

Valeriy Sizov's avatar
Valeriy Sizov committed
57
    it "project_destroy hook" do
58 59
      user = create(:user)
      project = create(:project)
60
      project.team << [user, :master]
61
      project.project_members.destroy_all
62
      expect(WebMock).to have_requested(:post, @system_hook.url).with(body: /user_remove_from_team/).once
Valeriy Sizov's avatar
Valeriy Sizov committed
63
    end
64 65 66

    it 'group create hook' do
      create(:group)
67
      expect(WebMock).to have_requested(:post, @system_hook.url).with(
68 69 70 71 72 73 74
        body: /group_create/
      ).once
    end

    it 'group destroy hook' do
      group = create(:group)
      group.destroy
75
      expect(WebMock).to have_requested(:post, @system_hook.url).with(
76 77 78 79 80 81 82 83
        body: /group_destroy/
      ).once
    end

    it 'group member create hook' do
      group = create(:group)
      user = create(:user)
      group.add_user(user, Gitlab::Access::MASTER)
84
      expect(WebMock).to have_requested(:post, @system_hook.url).with(
85 86 87 88 89 90 91 92 93
        body: /user_add_to_group/
      ).once
    end

    it 'group member destroy hook' do
      group = create(:group)
      user = create(:user)
      group.add_user(user, Gitlab::Access::MASTER)
      group.group_members.destroy_all
94
      expect(WebMock).to have_requested(:post, @system_hook.url).with(
95 96 97 98
        body: /user_remove_from_group/
      ).once
    end

Valeriy Sizov's avatar
Valeriy Sizov committed
99 100
  end
end