File: hooks_spec.rb

package info (click to toggle)
ruby-octokit 10.0.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 24,092 kB
  • sloc: ruby: 13,339; sh: 99; makefile: 7; javascript: 3
file content (172 lines) | stat: -rw-r--r-- 6,243 bytes parent folder | download | duplicates (2)
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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
# frozen_string_literal: true

describe Octokit::Client::Hooks do
  before do
    Octokit.reset!
    @client = oauth_client
  end

  context 'with repository' do
    before(:each) do
      @repo = @client.create_repository('an-repo')
    end

    after(:each) do
      @client.delete_repository(@repo.full_name)
    rescue Octokit::NotFound
    end

    describe '.hooks', :vcr do
      it "returns a repository's hooks" do
        hooks = @client.hooks(@repo.full_name)
        expect(hooks).to be_kind_of Array
        assert_requested :get, github_url("/repos/#{@repo.full_name}/hooks")
      end
    end

    context 'with hook' do
      before(:each) do
        @hook = @client.create_hook(@repo.full_name, 'railsbp', { railsbp_url: 'http://railsbp.com', token: 'xAAQZtJhYHGagsed1kYR' })
      end

      after(:each) do
        @client.remove_hook(@repo.full_name, @hook.id)
      end

      describe '.create_hook', :vcr do
        it 'creates a hook' do
          assert_requested :post, github_url("/repos/#{@repo.full_name}/hooks")
        end
      end # .create_hook

      describe '.hook', :vcr do
        it "returns a repository's single hook" do
          @client.hook(@repo.full_name, @hook.id)
          assert_requested :get, github_url("/repos/#{@repo.full_name}/hooks/#{@hook.id}")
        end
      end # .hook

      describe '.edit_hook', :vcr do
        it 'edits a hook' do
          @client.edit_hook(@repo.full_name, @hook.id, 'railsbp', { railsbp_url: 'https://railsbp.com', token: 'xAAQZtJhYHGagsed1kYR' })
          assert_requested :patch, github_url("/repos/#{@repo.full_name}/hooks/#{@hook.id}")
        end
      end # .edit_hook

      describe '.test_hook', :vcr do
        it 'tests a hook' do
          @client.create_hook(@repo.full_name, 'railsbp', { railsbp_url: 'http://railsbp.com', token: 'xAAQZtJhYHGagsed1kYR' })
          @client.test_hook(@repo.full_name, @hook.id)
          assert_requested :post, github_url("/repos/#{@repo.full_name}/hooks/#{@hook.id}/tests")
        end
      end # .test_hook

      describe '.ping_hook', :vcr do
        it 'pings a hook' do
          @client.create_hook(@repo.full_name, 'railsbp', { railsbp_url: 'http://railsbp.com', token: 'xAAQZtJhYHGagsed1kYR' })
          @client.ping_hook(@repo.full_name, @hook.id)
          assert_requested :post, github_url("/repos/#{@repo.full_name}/hooks/#{@hook.id}/pings")
        end
      end # .ping_hook

      describe '.remove_hook', :vcr do
        it 'removes a hook' do
          @client.remove_hook(@repo.full_name, @hook.id)
          assert_requested :delete, github_url("/repos/#{@repo.full_name}/hooks/#{@hook.id}")
        end
      end # .remove_hook
    end # with hook
  end # with repository

  describe '.org_hooks', :vcr do
    it "returns an organization's hooks" do
      hooks = @client.org_hooks(test_github_org)
      expect(hooks).to be_kind_of Array
      assert_requested :get, github_url("/orgs/#{test_github_org}/hooks")
    end
    it "returns an organization's hooks by ID" do
      request = stub_get('/organizations/1/hooks')
      @client.org_hooks(1)
      assert_requested request
    end
  end

  context 'with org hook' do
    before(:each) do
      @org_hook = @client.create_org_hook(test_github_org, { url: 'http://railsbp.com', content_type: 'json' })
    end

    after(:each) do
      @client.remove_org_hook(test_github_org, @org_hook.id)
    end

    describe '.create_org_hook', :vcr do
      it 'creates an org hook' do
        assert_requested :post, github_url("/orgs/#{test_github_org}/hooks")
      end
      it 'creates an org hook for by ID' do
        request = stub_post('/organizations/1/hooks')
        @client.create_org_hook(1, { url: 'http://railsbp.com', content_type: 'json' })
        assert_requested request
      end
    end # .create_org_hook

    describe '.org_hook', :vcr do
      it 'returns a single org hook' do
        @client.org_hook(test_github_org, @org_hook.id)
        assert_requested :get, github_url("/orgs/#{test_github_org}/hooks/#{@org_hook.id}")
      end
      it 'returns a single org hook by ID' do
        request = stub_get(github_url("/organizations/1/hooks/#{@org_hook.id}"))
        @client.org_hook(1, @org_hook.id)
        assert_requested request
      end
    end # .org_hook

    describe '.edit_org_hook', :vcr do
      it 'edits an org hook' do
        @client.edit_org_hook(test_github_org, @org_hook.id, { url: 'https://railsbp.com', content_type: 'application/json' })
        assert_requested :patch, github_url("/orgs/#{test_github_org}/hooks/#{@org_hook.id}")
      end
      it 'edits an org hook by ID' do
        request = stub_patch("/organizations/1/hooks/#{@org_hook.id}")
        @client.edit_org_hook(1, @org_hook.id, { url: 'https://railsbp.com', content_type: 'application/json' })
        assert_requested request
      end
    end # .edit_org_hook

    describe '.ping_org_hook', :vcr do
      it 'pings an org hook' do
        @client.ping_org_hook(test_github_org, @org_hook.id)
        assert_requested :post, github_url("/orgs/#{test_github_org}/hooks/#{@org_hook.id}/pings")
      end
      it 'pings an org hook by ID' do
        request = stub_post("/organizations/1/hooks/#{@org_hook.id}/pings")
        @client.ping_org_hook(1, @org_hook.id)
        assert_requested request
      end
    end # .ping_org_hook

    describe '.remove_org_hook', :vcr do
      it 'removes an org hook' do
        @client.remove_org_hook(test_github_org, @org_hook.id)
        assert_requested :delete, github_url("/orgs/#{test_github_org}/hooks/#{@org_hook.id}")
      end
      it 'removes an org hook by ID' do
        request = stub_delete("/organizations/1/hooks/#{@org_hook.id}")
        @client.remove_org_hook(1, @org_hook.id)
        assert_requested request
      end
    end # .remove_org_hook
  end # with org hook

  describe '.parse_payload', :vcr do
    it 'parses payload string' do
      test_json = fixture('create_payload.json').read
      result = @client.parse_payload test_json
      expect(result[:ref]).to eq('0.0.1')
      expect(result[:repository][:name]).to eq('public-repo')
      expect(result[:repository][:owner][:site_admin]).to eq(false)
    end
  end # .parse_payload
end