pact_broker 1.18.0 → 2.0.0.beta.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (133) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +12 -9
  3. data/DEVELOPER_DOCUMENTATION.md +53 -0
  4. data/README.md +13 -13
  5. data/db/migrations/23_create_pact_contents_table.rb +19 -0
  6. data/db/migrations/24_populate_pact_contents.rb +9 -0
  7. data/db/migrations/25_populate_pact_contents_pacticipants.rb +7 -0
  8. data/db/migrations/26_make_pc_pacticipants_mandatory.rb +8 -0
  9. data/db/migrations/27_create_pact_publications.rb +18 -0
  10. data/db/migrations/28_populate_pact_publications.rb +13 -0
  11. data/db/migrations/29_recreate_all_pacts.rb +16 -0
  12. data/db/migrations/30_drop_pacts.rb +8 -0
  13. data/db/migrations/31_drop_pact_version_contents.rb +5 -0
  14. data/db/migrations/32_rename_pact_contents.rb +5 -0
  15. data/db/migrations/33_recreate_all_pacts.rb +52 -0
  16. data/db/migrations/34_recreate_latest_tagged_pacts.rb +23 -0
  17. data/db/migrations/35_create_verifications.rb +15 -0
  18. data/db/migrations/36_create_latest_verifications.rb +14 -0
  19. data/db/pact_broker_database.sqlite3 +0 -0
  20. data/lib/pact_broker/api.rb +25 -10
  21. data/lib/pact_broker/api/contracts/verification_contract.rb +41 -0
  22. data/lib/pact_broker/api/decorators/pact_decorator.rb +7 -0
  23. data/lib/pact_broker/api/decorators/pact_version_decorator.rb +0 -1
  24. data/lib/pact_broker/api/decorators/representable_pact.rb +4 -3
  25. data/lib/pact_broker/api/decorators/timestamps.rb +1 -1
  26. data/lib/pact_broker/api/decorators/verification_decorator.rb +30 -0
  27. data/lib/pact_broker/api/decorators/verifications_decorator.rb +21 -0
  28. data/lib/pact_broker/api/decorators/version_decorator.rb +14 -0
  29. data/lib/pact_broker/api/decorators/versions_decorator.rb +1 -1
  30. data/lib/pact_broker/api/pact_broker_urls.rb +41 -2
  31. data/lib/pact_broker/api/renderers/html_pact_renderer.rb +1 -1
  32. data/lib/pact_broker/api/resources/base_resource.rb +11 -2
  33. data/lib/pact_broker/api/resources/latest_verifications_for_consumer_version.rb +39 -0
  34. data/lib/pact_broker/api/resources/pacticipants.rb +1 -1
  35. data/lib/pact_broker/api/resources/previous_distinct_pact_version.rb +1 -1
  36. data/lib/pact_broker/api/resources/verifications.rb +67 -0
  37. data/lib/pact_broker/api/resources/versions.rb +1 -1
  38. data/lib/pact_broker/api/resources/webhooks.rb +1 -1
  39. data/lib/pact_broker/app.rb +0 -2
  40. data/lib/pact_broker/configuration.rb +1 -4
  41. data/lib/pact_broker/doc/views/latest-verifications.markdown +7 -0
  42. data/lib/pact_broker/doc/views/publish-verification.markdown +14 -0
  43. data/lib/pact_broker/domain.rb +1 -1
  44. data/lib/pact_broker/domain/order_versions.rb +5 -15
  45. data/lib/pact_broker/domain/pact.rb +10 -2
  46. data/lib/pact_broker/domain/relationship.rb +31 -4
  47. data/lib/pact_broker/domain/verification.rb +77 -0
  48. data/lib/pact_broker/domain/version.rb +6 -1
  49. data/lib/pact_broker/domain/webhook.rb +1 -0
  50. data/lib/pact_broker/domain/webhook_request.rb +4 -6
  51. data/lib/pact_broker/locale/en.yml +2 -1
  52. data/lib/pact_broker/logging.rb +0 -4
  53. data/lib/pact_broker/pacticipants/repository.rb +1 -2
  54. data/lib/pact_broker/pacticipants/service.rb +11 -5
  55. data/lib/pact_broker/pacts/all_pact_publications.rb +96 -0
  56. data/lib/pact_broker/pacts/all_pacts.rb +4 -89
  57. data/lib/pact_broker/pacts/diff.rb +2 -2
  58. data/lib/pact_broker/pacts/latest_pact_publications.rb +11 -0
  59. data/lib/pact_broker/pacts/latest_pact_publications_by_consumer_version.rb +11 -0
  60. data/lib/pact_broker/pacts/latest_pacts.rb +1 -0
  61. data/lib/pact_broker/pacts/latest_tagged_pact_publications.rb +11 -0
  62. data/lib/pact_broker/pacts/pact_params.rb +11 -1
  63. data/lib/pact_broker/pacts/pact_publication.rb +50 -0
  64. data/lib/pact_broker/pacts/pact_version.rb +39 -0
  65. data/lib/pact_broker/pacts/repository.rb +46 -36
  66. data/lib/pact_broker/pacts/service.rb +2 -2
  67. data/lib/pact_broker/repositories.rb +5 -0
  68. data/lib/pact_broker/services.rb +5 -0
  69. data/lib/pact_broker/ui/view_models/relationship.rb +38 -0
  70. data/lib/pact_broker/ui/views/relationships/show.haml +9 -0
  71. data/lib/pact_broker/verifications/repository.rb +45 -0
  72. data/lib/pact_broker/verifications/service.rb +40 -0
  73. data/lib/pact_broker/version.rb +1 -1
  74. data/lib/pact_broker/versions/parse_semantic_version.rb +9 -6
  75. data/lib/pact_broker/webhooks/service.rb +8 -9
  76. data/lib/pact_broker/webhooks/webhook.rb +1 -1
  77. data/pact_broker.gemspec +3 -4
  78. data/pact_broker_client-pact_broker.json +4 -4
  79. data/script/publish.sh +2 -2
  80. data/script/record_verification.sh +3 -0
  81. data/spec/features/delete_pact_spec.rb +1 -1
  82. data/spec/features/get_verifications_for_consumer_version_spec.rb +33 -0
  83. data/spec/features/publish_verification_spec.rb +28 -0
  84. data/spec/fixtures/a_consumer-a_provider-2.json +1 -1
  85. data/spec/fixtures/a_consumer-a_provider-3.json +1 -1
  86. data/spec/fixtures/a_consumer-a_provider-conflict.json +1 -1
  87. data/spec/fixtures/a_consumer-a_provider-merged.json +2 -2
  88. data/spec/fixtures/a_consumer-a_provider.json +1 -1
  89. data/spec/fixtures/consumer-provider.json +1 -1
  90. data/spec/fixtures/renderer_pact.json +1 -1
  91. data/spec/fixtures/verification.json +4 -0
  92. data/spec/lib/pact_broker/api/contracts/verification_contract_spec.rb +91 -0
  93. data/spec/lib/pact_broker/api/decorators/latest_pact_decorator_spec.rb +0 -18
  94. data/spec/lib/pact_broker/api/decorators/pact_decorator_spec.rb +6 -2
  95. data/spec/lib/pact_broker/api/decorators/pact_version_decorator_spec.rb +0 -3
  96. data/spec/lib/pact_broker/api/decorators/verification_decorator_spec.rb +61 -0
  97. data/spec/lib/pact_broker/api/decorators/verifications_decorator_spec.rb +42 -0
  98. data/spec/lib/pact_broker/api/decorators/version_decorator_spec.rb +4 -0
  99. data/spec/lib/pact_broker/api/renderers/html_pact_renderer_spec.rb +1 -1
  100. data/spec/lib/pact_broker/api/resources/latest_verifications_for_consumer_version_spec.rb +68 -0
  101. data/spec/lib/pact_broker/api/resources/pact_spec.rb +1 -1
  102. data/spec/lib/pact_broker/api/resources/pacticipants_spec.rb +1 -1
  103. data/spec/lib/pact_broker/api/resources/verifications_spec.rb +92 -0
  104. data/spec/lib/pact_broker/api/resources/webhooks_spec.rb +1 -1
  105. data/spec/lib/pact_broker/domain/order_versions_spec.rb +10 -30
  106. data/spec/lib/pact_broker/domain/verification_spec.rb +41 -0
  107. data/spec/lib/pact_broker/domain/version_spec.rb +26 -0
  108. data/spec/lib/pact_broker/domain/webhook_request_spec.rb +1 -3
  109. data/spec/lib/pact_broker/pacticipants/repository_spec.rb +0 -16
  110. data/spec/lib/pact_broker/pacticipants/service_spec.rb +4 -3
  111. data/spec/lib/pact_broker/pacts/pact_params_spec.rb +14 -1
  112. data/spec/lib/pact_broker/pacts/pact_version_spec.rb +50 -0
  113. data/spec/lib/pact_broker/pacts/repository_spec.rb +85 -36
  114. data/spec/lib/pact_broker/ui/view_models/relationship_spec.rb +48 -2
  115. data/spec/lib/pact_broker/verifications/repository_spec.rb +92 -0
  116. data/spec/lib/pact_broker/verifications/service_spec.rb +61 -0
  117. data/spec/lib/pact_broker/versions/parse_semantic_version_spec.rb +39 -0
  118. data/spec/lib/pact_broker/webhooks/service_spec.rb +3 -40
  119. data/spec/migrations/23_pact_versions_spec.rb +95 -0
  120. data/spec/migrations/24_populate_pact_contents_spec.rb +48 -0
  121. data/spec/migrations/34_latest_tagged_pacts_spec.rb +108 -0
  122. data/spec/migrations/34_pact_revisions_spec.rb +106 -0
  123. data/spec/support/database_cleaner.rb +8 -4
  124. data/spec/support/provider_state_builder.rb +22 -8
  125. metadata +81 -36
  126. data/lib/pact_broker/pacts/database_model.rb +0 -35
  127. data/lib/pact_broker/pacts/latest_tagged_pacts.rb +0 -11
  128. data/lib/pact_broker/pacts/pact_version_content.rb +0 -11
  129. data/lib/pact_broker/webhooks/job.rb +0 -46
  130. data/script/foo-bar.json +0 -22
  131. data/script/publish-new.sh +0 -7
  132. data/script/recreate-pg-db.sh +0 -7
  133. data/spec/lib/pact_broker/webhooks/job_spec.rb +0 -67
