pact_broker 2.75.0 → 2.78.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (193) hide show
  1. checksums.yaml +4 -4
  2. data/.codeclimate.yml +12 -0
  3. data/.github/workflows/test-ruby-3.yml +19 -0
  4. data/.github/workflows/test.yml +19 -4
  5. data/.gitignore +3 -1
  6. data/CHANGELOG.md +48 -0
  7. data/DEVELOPER_SETUP.md +62 -3
  8. data/Dockerfile +1 -0
  9. data/ISSUES.md +13 -5
  10. data/README.md +1 -1
  11. data/config.ru +1 -0
  12. data/db/ddl_statements/head_pact_tags.rb +24 -1
  13. data/db/ddl_statements/latest_tagged_pact_consumer_version_orders.rb +11 -0
  14. data/db/ddl_statements/latest_tagged_pact_publications.rb +6 -0
  15. data/db/ddl_statements/latest_verification_ids_for_consumer_version_tags.rb +13 -0
  16. data/db/migrations/20210117_add_branch_to_version.rb +9 -0
  17. data/db/migrations/20210202_add_created_at_to_head_pact_tags.rb +14 -0
  18. data/db/migrations/20210205_add_pacticipant_id_to_tag.rb +17 -0
  19. data/db/migrations/20210206_add_index_to_tags_and_versions.rb +27 -0
  20. data/db/migrations/20210207_optimise_latest_verification_ids_for_consumer_version_tags.rb +13 -0
  21. data/db/migrations/20210208_optimise_latest_tagged_pact_cv_orders.rb +13 -0
  22. data/db/migrations/20210210_create_environments_table.rb +16 -0
  23. data/docker-compose-issue-repro-with-pact-broker-docker-image.yml +44 -0
  24. data/lib/pact_broker/api.rb +7 -2
  25. data/lib/pact_broker/api/contracts/dry_validation_predicates.rb +8 -0
  26. data/lib/pact_broker/api/contracts/environment_schema.rb +49 -0
  27. data/lib/pact_broker/api/decorators/base_decorator.rb +11 -0
  28. data/lib/pact_broker/api/decorators/dashboard_decorator.rb +5 -1
  29. data/lib/pact_broker/api/decorators/environment_decorator.rb +30 -0
  30. data/lib/pact_broker/api/decorators/environments_decorator.rb +21 -0
  31. data/lib/pact_broker/api/decorators/matrix_decorator.rb +8 -2
  32. data/lib/pact_broker/api/decorators/reason_decorator.rb +2 -2
  33. data/lib/pact_broker/api/decorators/verifiable_pacts_query_decorator.rb +2 -0
  34. data/lib/pact_broker/api/decorators/version_decorator.rb +15 -2
  35. data/lib/pact_broker/api/pact_broker_urls.rb +8 -0
  36. data/lib/pact_broker/api/paths.rb +5 -0
  37. data/lib/pact_broker/api/resources/default_base_resource.rb +15 -2
  38. data/lib/pact_broker/api/resources/environment.rb +76 -0
  39. data/lib/pact_broker/api/resources/environments.rb +75 -0
  40. data/lib/pact_broker/api/resources/index.rb +20 -0
  41. data/lib/pact_broker/api/resources/latest_version.rb +27 -0
  42. data/lib/pact_broker/api/resources/provider_pacts_for_verification.rb +1 -0
  43. data/lib/pact_broker/api/resources/verifications.rb +5 -2
  44. data/lib/pact_broker/api/resources/version.rb +15 -9
  45. data/lib/pact_broker/api/resources/webhook_execution.rb +1 -1
  46. data/lib/pact_broker/app.rb +3 -0
  47. data/lib/pact_broker/certificates/certificate.rb +1 -1
  48. data/lib/pact_broker/config/setting.rb +1 -1
  49. data/lib/pact_broker/config/space_delimited_integer_list.rb +25 -0
  50. data/lib/pact_broker/configuration.rb +18 -1
  51. data/lib/pact_broker/db/data_migrations/helpers.rb +4 -0
  52. data/lib/pact_broker/db/data_migrations/set_extra_columns_for_tags.rb +29 -0
  53. data/lib/pact_broker/db/migrate_data.rb +1 -0
  54. data/lib/pact_broker/db/seed_example_data.rb +13 -13
  55. data/lib/pact_broker/deployments/environment.rb +15 -0
  56. data/lib/pact_broker/deployments/environment_service.rb +39 -0
  57. data/lib/pact_broker/doc/controllers/app.rb +1 -1
  58. data/lib/pact_broker/doc/views/index/environment.markdown +37 -0
  59. data/lib/pact_broker/doc/views/index/environments.markdown +53 -0
  60. data/lib/pact_broker/doc/views/index/latest-pact-versions.markdown +1 -1
  61. data/lib/pact_broker/doc/views/index/pacticipant-version-tag.markdown +1 -0
  62. data/lib/pact_broker/doc/views/index/pacticipant-version.markdown +13 -0
  63. data/lib/pact_broker/domain/index_item.rb +18 -4
  64. data/lib/pact_broker/domain/pacticipant.rb +9 -5
  65. data/lib/pact_broker/domain/tag.rb +131 -71
  66. data/lib/pact_broker/domain/verification.rb +3 -2
  67. data/lib/pact_broker/domain/version.rb +58 -23
  68. data/lib/pact_broker/domain/webhook.rb +12 -9
  69. data/lib/pact_broker/hash_refinements.rb +4 -0
  70. data/lib/pact_broker/index/service.rb +55 -49
  71. data/lib/pact_broker/locale/en.yml +3 -1
  72. data/lib/pact_broker/matrix/quick_row.rb +8 -0
  73. data/lib/pact_broker/metrics/service.rb +1 -1
  74. data/lib/pact_broker/pacts/eager_loaders.rb +52 -0
  75. data/lib/pact_broker/pacts/latest_pact_publication_id_for_consumer_version.rb +18 -13
  76. data/lib/pact_broker/pacts/lazy_loaders.rb +14 -0
  77. data/lib/pact_broker/pacts/pact_publication.rb +38 -84
  78. data/lib/pact_broker/pacts/pact_publication_dataset_module.rb +297 -0
  79. data/lib/pact_broker/pacts/pact_version.rb +1 -2
  80. data/lib/pact_broker/pacts/pacts_for_verification_repository.rb +286 -0
  81. data/lib/pact_broker/pacts/repository.rb +5 -231
  82. data/lib/pact_broker/pacts/selected_pact.rb +4 -0
  83. data/lib/pact_broker/pacts/selector.rb +56 -1
  84. data/lib/pact_broker/pacts/selectors.rb +16 -0
  85. data/lib/pact_broker/pacts/service.rb +6 -8
  86. data/lib/pact_broker/pacts/squash_pacts_for_verification.rb +1 -4
  87. data/lib/pact_broker/pacts/verifiable_pact.rb +45 -2
  88. data/lib/pact_broker/pacts/verifiable_pact_messages.rb +56 -16
  89. data/lib/pact_broker/repositories/helpers.rb +4 -0
  90. data/lib/pact_broker/services.rb +9 -0
  91. data/lib/pact_broker/tags/eager_loaders.rb +47 -0
  92. data/lib/pact_broker/tags/repository.rb +3 -1
  93. data/lib/pact_broker/tags/service.rb +0 -3
  94. data/lib/pact_broker/tags/tag_with_latest_flag.rb +1 -0
  95. data/lib/pact_broker/test/http_test_data_builder.rb +101 -35
  96. data/lib/pact_broker/test/test_data_builder.rb +50 -3
  97. data/lib/pact_broker/ui/app.rb +6 -0
  98. data/lib/pact_broker/ui/controllers/base_controller.rb +5 -1
  99. data/lib/pact_broker/ui/controllers/pacts.rb +18 -0
  100. data/lib/pact_broker/ui/view_models/index_item.rb +9 -0
  101. data/lib/pact_broker/ui/view_models/matrix_line.rb +36 -0
  102. data/lib/pact_broker/ui/views/index/show-with-tags.haml +8 -0
  103. data/lib/pact_broker/ui/views/matrix/show.haml +10 -0
  104. data/lib/pact_broker/verifications/latest_verification_id_for_pact_version_and_provider_version.rb +7 -5
  105. data/lib/pact_broker/verifications/service.rb +2 -1
  106. data/lib/pact_broker/version.rb +1 -1
  107. data/lib/pact_broker/versions/eager_loaders.rb +71 -0
  108. data/lib/pact_broker/versions/lazy_loaders.rb +13 -0
  109. data/lib/pact_broker/versions/repository.rb +22 -2
  110. data/lib/pact_broker/versions/service.rb +5 -1
  111. data/lib/pact_broker/webhooks/execution.rb +3 -2
  112. data/lib/pact_broker/webhooks/latest_triggered_webhook.rb +2 -0
  113. data/lib/pact_broker/webhooks/pact_and_verification_parameters.rb +10 -3
  114. data/lib/pact_broker/webhooks/service.rb +8 -7
  115. data/lib/pact_broker/webhooks/trigger_service.rb +56 -23
  116. data/lib/pact_broker/webhooks/triggered_webhook.rb +14 -5
  117. data/lib/pact_broker/webhooks/webhook.rb +1 -1
  118. data/lib/pact_broker/webhooks/webhook_event.rb +1 -1
  119. data/lib/pact_broker/webhooks/webhook_execution_result.rb +4 -1
  120. data/lib/pact_broker/webhooks/webhook_request_logger.rb +5 -1
  121. data/lib/rack/pact_broker/set_base_url.rb +22 -0
  122. data/lib/sequel/plugins/upsert.rb +18 -4
  123. data/public/stylesheets/index.css +22 -1
  124. data/public/stylesheets/matrix.css +0 -21
  125. data/regression/can_i_deploy_spec.rb +5 -4
  126. data/regression/index_spec.rb +26 -0
  127. data/regression/regression_helper.rb +29 -3
  128. data/regression/script/clear.sh +3 -0
  129. data/regression/script/run.sh +3 -0
  130. data/script/demonstrate-version-branches.rb +33 -0
  131. data/script/pry.rb +2 -2
  132. data/script/reproduce-issue-starting-up.rb +13 -23
  133. data/script/reproduce-issue.rb +18 -14
  134. data/script/trigger-release.sh +1 -1
  135. data/script/webhook-server.ru +5 -5
  136. data/spec/features/create_environment_spec.rb +47 -0
  137. data/spec/features/create_tag_spec.rb +32 -0
  138. data/spec/features/create_version_spec.rb +70 -0
  139. data/spec/features/delete_environment_spec.rb +16 -0
  140. data/spec/features/end_deployment_spec.rb +29 -0
  141. data/spec/features/get_environment_spec.rb +19 -0
  142. data/spec/features/get_environments_spec.rb +20 -0
  143. data/spec/features/record_deployment_spec.rb +28 -0
  144. data/spec/features/update_environment_spec.rb +44 -0
  145. data/spec/fixtures/approvals/modifiable_resources.approved.json +6 -0
  146. data/spec/fixtures/dashboard.json +4 -2
  147. data/spec/integration/ui/index_spec.rb +4 -4
  148. data/spec/lib/pact_broker/api/contracts/environment_schema_spec.rb +83 -0
  149. data/spec/lib/pact_broker/api/decorators/dashboard_decorator_spec.rb +4 -2
  150. data/spec/lib/pact_broker/api/decorators/matrix_decorator_spec.rb +11 -6
  151. data/spec/lib/pact_broker/api/decorators/reason_decorator_spec.rb +6 -6
  152. data/spec/lib/pact_broker/api/decorators/verifiable_pacts_query_decorator_spec.rb +6 -0
  153. data/spec/lib/pact_broker/api/decorators/version_decorator_spec.rb +18 -0
  154. data/spec/lib/pact_broker/api/resources/default_base_resource_approval_spec.rb +1 -1
  155. data/spec/lib/pact_broker/api/resources/default_base_resource_spec.rb +1 -12
  156. data/spec/lib/pact_broker/api/resources/provider_pacts_for_verification_spec.rb +4 -0
  157. data/spec/lib/pact_broker/api/resources/verifications_spec.rb +2 -5
  158. data/spec/lib/pact_broker/api/resources/webhook_execution_result_spec.rb +56 -0
  159. data/spec/lib/pact_broker/api/resources/webhook_execution_spec.rb +3 -2
  160. data/spec/lib/pact_broker/config/space_delimited_integer_list_spec.rb +47 -0
  161. data/spec/lib/pact_broker/configuration_spec.rb +12 -0
  162. data/spec/lib/pact_broker/doc/controllers/app_spec.rb +3 -5
  163. data/spec/lib/pact_broker/domain/tag_spec.rb +101 -27
  164. data/spec/lib/pact_broker/domain/version_spec.rb +103 -15
  165. data/spec/lib/pact_broker/domain/webhook_spec.rb +7 -7
  166. data/spec/lib/pact_broker/index/service_spec.rb +89 -15
  167. data/spec/lib/pact_broker/pacts/pact_publication_dataset_module_spec.rb +400 -0
  168. data/spec/lib/pact_broker/pacts/pact_publication_spec.rb +434 -14
  169. data/spec/lib/pact_broker/pacts/repository_find_for_verification_fallback_spec.rb +1 -1
  170. data/spec/lib/pact_broker/pacts/repository_find_for_verification_spec.rb +1 -1
  171. data/spec/lib/pact_broker/pacts/repository_find_wip_pact_versions_for_provider_branch_spec.rb +224 -0
  172. data/spec/lib/pact_broker/pacts/repository_find_wip_pact_versions_for_provider_spec.rb +46 -7
  173. data/spec/lib/pact_broker/pacts/selector_spec.rb +3 -2
  174. data/spec/lib/pact_broker/pacts/service_find_for_verification_spec.rb +2 -3
  175. data/spec/lib/pact_broker/pacts/service_spec.rb +9 -7
  176. data/spec/lib/pact_broker/pacts/verifiable_pact_messages_spec.rb +57 -10
  177. data/spec/lib/pact_broker/tags/repository_spec.rb +2 -0
  178. data/spec/lib/pact_broker/verifications/service_spec.rb +4 -1
  179. data/spec/lib/pact_broker/versions/repository_spec.rb +54 -0
  180. data/spec/lib/pact_broker/webhooks/render_spec.rb +6 -5
  181. data/spec/lib/pact_broker/webhooks/service_spec.rb +13 -9
  182. data/spec/lib/pact_broker/webhooks/trigger_service_spec.rb +60 -18
  183. data/spec/lib/pact_broker/webhooks/webhook_request_logger_spec.rb +8 -0
  184. data/spec/lib/sequel/plugins/upsert_spec.rb +31 -3
  185. data/spec/service_consumers/hal_relation_proxy_app.rb +3 -1
  186. data/spec/service_consumers/provider_states_for_pact_broker_client.rb +16 -0
  187. data/spec/spec_helper.rb +17 -5
  188. data/spec/support/approvals.rb +24 -0
  189. data/spec/support/shared_examples_for_responses.rb +11 -0
  190. data/tasks/db.rake +1 -0
  191. data/tasks/rspec.rake +1 -1
  192. metadata +69 -4
  193. data/docker-compose-issue-repro.yml +0 -22
