File: project_hooks_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 (81 lines) | stat: -rw-r--r-- 2,084 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
# frozen_string_literal: true

require 'spec_helper'

RSpec.describe API::ProjectHooks, 'ProjectHooks', feature_category: :webhooks do
  let_it_be(:user) { create(:user) }
  let_it_be(:user3) { create(:user) }
  let_it_be_with_reload(:project) do
    create(:project, :repository, creator_id: user.id, namespace: user.namespace, maintainers: user, developers: user3)
  end

  let_it_be_with_refind(:hook) do
    create(
      :project_hook,
      :all_events_enabled,
      project: project,
      url: 'http://example.com',
      enable_ssl_verification: true,
      push_events_branch_filter: 'master'
    )
  end

  it_behaves_like 'web-hook API endpoints', '/projects/:id' do
    let(:unauthorized_user) { user3 }

    def scope
      project.hooks
    end

    def collection_uri
      "/projects/#{project.id}/hooks"
    end

    def match_collection_schema
      match_response_schema('public_api/v4/project_hooks')
    end

    def hook_uri(hook_id = hook.id)
      "/projects/#{project.id}/hooks/#{hook_id}"
    end

    def match_hook_schema
      match_response_schema('public_api/v4/project_hook')
    end

    def event_names
      %i[
        push_events
        tag_push_events
        merge_requests_events
        issues_events
        confidential_issues_events
        note_events
        confidential_note_events
        pipeline_events
        wiki_page_events
        job_events
        deployment_events
        feature_flag_events
        releases_events
        emoji_events
        resource_access_token_events
      ]
    end

    let(:default_values) do
      { push_events: true, confidential_note_events: nil }
    end

    it_behaves_like 'test web-hook endpoint'
    it_behaves_like 'POST webhook API endpoints with a branch filter', '/projects/:id'
    it_behaves_like 'PUT webhook API endpoints with a branch filter', '/projects/:id'
    it_behaves_like 'resend web-hook event endpoint' do
      let(:unauthorized_user) { user3 }
    end

    it_behaves_like 'get web-hook event endpoint' do
      let(:unauthorized_user) { user3 }
    end
  end
end