@@ -22,7 +22,7 @@ module PactBroker
22
22
  end
23
23
 
24
24
  def find_pact params
25
- pact_repository.find_pact(params[:consumer_name], params[:consumer_version_number], params[:provider_name])
25
+ pact_repository.find_pact(params[:consumer_name], params[:consumer_version_number], params[:provider_name], params[:revision_number])
26
26
  end
27
27
 
28
28
  def delete params
@@ -104,7 +104,7 @@ module PactBroker
104
104
 
105
105
  def create_pact params, version, provider
106
106
  logger.info "Creating new pact version with params #{params}"
107
- pact = pact_repository.create json_content: params[:json_content], version_id: version.id, provider_id: provider.id
107
+ pact = pact_repository.create json_content: params[:json_content], version_id: version.id, provider_id: provider.id, consumer_id: version.pacticipant_id
108
108
  trigger_webhooks pact
109
109
  pact
110
110
  end
@@ -27,6 +27,11 @@ module PactBroker
27
27
  Webhooks::Repository.new
28
28
  end
29
29
 
30
+ def verification_repository
31
+ require 'pact_broker/verifications/repository'
32
+ Verifications::Repository.new
33
+ end
34
+
30
35
  extend self
31
36
  end
32
37
  end
@@ -31,5 +31,10 @@ module PactBroker
31
31
  require 'pact_broker/versions/service'