@@ -0,0 +1,44 @@
1
+ require 'pact_broker/api/pact_broker_urls'
2
+
3
+ describe "Updating an environment" do
4
+ before do
5
+ td.create_environment("test", uuid: "1234", contacts: [ { name: "Foo" } ] )
6
+ end
7
+ let(:path) { PactBroker::Api::PactBrokerUrls.environment_url(td.and_return(:environment)) }
8
+ let(:headers) { {'CONTENT_TYPE' => 'application/json'} }
9
+ let(:response_body) { JSON.parse(last_response.body, symbolize_names: true)}
10
+ let(:environment_hash) do
11
+ {
12
+ name: "test",
13
+ production: false,
14
+ displayName: "Testing"
15
+ }
16
+ end
17
+
18
+ subject { put(path, environment_hash.to_json, headers) }
19
+
20
+ it { is_expected.to be_a_hal_json_success_response }
21
+
22
+ it "returns the updated environment" do
23
+ subject
24
+ expect(response_body[:displayName]).to eq "Testing"
25
+ expect(response_body[:contacts]).to be nil
26
+ end
27
+
28
+ context "when the environment doesn't exist" do
29
+ let(:path) { "/environments/5678" }
30
+
31
+ it "returns a 404" do
32
+ expect(subject.status).to eq 404
33
+ end
34
+ end
35
+
36
+ context "with invalid params" do
37
+ let(:environment_hash) { {} }
38
+
39
+ it "returns a 400 response" do
40
+ expect(subject.status).to be 400
41
+ expect(response_body[:errors]).to_not be nil
42
+ end
43
+ end
44
+ end
@@ -6,6 +6,12 @@
6
6
  {
7
7
  "resource_class_name": "PactBroker::Api::Resources::Clean"
8
8
  },
