pact_broker 2.31.0 → 2.32.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (105) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +40 -0
  3. data/db/migrations/20190509_create_version_sequence.rb +8 -0
  4. data/db/migrations/20190510_set_version_sequence.rb +9 -0
  5. data/db/migrations/20190511_create_integrations_view.rb +19 -0
  6. data/db/migrations/20190523_add_enabled_column_to_webhooks.rb +5 -0
  7. data/db/migrations/20190524_set_webhooks_enabled.rb +10 -0
  8. data/db/migrations/20190525_add_description_column_to_webhooks.rb +5 -0
  9. data/lib/pact_broker/api.rb +3 -0
  10. data/lib/pact_broker/api/decorators/base_decorator.rb +0 -3
  11. data/lib/pact_broker/api/decorators/integration_decorator.rb +40 -0
  12. data/lib/pact_broker/api/decorators/integrations_decorator.rb +19 -0
  13. data/lib/pact_broker/api/decorators/pact_decorator.rb +1 -1
  14. data/lib/pact_broker/api/decorators/pact_details_decorator.rb +1 -6
  15. data/lib/pact_broker/api/decorators/verifiable_pact_decorator.rb +12 -0
  16. data/lib/pact_broker/api/decorators/verifiable_pacts_decorator.rb +20 -0
  17. data/lib/pact_broker/api/decorators/webhook_decorator.rb +5 -1
  18. data/lib/pact_broker/api/decorators/webhook_execution_result_decorator.rb +0 -1
  19. data/lib/pact_broker/api/decorators/webhooks_decorator.rb +2 -2
  20. data/lib/pact_broker/api/pact_broker_urls.rb +37 -3
  21. data/lib/pact_broker/api/resources/base_resource.rb +4 -0
  22. data/lib/pact_broker/api/resources/dashboard.rb +1 -1
  23. data/lib/pact_broker/api/resources/integrations.rb +10 -2
  24. data/lib/pact_broker/api/resources/matrix_for_consumer_and_provider.rb +8 -14
  25. data/lib/pact_broker/api/resources/pact.rb +15 -3
  26. data/lib/pact_broker/api/resources/verification.rb +0 -2
  27. data/lib/pact_broker/api/resources/verifications.rb +18 -1
  28. data/lib/pact_broker/api/resources/webhook.rb +1 -1
  29. data/lib/pact_broker/api/resources/webhook_execution.rb +18 -9
  30. data/lib/pact_broker/app.rb +10 -11
  31. data/lib/pact_broker/db.rb +2 -2
  32. data/lib/pact_broker/db/data_migrations/helpers.rb +11 -0
  33. data/lib/pact_broker/db/data_migrations/set_latest_version_sequence_value.rb +29 -0
  34. data/lib/pact_broker/db/data_migrations/set_webhooks_enabled.rb +17 -0
  35. data/lib/pact_broker/db/migrate_data.rb +2 -0
  36. data/lib/pact_broker/db/seed_example_data.rb +6 -3
  37. data/lib/pact_broker/domain/order_versions.rb +14 -1
  38. data/lib/pact_broker/domain/verification.rb +4 -0
  39. data/lib/pact_broker/domain/webhook.rb +13 -3
  40. data/lib/pact_broker/domain/webhook_request.rb +3 -2
  41. data/lib/pact_broker/index/service.rb +3 -0
  42. data/lib/pact_broker/integrations/integration.rb +10 -0
  43. data/lib/pact_broker/integrations/service.rb +5 -0
  44. data/lib/pact_broker/matrix/parse_query.rb +2 -0
  45. data/lib/pact_broker/matrix/row.rb +8 -0
  46. data/lib/pact_broker/matrix/service.rb +1 -2
  47. data/lib/pact_broker/pacts/service.rb +16 -9
  48. data/lib/pact_broker/test/test_data_builder.rb +6 -2
  49. data/lib/pact_broker/verifications/sequence.rb +0 -2
  50. data/lib/pact_broker/verifications/service.rb +10 -2
  51. data/lib/pact_broker/version.rb +1 -1
  52. data/lib/pact_broker/versions/sequence.rb +38 -0
  53. data/lib/pact_broker/webhooks/job.rb +19 -7
  54. data/lib/pact_broker/webhooks/render.rb +30 -13
  55. data/lib/pact_broker/webhooks/repository.rb +3 -4
  56. data/lib/pact_broker/webhooks/service.rb +60 -34
  57. data/lib/pact_broker/webhooks/trigger_service.rb +6 -6
  58. data/lib/pact_broker/webhooks/webhook.rb +9 -1
  59. data/lib/pact_broker/webhooks/webhook_request_template.rb +11 -7
  60. data/lib/rack/pact_broker/database_transaction.rb +6 -2
  61. data/script/publish-new.sh +23 -1
  62. data/script/publish.sh +13 -4
  63. data/script/seed.rb +53 -52
  64. data/spec/features/create_webhook_spec.rb +2 -0
  65. data/spec/features/execute_webhook_spec.rb +4 -3
  66. data/spec/features/get_integrations_spec.rb +17 -0
  67. data/spec/features/get_pacts_to_verify_spec.rb +7 -3
  68. data/spec/features/publish_verification_spec.rb +8 -1
  69. data/spec/features/update_webhook_spec.rb +47 -0
  70. data/spec/integration/webhooks/certificate_spec.rb +1 -1
  71. data/spec/lib/pact_broker/api/contracts/webhook_contract_spec.rb +12 -0
  72. data/spec/lib/pact_broker/api/decorators/integration_decorator_spec.rb +82 -0
  73. data/spec/lib/pact_broker/api/decorators/integrations_decorator_spec.rb +29 -0
  74. data/spec/lib/pact_broker/api/decorators/pact_decorator_spec.rb +12 -4
  75. data/spec/lib/pact_broker/api/decorators/verifiable_pact_decorator_spec.rb +30 -0
  76. data/spec/lib/pact_broker/api/decorators/verifiable_pacts_decorator_spec.rb +29 -0
  77. data/spec/lib/pact_broker/api/decorators/webhook_decorator_spec.rb +20 -1
  78. data/spec/lib/pact_broker/api/decorators/webhook_execution_result_decorator_spec.rb +0 -4
  79. data/spec/lib/pact_broker/api/decorators/webhooks_decorator_spec.rb +5 -4
  80. data/spec/lib/pact_broker/api/pact_broker_urls_spec.rb +64 -1
  81. data/spec/lib/pact_broker/api/resources/pact_spec.rb +0 -3
  82. data/spec/lib/pact_broker/api/resources/verifications_spec.rb +40 -10
  83. data/spec/lib/pact_broker/api/resources/webhook_execution_spec.rb +13 -3
  84. data/spec/lib/pact_broker/app_spec.rb +28 -4
  85. data/spec/lib/pact_broker/db/data_migrations/set_latest_version_sequence_value_spec.rb +68 -0
  86. data/spec/lib/pact_broker/domain/order_versions_spec.rb +1 -4
  87. data/spec/lib/pact_broker/domain/webhook_spec.rb +10 -6
  88. data/spec/lib/pact_broker/matrix/parse_query_spec.rb +15 -7
  89. data/spec/lib/pact_broker/pacts/service_spec.rb +13 -5
  90. data/spec/lib/pact_broker/verifications/service_spec.rb +15 -3
  91. data/spec/lib/pact_broker/versions/repository_spec.rb +1 -1
  92. data/spec/lib/pact_broker/webhooks/job_spec.rb +52 -15
  93. data/spec/lib/pact_broker/webhooks/render_spec.rb +28 -7
  94. data/spec/lib/pact_broker/webhooks/repository_spec.rb +23 -32
  95. data/spec/lib/pact_broker/webhooks/service_spec.rb +186 -62
  96. data/spec/lib/pact_broker/webhooks/trigger_service_spec.rb +6 -5
  97. data/spec/lib/pact_broker/webhooks/webhook_request_template_spec.rb +12 -5
  98. data/spec/lib/rack/pact_broker/database_transaction_spec.rb +10 -0
  99. data/spec/lib/rack/pact_broker/ui_request_filter_spec.rb +9 -0
  100. data/spec/migrations/23_pact_versions_spec.rb +7 -1
  101. data/spec/support/database_cleaner.rb +11 -1
  102. data/spec/support/metadata_test_server.rb +40 -0
  103. data/spec/support/verification_job.rb +34 -0
  104. data/spec/support/webhook_endpoint_middleware.rb +22 -0
  105. metadata +37 -2