32
32
  Versions::Service
33
33
  end
34
+
35
+ def verification_service
36
+ require 'pact_broker/verifications/service'
37
+ Verifications::Service
38
+ end
34
39
  end
35
40
  end
@@ -1,5 +1,6 @@
1
1
  require 'pact_broker/api/pact_broker_urls'
2
2
  require 'pact_broker/ui/helpers/url_helper'
3
+ require 'pact_broker/date_helper'
3
4
 
4
5
  module PactBroker
5
6
  module UI
@@ -32,6 +33,43 @@ module PactBroker
32
33
  "#{pactigration_base_url('', @relationship)}/latest"
33
34
  end
34
35
 
36
+ def last_verified_date
37
+ if @relationship.ever_verified?
38
+ date = @relationship.latest_verification.execution_date
39
+ PactBroker::DateHelper.distance_of_time_in_words(date, DateTime.now) + " ago"
40
+ else
41
+ ""
42
+ end
43
+ end
44
+
45
+ def verification_status
46
+ return "" unless @relationship.ever_verified?
47
+ if @relationship.latest_verification_successful?
48
+ if @relationship.pact_changed_since_last_verification?
49
+ "warning"
50
+ else
51
+ "success"
52
+ end
53
+ else
54
+ "danger"
55
+ end
56
+ end
57
+
58
+ def warning?
59
+ verification_status == 'warning'
60
+ end
61
+
62
+ def verification_tooltip
63
+ return nil unless @relationship.ever_verified?
64
+ if warning?
65
+ "Pact has changed since last successful verification by #{provider_name} (v#{@relationship.latest_verification_provider_version})"
66
+ elsif @relationship.latest_verification_successful?
67
+ "Successfully verified by #{provider_name} (v#{@relationship.latest_verification_provider_version})"
68
+ elsif !@relationship.latest_verification_successful?
69
+ "Verification by #{provider_name} (v#{@relationship.latest_verification_provider_version}) failed"
70
+ end
71
+ end
72
+
35
73
  def <=> other
