|
6 | 6 | TestDataBuilder.new.create_pact_with_hierarchy("Some Consumer", "1", "Some Provider")
|
7 | 7 | end
|
8 | 8 |
|
9 |
| - let(:path) { "/webhooks/provider/Some%20Provider/consumer/Some%20Consumer" } |
10 | 9 | let(:headers) { {'CONTENT_TYPE' => 'application/json'} }
|
11 | 10 | let(:response_body) { JSON.parse(last_response.body, symbolize_names: true)}
|
12 | 11 | let(:webhook_json) { webhook_hash.to_json }
|
| 12 | + let(:webhook_hash) do |
| 13 | + { |
| 14 | + events: [{ |
| 15 | + name: 'something_happened' |
| 16 | + }], |
| 17 | + request: { |
| 18 | + method: 'POST', |
| 19 | + url: 'http://example.org', |
| 20 | + headers: { |
| 21 | + :"Content-Type" => "application/json" |
| 22 | + }, |
| 23 | + body: { |
| 24 | + a: 'body' |
| 25 | + } |
| 26 | + } |
| 27 | + } |
| 28 | + end |
13 | 29 |
|
14 | 30 | subject { post path, webhook_json, headers }
|
15 | 31 |
|
16 |
| - context "with invalid attributes" do |
| 32 | + context "for a consumer and provider" do |
| 33 | + let(:path) { "/webhooks/provider/Some%20Provider/consumer/Some%20Consumer" } |
17 | 34 |
|
18 |
| - let(:webhook_hash) { {} } |
| 35 | + context "with invalid attributes" do |
| 36 | + let(:webhook_hash) { {} } |
19 | 37 |
|
20 |
| - it "returns a 400" do |
21 |
| - subject |
22 |
| - expect(last_response.status).to be 400 |
23 |
| - end |
| 38 | + it "returns a 400" do |
| 39 | + subject |
| 40 | + expect(last_response.status).to be 400 |
| 41 | + end |
24 | 42 |
|
25 | 43 | it "returns a JSON content type" do
|
26 | 44 | subject
|
27 | 45 | expect(last_response.headers['Content-Type']).to eq 'application/hal+json;charset=utf-8'
|
28 | 46 | end
|
29 | 47 |
|
30 |
| - it "returns the validation errors" do |
31 |
| - subject |
32 |
| - expect(response_body[:errors]).to_not be_empty |
| 48 | + it "returns the validation errors" do |
| 49 | + subject |
| 50 | + expect(response_body[:errors]).to_not be_empty |
| 51 | + end |
33 | 52 | end
|
34 | 53 |
|
35 |
| - end |
36 |
| - |
37 |
| - context "with valid attributes" do |
38 |
| - |
39 |
| - let(:webhook_hash) do |
40 |
| - { |
41 |
| - events: [{ |
42 |
| - name: 'something_happened' |
43 |
| - }], |
44 |
| - request: { |
45 |
| - method: 'POST', |
46 |
| - url: 'https://example.org', |
47 |
| - headers: { |
48 |
| - :"Content-Type" => "application/json" |
49 |
| - }, |
50 |
| - body: { |
51 |
| - a: 'body' |
52 |
| - } |
53 |
| - } |
54 |
| - } |
| 54 | + context "with valid attributes" do |
| 55 | + it "returns a 201 response" do |
| 56 | + subject |
| 57 | + expect(last_response.status).to be 201 |
| 58 | + end |
| 59 | + |
| 60 | + it "returns the Location header" do |
| 61 | + subject |
| 62 | + expect(last_response.headers['Location']).to match(%r{http://example.org/webhooks/.+}) |
| 63 | + end |
| 64 | + |
| 65 | + it "returns a JSON Content Type" do |
| 66 | + subject |
| 67 | + expect(last_response.headers['Content-Type']).to eq 'application/hal+json;charset=utf-8' |
| 68 | + end |
| 69 | + |
| 70 | + it "returns the newly created webhook" do |
| 71 | + subject |
| 72 | + expect(response_body).to include webhook_hash |
| 73 | + end |
55 | 74 | end
|
| 75 | + end |
56 | 76 |
|
57 |
| - let(:webhook_json) { webhook_hash.to_json } |
| 77 | + context "for a provider" do |
| 78 | + let(:path) { "/webhooks/provider/Some%20Provider" } |
58 | 79 |
|
59 | 80 | it "returns a 201 response" do
|
60 | 81 | subject
|
61 | 82 | expect(last_response.status).to be 201
|
62 | 83 | end
|
63 | 84 |
|
64 |
| - it "returns the Location header" do |
| 85 | + it "creates a webhook without a consumer" do |
65 | 86 | subject
|
66 |
| - expect(last_response.headers['Location']).to match(%r{http://example.org/webhooks/.+}) |
| 87 | + expect(PactBroker::Webhooks::Webhook.first.provider).to_not be nil |
| 88 | + expect(PactBroker::Webhooks::Webhook.first.consumer).to be nil |
67 | 89 | end
|
| 90 | + end |
68 | 91 |
|
69 |
| - it "returns a JSON Content Type" do |
| 92 | + context "for a consumer" do |
| 93 | + let(:path) { "/webhooks/consumer/Some%20Consumer" } |
| 94 | + |
| 95 | + it "returns a 201 response" do |
70 | 96 | subject
|
71 |
| - expect(last_response.headers['Content-Type']).to eq 'application/hal+json;charset=utf-8' |
| 97 | + expect(last_response.status).to be 201 |
72 | 98 | end
|
73 | 99 |
|
74 |
| - it "returns the newly created webhook" do |
| 100 | + it "creates a webhook without a provider" do |
75 | 101 | subject
|
76 |
| - expect(response_body).to include webhook_hash |
| 102 | + expect(PactBroker::Webhooks::Webhook.first.consumer).to_not be nil |
| 103 | + expect(PactBroker::Webhooks::Webhook.first.provider).to be nil |
77 | 104 | end
|
78 | 105 | end
|
79 | 106 | end
|
0 commit comments