@@ -9,21 +9,21 @@ module PactBroker
9
9
  extend PactBroker::Services
10
10
  include PactBroker::Logging
11
11
 
12
- def trigger_webhooks_for_new_pact pact
13
- webhook_service.trigger_webhooks pact, nil, PactBroker::Webhooks::WebhookEvent::CONTRACT_PUBLISHED
12
+ def trigger_webhooks_for_new_pact(pact, webhook_options)
13
+ webhook_service.trigger_webhooks pact, nil, PactBroker::Webhooks::WebhookEvent::CONTRACT_PUBLISHED, webhook_options
14
14
  if pact_is_new_or_newly_tagged_or_pact_has_changed_since_previous_version?(pact)
15
- webhook_service.trigger_webhooks pact, nil, PactBroker::Webhooks::WebhookEvent::CONTRACT_CONTENT_CHANGED
15
+ webhook_service.trigger_webhooks pact, nil, PactBroker::Webhooks::WebhookEvent::CONTRACT_CONTENT_CHANGED, webhook_options
16
16
  else
17
17
  logger.debug "Pact content has not changed since previous version, not triggering webhooks for changed content"
18
18
  end
19
19
  end
20
20
 
21
- def trigger_webhooks_for_updated_pact(existing_pact, updated_pact)
22
- webhook_service.trigger_webhooks updated_pact, nil, PactBroker::Webhooks::WebhookEvent::CONTRACT_PUBLISHED
21
+ def trigger_webhooks_for_updated_pact(existing_pact, updated_pact, webhook_options)
22
+ webhook_service.trigger_webhooks updated_pact, nil, PactBroker::Webhooks::WebhookEvent::CONTRACT_PUBLISHED, webhook_options
23
23
  # TODO this should use the sha!