36
74
  comp = consumer_name.downcase <=> other.consumer_name.downcase
37
75
  return comp unless comp == 0
@@ -5,6 +5,7 @@
5
5
  %link{rel: 'stylesheet', href: '/stylesheets/relationships.css'}
6
6
  %script{type: 'text/javascript', src:'/javascripts/jquery-2.1.1.min.js'}
7
7
  %script{type: 'text/javascript', src:'/javascripts/jquery.tablesorter.min.js'}
8
+ %script{type: 'text/javascript', src:'/js/bootstrap.min.js'}
8
9
  %body
9
10
  %nav.navbase-default.navbar-right{role: "navigation"}
10
11
  .container
@@ -27,6 +28,8 @@
27
28
  Provider
28
29
  %span.glyphicon.glyphicon-sort.relationships-sort
29
30
  %th
31
+ %th
32
+ Last verified
30
33
  %tbody
31
34
 
32
35
  - relationships.each do | relationship |
@@ -42,6 +45,11 @@
42
45
  %a{:href => relationship.provider_group_url}
43
46
  = relationship.provider_name
44
47
  %td
48
+ %td{class: relationship.verification_status}
49
+ %div{title: relationship.verification_tooltip, "data-toggle": "tooltip", "data-placement": "left"}
50
+ = relationship.last_verified_date
51
+ - if relationship.warning?
52
+ %span.glyphicon.glyphicon-warning-sign{'aria-hidden':true}
45
53
  %div.relationships-size
46
54
  = relationships.size_label
47
55
 
@@ -52,4 +60,5 @@
52
60
 
53
61
  $(document).ready(function(){
54
62
  $("span.pact").load("/images/doc-text.svg");
63
+ $('[data-toggle="tooltip"]').tooltip();
55
64
  });