9
+ {
10
+ "resource_class_name": "PactBroker::Api::Resources::Environment"
11
+ },
12
+ {
13
+ "resource_class_name": "PactBroker::Api::Resources::Environments"
14
+ },
9
15
  {
10
16
  "resource_class_name": "PactBroker::Api::Resources::ErrorTest"
11
17
  },
@@ -20,7 +20,8 @@
20
20
  "href": "consumer_version_url"
21
21
  }
22
22
  },
23
- "number": "1"
23
+ "number": "1",
24
+ "branch": "main"
24
25
  }
25
26
  },
26
27
  "latestVerificationResult": {
@@ -73,7 +74,8 @@
73
74
  },
74
75
  "name": "Bar",
75
76
  "version": {
76
- "number": "2"
77
+ "number": "2",
78
+ "branch": "main"
77
79
  }
78
80
  },
79
81
  "verificationStatus": "wiffle",
@@ -14,7 +14,9 @@ describe "UI index" do
14
14
  get "/"
15
15
  end
16
16
 
17
- subject { get("/", params, {}); last_response }
17
+ let(:rack_env) { {} }
18
+
19
+ subject { get("/", params, rack_env) }
18
20
 
19
21
  describe "GET" do
20
22
  it "returns a success response" do
@@ -40,9 +42,7 @@ describe "UI index" do
40
42
  end