24
24
  if existing_pact.pact_version_sha != updated_pact.pact_version_sha
25
25
  logger.debug "Existing pact for version #{existing_pact.consumer_version_number} has been updated with new content, triggering webhooks for changed content"
26
- webhook_service.trigger_webhooks updated_pact, nil, PactBroker::Webhooks::WebhookEvent::CONTRACT_CONTENT_CHANGED
26
+ webhook_service.trigger_webhooks updated_pact, nil, PactBroker::Webhooks::WebhookEvent::CONTRACT_CONTENT_CHANGED, webhook_options
27
27
  else
28
28
  logger.debug "Pact content has not changed since previous revision, not triggering webhooks for changed content"
29
29
  end
@@ -15,6 +15,10 @@ module PactBroker
15
15
 
16
16
  dataset_module do
17
17
  include PactBroker::Repositories::Helpers
18
+
19
+ def enabled
20
+ where(enabled: true)
21
+ end
18
22
  end
19
23
 
20
24
  def before_destroy
@@ -42,10 +46,12 @@ module PactBroker
42
46
  def to_domain
43
47
  Domain::Webhook.new(
44
48
  uuid: uuid,
49
+ description: description,
45
50
  consumer: consumer,
46
51
  provider: provider,
47
52
  events: events,
48
53
  request: Webhooks::WebhookRequestTemplate.new(request_attributes),
54
+ enabled: enabled,
49
55
  created_at: created_at,
50
56
  updated_at: updated_at)
51
57
  end
@@ -81,17 +87,19 @@ module PactBroker
81
87
  def self.properties_hash_from_domain webhook
82
88
  is_json_request_body = !(String === webhook.request.body || webhook.request.body.nil?) # Can't rely on people to set content type
83
89
  {
90
+ description: webhook.description,
84
91
  method: webhook.request.method,
85
92
  url: webhook.request.url,
86
93
  username: webhook.request.username,
87
94
  password: not_plain_text_password(webhook.request.password),
95
+ enabled: webhook.enabled.nil? ? true : webhook.enabled,
88
96
  body: (is_json_request_body ? webhook.request.body.to_json : webhook.request.body),
89
97
  is_json_request_body: is_json_request_body
90
98
  }