@@ -0,0 +1,45 @@
1
+ require 'sequel'
2
+ require 'pact_broker/domain/verification'
3
+
4
+ module PactBroker
5
+ module Verifications
6
+ class Repository
7
+
8
+ include PactBroker::Repositories::Helpers
9
+
10
+ class LatestVerifications < PactBroker::Domain::Verification
11
+ set_dataset(:latest_verifications)
12
+ end
13
+
14
+ def create verification, pact
15
+ verification.pact_version_id = pact_version_id_for(pact)
16
+ verification.save
17
+ end
18
+
19
+ def verification_count_for_pact pact
20
+ PactBroker::Domain::Verification.where(pact_version_id: pact_version_id_for(pact)).count
21
+ end
22
+
23
+ def find_latest_verifications_for_consumer_version consumer_name, consumer_version_number
24
+ LatestVerifications
25
+ .join(PactBroker::Pacts::LatestPactPublicationsByConsumerVersion, pact_version_id: :pact_version_id)
26
+ .where(name_like(:consumer_name, consumer_name))
27
+ .where(consumer_version_number: consumer_version_number)
28
+ .order(:provider_name)
29
+ end
30
+
31
+ def find_latest_verification_for consumer_name, provider_name
32
+ query = LatestVerifications
33
+ .join(PactBroker::Pacts::AllPactPublications, pact_version_id: :pact_version_id)
34
+ .consumer(consumer_name)
35
+ .provider(provider_name)
36
+ .latest
37
+ query.first
38
+ end
39
+
40
+ def pact_version_id_for pact
41
+ PactBroker::Pacts::PactPublication.select(:pact_version_id).where(id: pact.id)
42
+ end
43
+ end
44
+ end
45
+ end
@@ -0,0 +1,40 @@
1
+ require 'pact_broker/repositories'
2
+ require 'pact_broker/api/decorators/verification_decorator'
3
+
4
+ module PactBroker
5
+
6
+ module Verifications
7
+ module Service
8
+
9
+ extend self
10
+
11
+ extend PactBroker::Repositories
12
+
13
+ def next_number_for pact
14
+ verification_repository.verification_count_for_pact(pact) + 1
15
+ end
16
+
17
+ def create next_verification_number, params, pact
18
+ PactBroker.logger.info "Creating verification #{next_verification_number} for pact_id=#{pact.id} from params #{params}"
19
+ verification = PactBroker::Domain::Verification.new
20
+ PactBroker::Api::Decorators::VerificationDecorator.new(verification).from_hash(params)
21
+ verification.number = next_verification_number
22
+ verification_repository.create(verification, pact)
23
+ end
24
+
25
+ def errors params
26
+ contract = PactBroker::Api::Contracts::VerificationContract.new(PactBroker::Domain::Verification.new)
27
+ contract.validate(params)
28
+ contract.errors
29
+ end
30
+
31
+ def find_latest_verifications_for_consumer_version params
32
+ verification_repository.find_latest_verifications_for_consumer_version params[:consumer_name], params[:consumer_version_number]
33
+ end
34
+
35
+ def find_latest_verification_for consumer, provider
36
+ verification_repository.find_latest_verification_for consumer.name, provider.name
37
+ end
38
+ end
39
+ end
40
+ end
@@ -1,3 +1,3 @@
1
1
  module PactBroker
2
- VERSION = '1.18.0'
2
+ VERSION = '2.0.0.beta.1'
3
3
  end
@@ -1,17 +1,20 @@
1
- require 'versionomy'
1
+ require 'semver'
2
2
 
3
3
  module PactBroker
4
4
  module Versions
5
5
  class ParseSemanticVersion
6
+ SEMVER_FORMAT = "%M.%m.%p%s%d"
6
7
 
7
8
  def self.call string_version
8
- begin
9
- ::Versionomy.parse(string_version)
10
- rescue ::Versionomy::Errors::ParseError => e
11
- nil
12
- end
9
+ version = ::SemVer.parse(string_version, SEMVER_FORMAT)
10
+ return SemVerWrapper.new(version) unless version.nil?
13
11
  end
14
12
 
13
+ class SemVerWrapper < SimpleDelegator
14
+ def to_s
15
+ format(SEMVER_FORMAT)
16
+ end
17
+ end
15
18
  end
16
19
  end
17
20
  end
@@ -1,8 +1,6 @@
1
1
  require 'pact_broker/repositories'
2
2
  require 'pact_broker/logging'
3
- require 'pact_broker/webhooks/job'
4
3
  require 'base64'
5
- require 'securerandom'
6
4
 
7
5
  module PactBroker
8
6
 
@@ -52,7 +50,6 @@ module PactBroker
52
50
 
53
51
  def self.execute_webhooks pact
