Skip to content

Commit 046383b

Browse files
committed
WIP webhooks
1 parent a59e46e commit 046383b

File tree

9 files changed

+127
-1
lines changed

9 files changed

+127
-1
lines changed

.rspec

+1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
--color
22
--format documentation
3+
--require spec_helper

db/migrations/12_create_webhooks_table.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
foreign_key :provider_id, :pacticipants, null: false
1010
end
1111

12-
create_table(:webhooks_headers) do
12+
create_table(:webhook_headers) do
1313
String :name, null: false
1414
String :value
1515
foreign_key :webhook_id, :webhooks, null: false
+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
require_relative 'base_decorator'
2+
3+
module PactBroker
4+
module Api
5+
module Decorators
6+
class WebhookDecorator < BaseDecorator
7+
8+
end
9+
end
10+
end
11+
end
+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
require 'pact_broker/api/resources/base_resource'
2+
3+
module PactBroker::Api
4+
5+
module Resources
6+
7+
class Webhooks < BaseResource
8+
9+
def content_types_accepted
10+
[["application/json", :from_json]]
11+
end
12+
13+
def allowed_methods
14+
["POST"]
15+
end
16+
17+
def from_json
18+
19+
end
20+
21+
end
22+
end
23+
24+
end
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
require 'sequel'
2+
require 'pact_broker/models/webook'
3+
4+
module PactBroker
5+
module Repositories
6+
class WebhookRepository
7+
8+
def save webhook
9+
10+
11+
end
12+
13+
end
14+
end
15+
end
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
require 'spec_helper'
2+
require 'pact_broker/api/decorators/webhook'
3+
4+
5+
6+
module PactBroker
7+
module Api
8+
module Decorators
9+
describe WebhookDecorator do
10+
11+
let(:hash) do
12+
{
13+
method: 'POST',
14+
url: 'http://example.org/hook',
15+
headers: {'Content-Type' => 'application/json'}
16+
body: { some: 'body' }
17+
}
18+
end
19+
20+
end
21+
end
22+
end
23+
end
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
require 'pact_broker/api/resources/webhooks'
2+
3+
module PactBroker::Api
4+
5+
module Resources
6+
7+
describe Webhooks do
8+
9+
describe "POST" do
10+
let(:webhook_json) do
11+
{
12+
method: 'POST',
13+
url: 'http://blah.com',
14+
headers: {''}
15+
}
16+
end
17+
18+
let(:uuid) { '1483234k24DKFGJ45K' }
19+
20+
before do
21+
allow(SecureRandom).to receive(:urlsafe_base64).and_return(uuid)
22+
end
23+
it "creates a webhook" do
24+
post "/webhooks/provider/Some%20Provider/consumer/Some%20Consumer", webhook_json, {'CONTENT_TYPE' => 'application/json'}
25+
end
26+
end
27+
28+
29+
30+
end
31+
end
32+
33+
end
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
require 'spec_helper'
2+
require 'pact_broker/repositories/webhook_repository'
3+
4+
module PactBroker
5+
module Repositories
6+
describe WebhookRepository do
7+
8+
describe "#save" do
9+
10+
let(:webhook) { Models::Webhook.new(consumer_id: consumer_id)}
11+
12+
end
13+
14+
end
15+
end
16+
end

spec/spec_helper.rb

+3
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,13 @@ def load_json_fixture(file_name)
2727
end
2828

2929
config.before :each do
30+
# TODO: Change this to transactional!
3031
DB::PACT_BROKER_DB[:pacts].truncate
3132
DB::PACT_BROKER_DB[:tags].truncate
3233
DB::PACT_BROKER_DB[:versions].truncate
3334
DB::PACT_BROKER_DB[:pacticipants].truncate
35+
DB::PACT_BROKER_DB[:webhooks].truncate
36+
DB::PACT_BROKER_DB[:webhook_headers].truncate
3437
end
3538

3639
config.include Rack::Test::Methods

0 commit comments

Comments
 (0)