41
43
 
42
44
  context "with the base_url set" do
43
- before do
44
- allow(PactBroker.configuration).to receive(:base_url).and_return('http://example.org/pact-broker')
45
- end
45
+ let(:rack_env) { { "pactbroker.base_url" => "http://example.org/pact-broker"} }
46
46
 
47
47
  it "returns absolute links" do
48
48
  expect(subject.body).to include "href='http://example.org/pact-broker/stylesheets"
@@ -0,0 +1,83 @@
1
+ require 'pact_broker/api/contracts/environment_schema'
2
+
3
+ module PactBroker
4
+ module Api
5
+ module Contracts
6
+ describe EnvironmentSchema do
7
+ before do
8
+ allow(PactBroker::Deployments::EnvironmentService).to receive(:find_by_name).and_return(existing_environment)
9
+ end
10
+ let(:existing_environment) { nil }
11
+ let(:name) { "test" }
12
+
13
+ let(:params) do
14
+ {
15
+ uuid: "1234",
16
+ name: name,
17
+ displayName: "Test",
18
+ production: false,
19
+ contacts: contacts
20
+ }
21
+ end
22
+
23
+ let(:contacts) do
24
+ [{
25
+ name: "Foo",
26
+ details: { email: "foo@bar.com" }
27
+ }]
28
+ end
29
+
30
+ subject { EnvironmentSchema.call(params) }
31
+
32
+ context "with valid params" do
33
+ it { is_expected.to be_empty }
34
+ end
35
+
36
+ context "with a name with a new line" do
37
+ let(:name) { "test 1" }
38
+
39
+ it { is_expected.to_not be_empty }
40
+ end
41
+
42
+ context "with empty params" do
43
+ let(:params) { {} }
44
+
45
+ it { is_expected.to_not be_empty }
46
+ end
47
+
48
+ context "when there is another environment with the same name but a different uuid" do
49
+ let(:existing_environment) { instance_double("PactBroker::Deployments::Environment", uuid: "5678")}
50
+
51
+ its([:name]) { is_expected.to eq ["Another environment with name 'test' already exists."] }
52
+ end
53
+
54
+ context "when there is another environment with the same name and same uuid" do
55
+ let(:existing_environment) { instance_double("PactBroker::Deployments::Environment", uuid: "1234")}
56
+
57
+ it { is_expected.to be_empty }
58
+ end
59
+
60
+ context "with no owner name" do
61
+ let(:contacts) do
62
+ [{
63
+ details: { email: "foo@bar.com" }
64
+ }]
65
+ end
66
+
67
+ its([:contacts, 0]) { is_expected.to eq "name is missing at index 0" }
68
+ end
69
+
70
+ context "with string contact details" do
71
+ let(:contacts) do
72
+ [{
73
+ name: "foo",
74
+ details: "foo"
75
+ }]
76
+ end
77
+
78
+ its([:contacts, 0]) { is_expected.to eq "details must be a hash at index 0" }
79
+ end
80
+ end
81
+ end
82
+ end
83
+ end
@@ -21,7 +21,9 @@ module PactBroker
21
21
  webhook_status: 'blah',