54
52
  webhooks = webhook_repository.find_by_consumer_and_provider pact.consumer, pact.provider
55
-
56
53
  if webhooks.any?
57
54
  run_later(webhooks)
58
55
  else
@@ -60,13 +57,15 @@ module PactBroker
60
57
  end
61
58
  end
62
59
 
60
+ # TODO background job?
63
61
  def self.run_later webhooks
64
- webhooks.each do | webhook |
65
- begin
66
- logger.info "Scheduling job for #{webhook.description} with uuid #{webhook.uuid}"
67
- Job.perform_async webhook: webhook
68
- rescue StandardError => e
69
- log_error e
62
+ Thread.new do
63
+ webhooks.each do | webhook |
64
+ begin
65
+ webhook.execute
66
+ rescue StandardError => e
67
+ # Exceptions are already logged, no need to log again.
68
+ end
70
69
  end
71
70
  end
72
71
  end
@@ -46,7 +46,7 @@ module PactBroker
46
46
  end
47
47
 
48
48
  def request_attributes
49
- values.merge(headers: parsed_headers, body: parsed_body, password: plain_text_password, uuid: uuid)
49
+ values.merge(headers: parsed_headers, body: parsed_body, password: plain_text_password)
50
50
  end
51
51
 
52
52
  def plain_text_password
data/pact_broker.gemspec CHANGED
@@ -28,17 +28,16 @@ Gem::Specification.new do |gem|
28
28
  gem.add_runtime_dependency 'dry-validation', '~> 0.10.5'
29
29
  gem.add_runtime_dependency 'sequel', '~> 4.23'
30
30
  gem.add_runtime_dependency 'webmachine', '1.4.0'
31
- gem.add_runtime_dependency 'versionomy', '~> 0.4'
31
+ gem.add_runtime_dependency 'semver2', '~> 3.4.2'
32
32
  gem.add_runtime_dependency 'rack', '< 3.0'
33
33
  gem.add_runtime_dependency 'redcarpet', '~>3.1'
34
34
  gem.add_runtime_dependency 'pact', '~>1.4'
35
35
  gem.add_runtime_dependency 'pact-support', '~>0.4', '>=0.4.2'
36
36
  gem.add_runtime_dependency 'padrino-core', '~>0.12.4'
37
37
  gem.add_runtime_dependency 'haml', '~>4.0'
38
- gem.add_runtime_dependency 'sucker_punch', '~>2.0'
39
38
 
40
- gem.add_development_dependency 'sqlite3'
41
- gem.add_development_dependency 'pry-byebug'
39
+ gem.add_development_dependency 'sqlite3', '~>1.3'
40
+ gem.add_development_dependency 'pry'
42
41
  gem.add_development_dependency 'rake', '~>10.0'
43
42
  gem.add_development_dependency 'fakefs', '~>0.4'
44
43
  gem.add_development_dependency 'mysql2', '~>0.3.15'
@@ -35,7 +35,7 @@
35
35
  },
