summaryrefslogtreecommitdiff
path: root/spec/lib/gitlab/github_import/hook_formatter_spec.rb
blob: 110ba428258eceb74d2c2ebbdc6cc9747a2444ef (plain)
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
require 'spec_helper'

describe Gitlab::GithubImport::HookFormatter, lib: true do
  describe '#id' do
    it 'returns raw id' do
      raw = double(id: 100000)
      formatter = described_class.new(raw)
      expect(formatter.id).to eq 100000
    end
  end

  describe '#name' do
    it 'returns raw id' do
      raw = double(name: 'web')
      formatter = described_class.new(raw)
      expect(formatter.name).to eq 'web'
    end
  end

  describe '#config' do
    it 'returns raw config.attrs' do
      raw = double(config: double(attrs: { url: 'http://something.com/webhook' }))
      formatter = described_class.new(raw)
      expect(formatter.config).to eq({ url: 'http://something.com/webhook' })
    end
  end

  describe '#valid?' do
    it 'returns true when events contains the wildcard event' do
      raw = double(events: ['*', 'commit_comment'], active: true)
      formatter = described_class.new(raw)
      expect(formatter.valid?).to eq true
    end

    it 'returns true when events contains the create event' do
      raw = double(events: ['create', 'commit_comment'], active: true)
      formatter = described_class.new(raw)
      expect(formatter.valid?).to eq true
    end

    it 'returns true when events contains delete event' do
      raw = double(events: ['delete', 'commit_comment'], active: true)
      formatter = described_class.new(raw)
      expect(formatter.valid?).to eq true
    end

    it 'returns true when events contains pull_request event' do
      raw = double(events: ['pull_request', 'commit_comment'], active: true)
      formatter = described_class.new(raw)
      expect(formatter.valid?).to eq true
    end

    it 'returns false when events does not contains branch related events' do
      raw = double(events: ['member', 'commit_comment'], active: true)
      formatter = described_class.new(raw)
      expect(formatter.valid?).to eq false
    end

    it 'returns false when hook is not active' do
      raw = double(events: ['pull_request', 'commit_comment'], active: false)
      formatter = described_class.new(raw)
      expect(formatter.valid?).to eq false
    end
  end
end