File: hook_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 (38 lines) | stat: -rw-r--r-- 1,255 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
# frozen_string_literal: true

require 'spec_helper'

RSpec.describe API::Entities::Hook, feature_category: :webhooks do
  let(:hook) { create(:project_hook) }
  let(:with_url_variables) { true }
  let(:with_custom_headers) { true }
  let(:entity) do
    described_class.new(hook, with_url_variables: with_url_variables, with_custom_headers: with_custom_headers)
  end

  subject(:json) { entity.as_json }

  it 'exposes correct attributes' do
    expect(json.keys).to contain_exactly(
      :id, :name, :description, :alert_status, :created_at, :disabled_until, :enable_ssl_verification, :tag_push_events,
      :merge_requests_events, :push_events, :repository_update_events, :url, :url_variables, :custom_webhook_template,
      :custom_headers, :branch_filter_strategy, :push_events_branch_filter
    )
  end

  context 'when `with_url_variables` is set to false' do
    let(:with_url_variables) { false }

    it 'does not expose `url_variables` field' do
      expect(json.keys).not_to include(:url_variables)
    end
  end

  context 'when `with_custom_headers` is set to false' do
    let(:with_custom_headers) { false }

    it 'does not expose `custom_headers` field' do
      expect(json.keys).not_to include(:custom_headers)
    end
  end
end