36
36
  {
37
37
  "description": "a request to publish a pact",
38
- "providerState": "an error occurs while publishing a pact",
38
+ "provider_state": "an error occurs while publishing a pact",
39
39
  "request": {
40
40
  "method": "put",
41
41
  "path": "/pacticipant/Condor/versions/1.3.0/pacts/Pricing%20Service",
@@ -72,7 +72,7 @@
72
72
  },
73
73
  {
74
74
  "description": "a request to retrieve the repository URL of the 'Pricing Service'",
75
- "providerState": "the 'Pricing Service' does not exist in the pact-broker",
75
+ "provider_state": "the 'Pricing Service' does not exist in the pact-broker",
76
76
  "request": {
77
77
  "method": "get",
78
78
  "path": "/pacticipant/Pricing%20Service/repository_url",
@@ -90,7 +90,7 @@
90
90
 
91
91
  {
92
92
  "description": "a request to register the repository URL of a pacticipant",
93
- "providerState": "the 'Pricing Service' does not exist in the pact-broker",
93
+ "provider_state": "the 'Pricing Service' does not exist in the pact-broker",
94
94
  "request": {
95
95
  "method": "patch",
96
96
  "path": "/pacticipant/Pricing%20Service",
@@ -108,7 +108,7 @@
108
108
  },
109
109
  {
110
110
  "description": "a request to retrieve the repository URL of the 'Pricing Service'",
111
- "providerState": "the 'Pricing Service' already exists in the pact-broker",
111
+ "provider_state": "the 'Pricing Service' already exists in the pact-broker",
112
112
  "request": {
113
113
  "method": "get",
114
114
  "path": "/pacticipant/Pricing%20Service/repository_url",
data/script/publish.sh CHANGED
@@ -1,3 +1,3 @@
1
1
  curl -v -XPUT \-H "Content-Type: application/json" \
2
- -d@script/foo-bar.json \
3
- http://127.0.0.1:9292/pacts/provider/Bar/consumer/Foo/version/1.0.0
2
+ -d@spec/fixtures/a_consumer-a_provider.json \
3
+ http://localhost:9292/pacts/provider/A%20Provider/consumer/A%20Consumer/version/1.0.0
@@ -0,0 +1,3 @@
1
+ curl -v -XPOST \-H "Content-Type: application/json" \
2
+ -d@spec/fixtures/record_verification.json \
3
+ http://127.0.0.1:9292/pacts/provider/Animal%20Service/consumer/Zoo%20App/version/1.0.2/verifications
@@ -12,7 +12,7 @@ describe "Deleting a pact" do
12
12
  end
13
13
 
14
14
  it "deletes the pact" do
15
- expect{ subject }.to change{ PactBroker::Pacts::DatabaseModel.count }.by(-1)
15
+ expect{ subject }.to change{ PactBroker::Pacts::PactPublication.count }.by(-1)
16
16
  end
17
17
 
18
18
  it "returns a 204" do
@@ -0,0 +1,33 @@
1
+ require 'spec/support/provider_state_builder'
2
+
3
+ describe "Get verifications for consumer version" do
4
+
5
+ let(:path) { "/pacts/consumer/Consumer/versions/1.2.3/verifications/latest" }
6
+ let(:last_response_body) { JSON.parse(subject.body, symbolize_names: true) }
7
+
8
+ subject { get path; last_response }
9
+
10
+ context "when the consumer exists" do
11
+
12
+ before do
13
+ ProviderStateBuilder.new
14
+ .create_provider("Provider")
15
+ .create_consumer("Consumer")
16
+ .create_consumer_version("1.2.3")
17
+ .create_pact
18
+ .create_verification(number: 1)
19
+ .create_verification(number: 2)
20
+ .create_provider("Another provider")
21
+ .create_pact
22
+ .create_verification(number: 1)
23
+ end
24
+
25
+ it "returns a 200 HAL JSON response" do
26
+ expect(subject).to be_a_hal_json_success_response
27
+ end
28
+
29
+ it "returns a list of verifications" do
30
+ expect(last_response_body[:_embedded][:verifications].size).to eq 2
31
+ end
32
+ end
33
+ end
@@ -0,0 +1,28 @@
1
+ require 'pact_broker/domain/verification'
2
+
3
+ describe "Recording a pact verification" do
4
+
5
+ let(:path) { "/pacts/provider/Provider/consumer/Consumer/pact-version/#{pact.pact_version_sha}/verifications" }
6
+ let(:verification_content) { load_fixture('verification.json') }
7
+ let(:parsed_response_body) { JSON.parse(subject.body) }
8
+
9
+ subject { post path, verification_content, {'CONTENT_TYPE' => 'application/json' }; last_response }
10
+
11
+ let(:pact) do
12
+ ProviderStateBuilder.new
13
+ .create_provider("Provider")
14
+ .create_consumer("Consumer")
15
+ .create_consumer_version("1.2.3")
16
+ .create_pact
17
+ .revise_pact
18
+ .and_return(:pact)
19
+ end
20
+
21
+ it "Responds with a 201 Created" do
22
+ expect(subject.status).to be 201
23
+ end
24
+
25
+ it "saves a verification against the pact" do
26
+ expect { subject }.to change { PactBroker::Domain::Verification.count }.by(1)
27
+ end
28
+ end