22
22
  pseudo_branch_verification_status: 'wiffle',
23
23
  provider_version_number: provider_version.number,
24
+ provider_version_branch: provider_version.branch,
24
25
  consumer_version_number: consumer_version.number,
26
+ consumer_version_branch: consumer_version.branch,
25
27
  tag_names: ['prod'],
26
28
  latest_verification_latest_tags: [double('tag', name: 'dev', latest?: true)]
27
29
  )
@@ -30,8 +32,8 @@ module PactBroker
30
32
  let(:provider) { instance_double('PactBroker::Domain::Pacticipant', name: 'Bar') }
31
33
  let(:pact) { instance_double('PactBroker::Domain::Pact', created_at: created_at) }
32
34
  let(:verification) { instance_double('PactBroker::Domain::Verification', success: true, created_at: created_at) }
33
- let(:consumer_version) { instance_double('PactBroker::Domain::Version', number: '1', pacticipant: consumer) }
34
- let(:provider_version) { instance_double('PactBroker::Domain::Version', number: '2', pacticipant: provider) }
35
+ let(:consumer_version) { instance_double('PactBroker::Domain::Version', number: '1', pacticipant: consumer, branch: "main") }
36
+ let(:provider_version) { instance_double('PactBroker::Domain::Version', number: '2', pacticipant: provider, branch: "main") }
35
37
  let(:last_webhook_execution_date) { created_at }