91
99
  end
92
100
  end
93
101
 
94
- Webhook.plugin :timestamps, :update_on_create=>true
102
+ Webhook.plugin :timestamps, update_on_create: true
95
103
 
96
104
  class WebhookHeader < Sequel::Model
97
105
  associate(:many_to_one, :webhook, :class => "PactBroker::Repositories::Webhook", :key => :webhook_id, :primary_key => :id)
@@ -22,7 +22,7 @@ module PactBroker
22
22
  @url = attributes[:url]
23
23
  @username = attributes[:username]
24
24
  @password = attributes[:password]
25
- @headers = attributes[:headers] || {}
25
+ @headers = Rack::Utils::HeaderHash.new(attributes[:headers] || {})
26
26
  @body = attributes[:body]
27
27
  @uuid = attributes[:uuid]
28
28
  end
@@ -30,23 +30,23 @@ module PactBroker
30
30
  def build(context)
31
31
  attributes = {
32
32
  method: http_method,
33
- url: build_url(context[:pact], context[:verification], context[:base_url]),
33
+ url: build_url(context[:pact], context[:verification], context[:webhook_context]),
34
34
  headers: headers,
35
35
  username: username,
36
36
  password: password,
37
37
  uuid: uuid,
38
- body: build_body(context[:pact], context[:verification], context[:base_url])
38
+ body: build_body(context[:pact], context[:verification], context[:webhook_context])
39
39
  }
40
40
  PactBroker::Domain::WebhookRequest.new(attributes)
41
41
  end
42
42
 
43
- def build_url(pact, verification, broker_base_url)
44
- URI(PactBroker::Webhooks::Render.call(url, pact, verification, broker_base_url){ | value | CGI::escape(value) if !value.nil? } ).to_s
43
+ def build_url(pact, verification, webhook_context)
44
+ URI(PactBroker::Webhooks::Render.call(url, pact, verification, webhook_context){ | value | CGI::escape(value) if !value.nil? } ).to_s
45
45
  end
46
46
 
47
- def build_body(pact, verification, broker_base_url)
47
+ def build_body(pact, verification, webhook_context)
48
48
  body_string = String === body ? body : body.to_json
49
- PactBroker::Webhooks::Render.call(body_string, pact, verification, broker_base_url)
49
+ PactBroker::Webhooks::Render.call(body_string, pact, verification, webhook_context)
50
50
  end
51
51
 
52
52
  def description
@@ -64,6 +64,10 @@ module PactBroker
64
64
  end
65
65
  end
66
66
 
67
+ def headers= headers
68
+ @headers = Rack::Utils::HeaderHash.new(headers)
69
+ end
70
+
67
71
  private
68
72
 
69
73
  def to_s
@@ -22,14 +22,18 @@ module Rack
22
22
  def call env
23
23
  set_database_connector
24
24
  if use_transaction? env
25
- call_with_transaction env
25
+ call_with_transaction(add_database_connector(env))
26
26
  else
27
- call_without_transaction env
27
+ call_without_transaction(add_database_connector(env))
28
28
  end
29
29
  ensure
30
30
  clear_database_connector
31
31
  end
32
32
 
33
+ def add_database_connector(env)
34
+ env.merge("pactbroker.database_connector" => @default_database_connector)
35
+ end
36
+
33
37
  def use_transaction? env
34
38
  TRANS_METHODS.include? env[REQUEST_METHOD]
35
39
  end
@@ -1,9 +1,31 @@
1
1
  set -e
2
+
2
3
  BODY=$(ruby -e "require 'json'; j = JSON.parse(File.read('script/foo-bar.json')); j['interactions'][0]['providerState'] = 'it is ' + Time.now.to_s; puts j.to_json")