36
38
  let(:base_url) { 'http://example.org' }
37
39
  let(:options) { { user_options: { base_url: base_url } } }
@@ -1,6 +1,7 @@
1
1
  require 'pact_broker/api/decorators/matrix_decorator'
2
2
  require 'pact_broker/matrix/query_results_with_deployment_status_summary'
3
3
  require 'pact_broker/matrix/deployment_status_summary'
4
+ require 'pact_broker/matrix/quick_row'
4
5
 
5
6
  module PactBroker
6
7
  module Api
@@ -12,37 +13,39 @@ module PactBroker
12
13
  let(:row_1_success) { true }
13
14
  let(:row_2_success) { true }
14
15
  let(:row_1) do
15
- double('PactBroker::Matrix::Row',
16
+ instance_double('PactBroker::Matrix::QuickRow',
16
17
  {
17
18
  consumer_name: "Consumer",
18
19
  consumer_version_number: "1.0.0",
20
+ consumer_version_branch: "main",
19
21
  consumer_version_tags: consumer_version_tags,
20
22
  provider_version_tags: provider_version_tags,
21
23
  pact_version_sha: "1234",
22
24
  pact_created_at: pact_created_at,
23
25
  provider_version_number: "4.5.6",
26
+ provider_version_branch: "feat/x",
24
27
  provider_name: "Provider",
25
28
  success: row_1_success,
26
29
  verification_number: 1,
27
- verification_build_url: nil,
28
30
  verification_executed_at: verification_date
29
31
  }
30
32
  )
31
33
  end
32
34
 
33
35
  let(:row_2) do
34
- double('PactBroker::Matrix::Row',
36
+ instance_double('PactBroker::Matrix::QuickRow',
35
37
  {
36
38
  consumer_name: "Consumer",
37
39
  consumer_version_number: "1.0.0",
40
+ consumer_version_branch: "main",
38
41
  consumer_version_tags: [],
39
42
  pact_version_sha: "1234",
40
43
  pact_created_at: pact_created_at,
41
44
  provider_version_number: nil,
45
+ provider_version_branch: nil,
42
46
  provider_name: "Provider",
43
47
  success: row_2_success,
44
48
  verification_number: nil,
45
- verification_build_url: nil,
46
49
  verification_executed_at: verification_date
47
50
  }
48
51
  )
@@ -58,6 +61,7 @@ module PactBroker
58
61
  },
59
62
  version: {
60
63
  number: '1.0.0',
64
+ branch: 'main',
61
65
  _links: {
62
66
  self: {
63
67
  href: 'http://example.org/pacticipants/Consumer/versions/1.0.0'
@@ -88,6 +92,7 @@ module PactBroker
88
92
  },
89
93
  version: {
90
94
  number: '4.5.6',
95
+ branch: 'feat/x',
91
96
  _links: {
92
97
  self: {
93
98
  href: 'http://example.org/pacticipants/Provider/versions/4.5.6'
@@ -135,7 +140,7 @@ module PactBroker
135
140
 
136
141
  let(:consumer_version_tags) do
137
142
  [
138
- double("tag", name: "prod", latest?: true, version: consumer_version)
143
+ double("tag", name: "prod", latest?: true, version: consumer_version, created_at: DateTime.now )
139
144
  ]
140
145
  end
141
146
 
@@ -143,7 +148,7 @@ module PactBroker
143
148
 
144
149
  let(:provider_version_tags) do
145
150
  [
146
- double("tag", name: "master", latest?: false, version: provider_version)
151
+ double("tag", name: "master", latest?: false, version: provider_version, created_at: DateTime.now)
147
152
  ]
148
153
  end
149
154
 
@@ -5,17 +5,17 @@ module PactBroker
5
5
  module Api
6
6
  module Decorators
7
7
  describe ReasonDecorator do
8
-
9
- REASON_CLASSES = ObjectSpace.each_object(Class).select { |klass| klass < PactBroker::Matrix::Reason }
8
+ REASON_CLASSES = ObjectSpace.each_object(Class).select { |klass| klass < PactBroker::Matrix::Reason && klass.name&.start_with?("PactBroker") }
10
9
 
11
10
  describe "the number of Reason classes" do
12
- it "is 9 - add another spec here if a new Reason is added" do
13
- expect(REASON_CLASSES.size).to eq 10
11
+ let(:expected_number_of_reason_classes) { 10 }
12
+
13
+ it "is 10 - add another spec here if a new Reason is added" do
14
+ expect(REASON_CLASSES.size).to eq expected_number_of_reason_classes
14
15
  end
15
16
  end
16
17
 
17
18
  describe "#to_s" do
18
-
19
19
  let(:consumer_selector) { double('consumer selector', description: "version 2 of Foo") }
20
20
  let(:provider_selector) { double('provider selector', description: "version 6 of Bar") }
21
21
  let(:selectors) { [consumer_selector, provider_selector] }
@@ -38,7 +38,7 @@ module PactBroker
38
38
  context "when the reason is PactBroker::Matrix::VerificationFailed" do
39
39
  let(:reason) { PactBroker::Matrix::VerificationFailed.new(*selectors) }
40
40
 
41
- its(:to_s) { is_expected.to eq "The verification between version 2 of Foo and version 6 of Bar failed" }
41
+ its(:to_s) { is_expected.to eq "The verification for the pact between version 2 of Foo and version 6 of Bar failed" }
42
42
  end
43
43
 
44
44
  context "when the reason is PactBroker::Matrix::NoDependenciesMissing" do
@@ -6,6 +6,7 @@ module PactBroker
6
6
  describe VerifiablePactsQueryDecorator do
7
7
 
8
8
  let(:provider_version_tags) { %w[dev] }
9
+ let(:provider_version_branch) { "main" }
9
10
 
10
11
  subject { VerifiablePactsQueryDecorator.new(OpenStruct.new).from_hash(params) }
11
12
 
@@ -13,6 +14,7 @@ module PactBroker
13
14
  let(:params) do
14
15
  {
15
16
  "providerVersionTags" => provider_version_tags,
17
+ "providerVersionBranch" => provider_version_branch,
16
18
  "consumerVersionSelectors" => consumer_version_selectors
17
19
  }
18
20
  end
@@ -25,6 +27,10 @@ module PactBroker
25
27
  expect(subject.consumer_version_selectors).to be_a(PactBroker::Pacts::Selectors)
26
28
  end
27
29
 
30
+ it "parses the provider version branch" do
31
+ expect(subject.provider_version_branch).to eq "main"
32
+ end
33
+
28
34
  context "when latest is not specified" do
29
35
  let(:consumer_version_selectors) do
30
36
  [{ "tag" => "dev" }]
@@ -6,6 +6,24 @@ module PactBroker
6
6
  module Decorators
7
7
  describe VersionDecorator do
8
8
 
9
+ describe "from_json" do
10
+ let(:hash) do
11
+ {
12
+ branch: "branch",
13
+ buildUrl: "buildUrl",
14
+ tags: [{ name: "main" }]
15
+ }
16
+ end
17
+
18
+ subject { VersionDecorator.new(OpenStruct.new).from_json(hash.to_json) }
19
+
20
+ it "sets the properties" do
21
+ expect(subject.branch).to eq "branch"
22
+ expect(subject.build_url).to eq "buildUrl"
23
+ expect(subject.tags.first.name).to eq "main"
24
+ end
25
+ end
26
+
9
27
  let(:version) do
10
28
  TestDataBuilder.new
11
29
  .create_consumer("Consumer")
@@ -45,7 +45,7 @@ module PactBroker
45
45
  if resource.respond_to?(:policy_pacticipant)
46
46
  resource_class_data[:resource_class_data] = resource.policy_pacticipant
47
47
  end
48
- resource_class_data
48
+ resource_class_data
49
49
  else
50
50
  nil
51
51
  end
@@ -90,7 +90,6 @@ module PactBroker
90
90
  describe "base_url" do
91
91
  before do
92
92
  allow(env).to receive(:[]).with("pactbroker.base_url").and_return("http://rack")
93
- allow(PactBroker.configuration).to receive(:base_url).and_return("http://foo")
94
93
  end
95
94
 
96
95
  context "when pactbroker.base_url is set on the env" do
@@ -99,20 +98,10 @@ module PactBroker
99
98
  end
100
99
  end
101
100
 
102
- context "when PactBroker.configuration.base_url is not nil" do
101
+ context "when the rack env value is not set" do
103
102
  before do
104
103
  allow(env).to receive(:[]).with("pactbroker.base_url").and_return(nil)
105
104
  end
106
- it "returns the configured base URL" do
107
- expect(subject.base_url).to eq "http://foo"
108
- end
109
- end
110
-
111
- context "when PactBroker.configuration.base_url is nil and the rack env value is not set" do
112
- before do
113
- allow(env).to receive(:[]).with("pactbroker.base_url").and_return(nil)
114
- allow(PactBroker.configuration).to receive(:base_url).and_return(nil)
115
- end
116
105
 
117
106
  it "returns the base URL from the request" do
118
107
  expect(subject.base_url).to eq "http://example.org"
@@ -16,6 +16,7 @@ module PactBroker
16
16
  let(:decorator) { instance_double('PactBroker::Api::Decorators::VerifiablePactsDecorator') }
17
17
  let(:query) do
18
18
  {
19
+ provider_version_branch: "main",
19
20
  provider_version_tags: ['master'],
20
21
  consumer_version_selectors: [ { tag: 'dev', latest: 'true' }],
21
22
  include_pending_status: 'true',
@@ -30,6 +31,7 @@ module PactBroker
30
31
  # Naughty not mocking out the query parsing...
31
32
  expect(PactBroker::Pacts::Service).to receive(:find_for_verification).with(
32
33
  "Bar",
34
+ "main",
33
35
  ["master"],
34
36
  PactBroker::Pacts::Selectors.new([PactBroker::Pacts::Selector.latest_for_tag("dev")]),
35
37
  {
@@ -56,6 +58,7 @@ module PactBroker
56
58
  describe "POST" do
57
59
  let(:request_body) do
58
60
  {
61
+ providerVersionBranch: "main",
59
62
  providerVersionTags: ['master'],
60
63
  consumerVersionSelectors: [ { tag: 'dev', latest: true }],
61
64
  includePendingStatus: true,
@@ -76,6 +79,7 @@ module PactBroker
76
79
  # Naughty not mocking out the query parsing...
77
80
  expect(PactBroker::Pacts::Service).to receive(:find_for_verification).with(
78
81
  "Bar",
82
+ "main",
79
83
  ["master"],
80
84
  PactBroker::Pacts::Selectors.new([PactBroker::Pacts::Selector.latest_for_tag("dev")]),
81
85
  {