3
4
  latest_url=$(curl http://localhost:9292/pacts/provider/Bar/consumer/Foo/latest | jq -r ._links.self.href)
4
5
  next_version=$(echo ${latest_url} | ruby -e "version = ARGF.read[/\d+\.\d+\.\d+/]; require 'semver'; puts SemVer.parse(version).tap{ | v| v.minor = v.minor + 1}.format('%M.%m.%p')")
6
+
7
+ curl -v -XPUT \
8
+ -H "Content-Length: 0" \
9
+ -H "Content-Type: application/json" \
10
+ http://localhost:9292/pacticipants/Foo/versions/${next_version}/tags/dev
11
+
5
12
  echo ${BODY} > tmp.json
6
13
  curl -v -XPUT \-H "Content-Type: application/json" -d@tmp.json \
7
14
  http://localhost:9292/pacts/provider/Bar/consumer/Foo/version/${next_version}
15
+
16
+
17
+ sleep 3
18
+
19
+
20
+ curl -v -XPUT \
21
+ -H "Content-Length: 0" \
22
+ -H "Content-Type: application/json" \
23
+ http://localhost:9292/pacticipants/Foo/versions/${next_version}/tags/prod
24
+
25
+ next_next_version=$(echo ${next_version} | ruby -e "version = ARGF.read[/\d+\.\d+\.\d+/]; require 'semver'; puts SemVer.parse(version).tap{ | v| v.minor = v.minor + 1}.format('%M.%m.%p')")
26
+
27
+ curl -v -XPUT \-H "Content-Type: application/json" -d@tmp.json \
28
+ http://localhost:9292/pacts/provider/Bar/consumer/Foo/version/${next_next_version}
29
+
8
30
  rm tmp.json
9
- echo ""
31
+ echo ""
@@ -1,19 +1,28 @@
1
1
  #!/bin/sh
2
2
  function finish {
3
- rm -rf tmp/pact.json
3
+ rm -rf $tmpfile
4
4
  }
5
5
  trap finish EXIT
6
6
 
7
7
  set -x
8
8
 
9
+ consumer_version="1.0.$(ruby -e "puts (rand * 10).to_i")"
9
10
  consumer=${1:-Foo}
10
11
  provider=${2:-Bar}
11
12
  escaped_consumer=$(echo $consumer | ruby -e "require 'uri'; puts URI.encode(ARGF.read.strip)")
12
13
  escaped_provider=$(echo $provider | ruby -e "require 'uri'; puts URI.encode(ARGF.read.strip)")
13
14
  echo $consumer $provider
15
+
16
+ curl -v -XPUT \
17
+ -H "Content-Length: 0" \
18
+ -H "Content-Type: application/json" \
19
+ http://localhost:9292/pacticipants/${escaped_consumer}/versions/${consumer_version}/tags/dev
20
+
21
+
14
22
  body=$(cat script/foo-bar.json | sed "s/Foo/${consumer}/" | sed "s/Bar/${provider}/")
15
- echo $body > tmp/pact.json
23
+ tmpfile=$(mktemp)
24
+ echo $body > $tmpfile
16
25
  curl -v -XPUT \-H "Content-Type: application/json" \
17
- -d@tmp/pact.json \
18
- http://127.0.0.1:9292/pacts/provider/${escaped_provider}/consumer/${escaped_consumer}/version/1.0.0
26
+ -d@$tmpfile \
27
+ http://127.0.0.1:9292/pacts/provider/${escaped_provider}/consumer/${escaped_consumer}/version/${consumer_version}
19
28
  echo ""
@@ -14,7 +14,7 @@ DATABASE_CREDENTIALS = {logger: Logger.new($stdout), adapter: "sqlite", database
14
14
  connection = Sequel.connect(DATABASE_CREDENTIALS)
15
15
  connection.timezone = :utc
16
16
  # Uncomment these lines to open a pry session for inspecting the database
17
- # require 'table_print'
17
+
18
18
  # require 'pry'; pry(binding);
19
19
  # exit
20
20
 
@@ -44,54 +44,55 @@ webhook_body = {
44
44
  }
45
45
 
46
46
  TestDataBuilder.new
47
- .create_global_webhook(method: 'GET', url: "http://example.org?consumer=${pactbroker.consumerName}&provider=${pactbroker.providerName}")
48
- .create_certificate(path: 'spec/fixtures/certificates/self-signed.badssl.com.pem')
49
- .create_consumer("Bethtest")
50
- .create_verification_webhook(method: 'GET', url: "http://localhost:9292", body: webhook_body, username: "foo", password: "bar", headers: {"Accept" => "application/json"})
51
- .create_consumer("Foo")
52
- .create_label("microservice")
53
- .create_provider("Bar")
54
- .create_label("microservice")
55
- .create_verification_webhook(method: 'GET', url: "http://example.org")
56
- .create_consumer_webhook(method: 'GET', url: 'https://www.google.com.au', event_names: ['provider_verification_published'])
57
- .create_provider_webhook(method: 'GET', url: 'https://theage.com.au')
58
- .create_webhook(method: 'GET', url: 'https://self-signed.badssl.com')
59
- .create_consumer_version("1.2.100")
60
- .create_pact
61
- .create_verification(provider_version: "1.4.234", success: true, execution_date: DateTime.now - 15)
62
- .revise_pact
63
- .create_consumer_version("1.2.101")
64
- .create_consumer_version_tag('prod')
65
- .create_pact
66
- .create_verification(provider_version: "9.9.10", success: false, execution_date: DateTime.now - 15)
67
- .create_consumer_version("1.2.102")
68
- .create_pact(created_at: (Date.today - 7).to_datetime)
69
- .create_verification(provider_version: "9.9.9", success: true, execution_date: DateTime.now - 14)
70
- .create_provider("Animals")
71
- .create_webhook(method: 'GET', url: 'http://localhost:9393/')
72
- .create_pact(created_at: (Time.now - 140).to_datetime)
73
- .create_verification(provider_version: "2.0.366", execution_date: Date.today - 2) #changed
74
- .create_provider("Wiffles")
75
- .create_pact
76
- .create_verification(provider_version: "3.6.100", success: false, execution_date: Date.today - 7)
77
- .create_provider("Hello World App")
78
- .create_consumer_version("1.2.107")
79
- .create_pact(created_at: (Date.today - 1).to_datetime)
80
- .create_consumer("The Android App")
81
- .create_provider("The back end")
82
- .create_webhook(method: 'GET', url: 'http://localhost:9393/')
83
- .create_consumer_version("1.2.106")
84
- .create_consumer_version_tag("production")
85
- .create_consumer_version_tag("feat-x")
86
- .create_pact
87
- .create_consumer("Some other app")
88
- .create_provider("A service")
89
- .create_webhook(method: 'GET', url: 'http://localhost:9393/')
90
- .create_triggered_webhook(status: 'success')
91
- .create_webhook_execution
92
- .create_webhook(method: 'POST', url: 'http://foo:9393/')
93
- .create_triggered_webhook(status: 'failure')
94
- .create_webhook_execution
95
- .create_consumer_version("1.2.106")
96
- .create_pact(created_at: (Date.today - 26).to_datetime)
97
- .create_verification(provider_version: "4.8.152", execution_date: DateTime.now)
47
+ .create_global_webhook(method: 'POST', url: "http://localhost:9292/pact-changed-webhook", body: webhook_body.to_json)
48
+ .create_global_verification_webhook(method: 'POST', url: "http://localhost:9292/verification-published-webhook", body: webhook_body.to_json)
49
+ # .create_certificate(path: 'spec/fixtures/certificates/self-signed.badssl.com.pem')
50
+ # .create_consumer("Bethtest")
51
+ # .create_verification_webhook(method: 'GET', url: "http://localhost:9292", body: webhook_body, username: "foo", password: "bar", headers: {"Accept" => "application/json"})
52
+ # .create_consumer("Foo")
53
+ # .create_label("microservice")
54
+ # .create_provider("Bar")
55
+ # .create_label("microservice")
56
+ # .create_verification_webhook(method: 'GET', url: "http://example.org")
57
+ # .create_consumer_webhook(method: 'GET', url: 'https://www.google.com.au', event_names: ['provider_verification_published'])
58
+ # .create_provider_webhook(method: 'GET', url: 'https://theage.com.au')
59
+ # .create_webhook(method: 'GET', url: 'https://self-signed.badssl.com')
60
+ # .create_consumer_version("1.2.100")
61
+ # .create_pact
62
+ # .create_verification(provider_version: "1.4.234", success: true, execution_date: DateTime.now - 15)
63
+ # .revise_pact
64
+ # .create_consumer_version("1.2.101")
65
+ # .create_consumer_version_tag('prod')
66
+ # .create_pact
67
+ # .create_verification(provider_version: "9.9.10", success: false, execution_date: DateTime.now - 15)
68
+ # .create_consumer_version("1.2.102")
69
+ # .create_pact(created_at: (Date.today - 7).to_datetime)
70
+ # .create_verification(provider_version: "9.9.9", success: true, execution_date: DateTime.now - 14)
71
+ # .create_provider("Animals")
72
+ # .create_webhook(method: 'GET', url: 'http://localhost:9393/')
73
+ # .create_pact(created_at: (Time.now - 140).to_datetime)
74
+ # .create_verification(provider_version: "2.0.366", execution_date: Date.today - 2) #changed
75
+ # .create_provider("Wiffles")
76
+ # .create_pact
77
+ # .create_verification(provider_version: "3.6.100", success: false, execution_date: Date.today - 7)
78
+ # .create_provider("Hello World App")
79
+ # .create_consumer_version("1.2.107")
80
+ # .create_pact(created_at: (Date.today - 1).to_datetime)
81
+ # .create_consumer("The Android App")
82
+ # .create_provider("The back end")
83
+ # .create_webhook(method: 'GET', url: 'http://localhost:9393/')
84
+ # .create_consumer_version("1.2.106")
85
+ # .create_consumer_version_tag("production")
86
+ # .create_consumer_version_tag("feat-x")
87
+ # .create_pact
88
+ # .create_consumer("Some other app")
89
+ # .create_provider("A service")
90
+ # .create_webhook(method: 'GET', url: 'http://localhost:9393/')
91
+ # .create_triggered_webhook(status: 'success')
92
+ # .create_webhook_execution
93
+ # .create_webhook(method: 'POST', url: 'http://foo:9393/')
94
+ # .create_triggered_webhook(status: 'failure')
95
+ # .create_webhook_execution
96
+ # .create_consumer_version("1.2.106")
97
+ # .create_pact(created_at: (Date.today - 26).to_datetime)
98
+ # .create_verification(provider_version: "4.8.152", execution_date: DateTime.now)
@@ -11,6 +11,8 @@ describe "Creating a webhook" do
11
11
  let(:webhook_json) { webhook_hash.to_json }
12
12
  let(:webhook_hash) do
13
13
  {
14
+ description: "trigger build",
15
+ enabled: false,
14
16
  events: [{
15
17
  name: 'something_happened'
16
18
  }],
@@ -19,9 +19,10 @@ describe "Execute a webhook" do
19
19
 
20
20
  context "when the execution is successful" do
21
21
  let!(:request) do
22
- stub_request(:post, /http/).with(body: 'http://broker/pacts/provider/Bar/consumer/Foo/version/1').to_return(:status => 200, body: response_body)
22
+ stub_request(:post, /http/).with(body: expected_webhook_url).to_return(:status => 200, body: response_body)
23
23
  end
24
24
 
25
+ let(:expected_webhook_url) { %r{http://example.org/pacts/provider/Bar/consumer/Foo/pact-version/.*/metadata/Y29uc3VtZXJfdmVyc2lvbl9udW1iZXI9MQ==} }
25
26
  let(:response_body) { "webhook-response-body" }
26
27
 
27
28
  it "performs the HTTP request" do
@@ -81,8 +82,8 @@ describe "Execute a webhook" do
81
82
 
82
83
  subject { post path; last_response }
83
84
 
84
- it "returns a 500 response" do
85
- expect(subject.status).to be 500
85
+ it "returns a 200 response" do
86
+ expect(subject.status).to be 200
86
87
  end
87
88
 
88
89
  it "does not save a TriggeredWebhook" do
@@ -0,0 +1,17 @@
1
+ describe "Get integrations dot file" do
2
+ before do
3
+ TestDataBuilder.new
4
+ .create_pact_with_hierarchy("Foo", "1", "Bar")
5
+ end
6
+
7
+ let(:path) { "/integrations" }
8
+ let(:response_body_hash) { JSON.parse(subject.body, symbolize_names: true) }
9
+
10
+ subject { get path, nil, {'HTTP_ACCEPT' => 'application/hal+json' } }
11
+
12
+ it { is_expected.to be_a_hal_json_success_response }
13
+
14
+ it "returns a json body with embedded integrations" do
15
+ expect(JSON.parse(subject.body)["_embedded"]["integrations"]).to be_a(Array)
16
+ end
17
+ end
@@ -12,7 +12,9 @@ describe "fetching pacts to verify", pending: 'not yet implemented' do
12
12
  # eg. if content has been verified on git branch (broker tag) feat-2,
13
13
  # it's still pending on master, and shouldn't fail the build
14
14
  {
15
- provider_version_tags: [{ name: "feat-2" }],
15
+ protocol: "http1", # other option is "message"
16
+ include_other_pending: true, # whether or not to include pending pacts not already specified by the consumer_version_tags('head' pacts that have not yet been successfully verified)
17
+ provider_version_tags: [{ name: "feat-2" }], # the provider tags that will be applied to this app version when the results are published
16
18
  consumer_version_tags: [
17
19
  { name: "feat-1", fallback: "master" }, # allow a fallback to be provided for the "branch mirroring" workflow
18
20
  { name: "test", required: true }, # default to optional or required??? Ron?
@@ -30,8 +32,10 @@ describe "fetching pacts to verify", pending: 'not yet implemented' do
30
32
  end
31
33
 
32
34
  it "returns a list of links to the pacts" do
33
- expect(response_body_hash[:_links][:'pb:pacts']).to be_instance_of(Array)
35
+ expect(response_body_hash[:_embedded][:'pacts']).to be_instance_of(Array)
34
36
  end
35
37
 
36
- it "indicates whether a pact is pending or not"
38
+ it "indicates whether a pact is pending or not" do
39
+ expect(response_body_hash[:_embedded][:'pacts'].first[:pending]).to be true
40
+ end
37
41
  end
@@ -7,8 +7,15 @@ describe "Recording a pact verification" do
7
7
  let(:verification_content) { load_fixture('verification.json') }
8
8
  let(:parsed_response_body) { JSON.parse(subject.body) }
9
9
  let(:pact) { td.pact }
10
+ let(:rack_env) do
11
+ {
12
+ 'CONTENT_TYPE' => 'application/json',
13
+ 'HTTP_ACCEPT' => 'application/hal+json',
14
+ 'pactbroker.database_connector' => lambda { |&block| block.call }
15
+ }
16
+ end
10
17
 
11
- subject { post path, verification_content, {'CONTENT_TYPE' => 'application/json', 'HTTP_ACCEPT' => 'application/hal+json' }; last_response }
18
+ subject { post path, verification_content, rack_env; last_response }
12
19
 
13
20
  before do
14
21
  td.create_provider("Provider")
@@ -0,0 +1,47 @@
1
+ require 'support/test_data_builder'
2
+
3
+ describe "Updating a webhook" do
4
+ let(:webhook) do
5
+ TestDataBuilder.new
6
+ .create_pact_with_hierarchy("Some Consumer", "1", "Some Provider")
7
+ .create_global_webhook
8
+ .and_return(:webhook)
9
+ end
10
+
11
+ let(:headers) { {'CONTENT_TYPE' => 'application/json'} }
12
+ let(:response_body) { JSON.parse(last_response.body, symbolize_names: true)}
13
+ let(:webhook_json) { webhook_hash.to_json }
14
+ let(:webhook_hash) do
15
+ {
16
+ description: "trigger build",
17
+ consumer: {
18
+ name: "Some Consumer"
19
+ },
20
+ enabled: false,
21
+ events: [{
22
+ name: 'contract_published'
23
+ }],
24
+ request: {
25
+ method: 'POST',
26
+ url: 'https://example.org',
27
+ headers: {
28
+ :"Content-Type" => "application/json"
29
+ },
30
+ body: {
31
+ a: 'body'
32
+ }
33
+ }
34
+ }
35
+ end
36
+
37
+ subject { put(path, webhook_json, headers) }
38
+
39
+ let(:path) { "/webhooks/#{webhook.uuid}" }
40
+
41
+ context "with valid attributes" do
42
+ it "returns the newly created webhook" do
43
+ subject
44
+ expect(response_body).to include description: "trigger build"
45
+ end
46
+ end
47
+ end