pact_broker 2.76.2 → 2.79.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (172) hide show
  1. checksums.yaml +4 -4
  2. data/.codeclimate.yml +12 -0
  3. data/.github/workflows/release_gem.yml +1 -0
  4. data/.github/workflows/test-ruby-3.yml +19 -0
  5. data/.github/workflows/test.yml +16 -7
  6. data/.gitignore +3 -1
  7. data/CHANGELOG.md +53 -0
  8. data/DEVELOPER_DOCUMENTATION.md +13 -0
  9. data/DEVELOPER_SETUP.md +62 -3
  10. data/Dockerfile +1 -0
  11. data/ISSUES.md +7 -7
  12. data/config.ru +2 -1
  13. data/db/ddl_statements/head_pact_tags.rb +24 -1
  14. data/db/ddl_statements/latest_tagged_pact_consumer_version_orders.rb +11 -0
  15. data/db/ddl_statements/latest_tagged_pact_publications.rb +6 -0
  16. data/db/ddl_statements/latest_verification_ids_for_consumer_version_tags.rb +13 -0
  17. data/db/migrations/20210117_add_branch_to_version.rb +9 -0
  18. data/db/migrations/20210202_add_created_at_to_head_pact_tags.rb +14 -0
  19. data/db/migrations/20210205_add_pacticipant_id_to_tag.rb +17 -0
  20. data/db/migrations/20210206_add_index_to_tags_and_versions.rb +27 -0
  21. data/db/migrations/20210207_optimise_latest_verification_ids_for_consumer_version_tags.rb +13 -0
  22. data/db/migrations/20210208_optimise_latest_tagged_pact_cv_orders.rb +13 -0
  23. data/db/migrations/20210210_create_environments_table.rb +16 -0
  24. data/docker-compose-dev-postgres.yml +9 -1
  25. data/lib/pact_broker/api.rb +7 -2
  26. data/lib/pact_broker/api/contracts/dry_validation_predicates.rb +8 -0
  27. data/lib/pact_broker/api/contracts/environment_schema.rb +49 -0
  28. data/lib/pact_broker/api/decorators/base_decorator.rb +11 -0
  29. data/lib/pact_broker/api/decorators/dashboard_decorator.rb +5 -1
  30. data/lib/pact_broker/api/decorators/environment_decorator.rb +30 -0
  31. data/lib/pact_broker/api/decorators/environments_decorator.rb +21 -0
  32. data/lib/pact_broker/api/decorators/matrix_decorator.rb +3 -1
  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/resources/default_base_resource.rb +18 -0
  37. data/lib/pact_broker/api/resources/environment.rb +76 -0
  38. data/lib/pact_broker/api/resources/environments.rb +75 -0
  39. data/lib/pact_broker/api/resources/index.rb +20 -0
  40. data/lib/pact_broker/api/resources/latest_version.rb +27 -0
  41. data/lib/pact_broker/api/resources/provider_pacts_for_verification.rb +1 -0
  42. data/lib/pact_broker/api/resources/version.rb +15 -9
  43. data/lib/pact_broker/app.rb +1 -1
  44. data/lib/pact_broker/certificates/certificate.rb +1 -1
  45. data/lib/pact_broker/config/setting.rb +1 -1
  46. data/lib/pact_broker/config/space_delimited_integer_list.rb +25 -0
  47. data/lib/pact_broker/configuration.rb +22 -1
  48. data/lib/pact_broker/db/data_migrations/helpers.rb +4 -0
  49. data/lib/pact_broker/db/data_migrations/set_extra_columns_for_tags.rb +29 -0
  50. data/lib/pact_broker/db/migrate_data.rb +1 -0
  51. data/lib/pact_broker/db/seed_example_data.rb +13 -13
  52. data/lib/pact_broker/deployments/environment.rb +15 -0
  53. data/lib/pact_broker/deployments/environment_service.rb +39 -0
  54. data/lib/pact_broker/doc/views/index/environment.markdown +37 -0
  55. data/lib/pact_broker/doc/views/index/environments.markdown +53 -0
  56. data/lib/pact_broker/doc/views/index/latest-pact-versions.markdown +1 -1
  57. data/lib/pact_broker/doc/views/index/pacticipant-version-tag.markdown +1 -0
  58. data/lib/pact_broker/doc/views/index/pacticipant-version.markdown +13 -0
  59. data/lib/pact_broker/domain/index_item.rb +18 -4
  60. data/lib/pact_broker/domain/pacticipant.rb +9 -5
  61. data/lib/pact_broker/domain/tag.rb +131 -71
  62. data/lib/pact_broker/domain/verification.rb +3 -2
  63. data/lib/pact_broker/domain/version.rb +58 -23
  64. data/lib/pact_broker/domain/webhook.rb +6 -3
  65. data/lib/pact_broker/index/service.rb +55 -49
  66. data/lib/pact_broker/locale/en.yml +3 -1
  67. data/lib/pact_broker/matrix/quick_row.rb +8 -0
  68. data/lib/pact_broker/metrics/service.rb +1 -1
  69. data/lib/pact_broker/pacts/eager_loaders.rb +52 -0
  70. data/lib/pact_broker/pacts/latest_pact_publication_id_for_consumer_version.rb +18 -13
  71. data/lib/pact_broker/pacts/lazy_loaders.rb +14 -0
  72. data/lib/pact_broker/pacts/pact_publication.rb +38 -84
  73. data/lib/pact_broker/pacts/pact_publication_dataset_module.rb +297 -0
  74. data/lib/pact_broker/pacts/pact_version.rb +1 -2
  75. data/lib/pact_broker/pacts/pacts_for_verification_repository.rb +286 -0
  76. data/lib/pact_broker/pacts/repository.rb +5 -240
  77. data/lib/pact_broker/pacts/selected_pact.rb +4 -0
  78. data/lib/pact_broker/pacts/selector.rb +56 -1
  79. data/lib/pact_broker/pacts/selectors.rb +16 -0
  80. data/lib/pact_broker/pacts/service.rb +2 -6
  81. data/lib/pact_broker/pacts/squash_pacts_for_verification.rb +1 -4
  82. data/lib/pact_broker/pacts/verifiable_pact.rb +23 -2
  83. data/lib/pact_broker/pacts/verifiable_pact_messages.rb +56 -16
  84. data/lib/pact_broker/repositories/helpers.rb +4 -0
  85. data/lib/pact_broker/services.rb +9 -0
  86. data/lib/pact_broker/tags/eager_loaders.rb +47 -0
  87. data/lib/pact_broker/tags/repository.rb +3 -1
  88. data/lib/pact_broker/tags/service.rb +0 -3
  89. data/lib/pact_broker/tags/tag_with_latest_flag.rb +1 -0
  90. data/lib/pact_broker/test/http_test_data_builder.rb +23 -7
  91. data/lib/pact_broker/test/test_data_builder.rb +50 -3
  92. data/lib/pact_broker/ui/view_models/index_item.rb +19 -2
  93. data/lib/pact_broker/ui/view_models/matrix_line.rb +38 -2
  94. data/lib/pact_broker/ui/views/index/show-with-tags.haml +14 -6
  95. data/lib/pact_broker/ui/views/matrix/show.haml +12 -2
  96. data/lib/pact_broker/verifications/latest_verification_id_for_pact_version_and_provider_version.rb +7 -5
  97. data/lib/pact_broker/version.rb +1 -1
  98. data/lib/pact_broker/versions/eager_loaders.rb +71 -0
  99. data/lib/pact_broker/versions/lazy_loaders.rb +13 -0
  100. data/lib/pact_broker/versions/repository.rb +22 -2
  101. data/lib/pact_broker/versions/service.rb +5 -1
  102. data/lib/pact_broker/webhooks/execution.rb +3 -2
  103. data/lib/pact_broker/webhooks/latest_triggered_webhook.rb +2 -0
  104. data/lib/pact_broker/webhooks/triggered_webhook.rb +11 -4
  105. data/lib/pact_broker/webhooks/webhook.rb +1 -1
  106. data/lib/pact_broker/webhooks/webhook_event.rb +1 -1
  107. data/lib/pact_broker/webhooks/webhook_execution_result.rb +6 -1
  108. data/lib/pact_broker/webhooks/webhook_request_logger.rb +7 -1
  109. data/lib/rack/pact_broker/set_base_url.rb +35 -5
  110. data/lib/sequel/plugins/upsert.rb +18 -4
  111. data/pact_broker.gemspec +1 -1
  112. data/public/javascripts/clipboard.js +8 -2
  113. data/public/stylesheets/index.css +26 -2
  114. data/public/stylesheets/matrix.css +0 -21
  115. data/regression/can_i_deploy_spec.rb +5 -4
  116. data/regression/index_spec.rb +26 -0
  117. data/regression/regression_helper.rb +29 -3
  118. data/regression/script/clear.sh +3 -0
  119. data/regression/script/run.sh +3 -0
  120. data/script/demonstrate-version-branches.rb +33 -0
  121. data/script/pry.rb +2 -2
  122. data/spec/features/create_environment_spec.rb +47 -0
  123. data/spec/features/create_tag_spec.rb +32 -0
  124. data/spec/features/create_version_spec.rb +70 -0
  125. data/spec/features/delete_environment_spec.rb +16 -0
  126. data/spec/features/end_deployment_spec.rb +29 -0
  127. data/spec/features/get_environment_spec.rb +19 -0
  128. data/spec/features/get_environments_spec.rb +20 -0
  129. data/spec/features/record_deployment_spec.rb +28 -0
  130. data/spec/features/update_environment_spec.rb +44 -0
  131. data/spec/fixtures/approvals/modifiable_resources.approved.json +6 -0
  132. data/spec/fixtures/dashboard.json +4 -2
  133. data/spec/lib/pact_broker/api/contracts/environment_schema_spec.rb +83 -0
  134. data/spec/lib/pact_broker/api/decorators/dashboard_decorator_spec.rb +4 -2
  135. data/spec/lib/pact_broker/api/decorators/matrix_decorator_spec.rb +11 -6
  136. data/spec/lib/pact_broker/api/decorators/verifiable_pacts_query_decorator_spec.rb +6 -0
  137. data/spec/lib/pact_broker/api/decorators/version_decorator_spec.rb +18 -0
  138. data/spec/lib/pact_broker/api/resources/default_base_resource_approval_spec.rb +1 -1
  139. data/spec/lib/pact_broker/api/resources/provider_pacts_for_verification_spec.rb +4 -0
  140. data/spec/lib/pact_broker/api/resources/webhook_execution_result_spec.rb +56 -0
  141. data/spec/lib/pact_broker/config/space_delimited_integer_list_spec.rb +47 -0
  142. data/spec/lib/pact_broker/configuration_spec.rb +12 -0
  143. data/spec/lib/pact_broker/domain/tag_spec.rb +101 -27
  144. data/spec/lib/pact_broker/domain/version_spec.rb +103 -15
  145. data/spec/lib/pact_broker/domain/webhook_spec.rb +1 -1
  146. data/spec/lib/pact_broker/index/service_spec.rb +89 -15
  147. data/spec/lib/pact_broker/pacts/pact_publication_dataset_module_spec.rb +400 -0
  148. data/spec/lib/pact_broker/pacts/pact_publication_spec.rb +434 -14
  149. data/spec/lib/pact_broker/pacts/repository_find_for_verification_fallback_spec.rb +1 -1
  150. data/spec/lib/pact_broker/pacts/repository_find_for_verification_spec.rb +1 -1
  151. data/spec/lib/pact_broker/pacts/repository_find_wip_pact_versions_for_provider_branch_spec.rb +224 -0
  152. data/spec/lib/pact_broker/pacts/repository_find_wip_pact_versions_for_provider_spec.rb +20 -7
  153. data/spec/lib/pact_broker/pacts/selector_spec.rb +3 -2
  154. data/spec/lib/pact_broker/pacts/service_find_for_verification_spec.rb +2 -3
  155. data/spec/lib/pact_broker/pacts/service_spec.rb +2 -2
  156. data/spec/lib/pact_broker/pacts/verifiable_pact_messages_spec.rb +57 -10
  157. data/spec/lib/pact_broker/tags/repository_spec.rb +2 -0
  158. data/spec/lib/pact_broker/versions/repository_spec.rb +54 -0
  159. data/spec/lib/pact_broker/webhooks/webhook_request_logger_spec.rb +8 -0
  160. data/spec/lib/rack/pact_broker/set_base_url_spec.rb +86 -0
  161. data/spec/lib/sequel/plugins/upsert_spec.rb +31 -3
  162. data/spec/migrations/change_migration_strategy_spec.rb +3 -3
  163. data/spec/service_consumers/hal_relation_proxy_app.rb +3 -1
  164. data/spec/service_consumers/provider_states_for_pact_broker_client.rb +16 -0
  165. data/spec/spec_helper.rb +17 -5
  166. data/spec/support/approvals.rb +24 -0
  167. data/spec/support/shared_examples_for_responses.rb +11 -0
  168. data/tasks/database.rb +1 -1
  169. data/tasks/db.rake +1 -0
  170. data/tasks/rspec.rake +1 -1
  171. data/vendor/hal-browser/styles.css +6 -0
  172. metadata +70 -11
@@ -0,0 +1,20 @@
1
+ require 'pact_broker/api/pact_broker_urls'
2
+
3
+ describe "Get all environments" do
4
+ before do
5
+ td.create_environment("test", display_name: "Test", uuid: "1234", contacts: [ { name: "Foo" } ] )
6
+ .create_environment("prod", display_name: "Production", uuid: "5678", contacts: [ { name: "Foo" } ] )
7
+ end
8
+ let(:path) { PactBroker::Api::PactBrokerUrls.environments_url }
9
+ let(:headers) { {'HTTP_ACCEPT' => 'application/hal+json'} }
10
+ let(:response_body) { JSON.parse(last_response.body, symbolize_names: true)}
11
+
12
+ subject { get(path, nil, headers) }
13
+
14
+ it { is_expected.to be_a_hal_json_success_response }
15
+
16
+ it "returns the environments" do
17
+ subject
18
+ expect(response_body[:_embedded][:environments].size).to be 2
19
+ end
20
+ end
@@ -0,0 +1,28 @@
1
+ #
2
+ # pact-broker record-deployment --pacticipant Foo --version 1 --environment test --end-previous-deployment
3
+ #
4
+
5
+ describe "Record deployment", skip: "Not yet implemented" do
6
+ before do
7
+ td.create_environment("test")
8
+ .create_pacticipant("Foo")
9
+ .create_pacticipant_version("1")
10
+ end
11
+ let(:path) { "/pacticipants/Foo/versions/1/deployments/test" }
12
+ let(:headers) { {"CONTENT_TYPE" => "application/json"} }
13
+ let(:response_body) { JSON.parse(last_response.body, symbolize_names: true)}
14
+
15
+ subject { post(path, nil, headers) }
16
+
17
+ it { is_expected.to be_a_hal_json_created_response }
18
+
19
+ it "returns the Location header" do
20
+ subject
21
+ expect(last_response.headers["Location"]).to eq "http://example.org/deployments/123456"
22
+ end
23
+
24
+ it "returns the newly created deployment" do
25
+ subject
26
+ expect(response_body).to include_key(:createdAt)
27
+ end
28
+ end
@@ -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",
@@ -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
 
@@ -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
@@ -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
  {
@@ -0,0 +1,56 @@
1
+ module PactBroker
2
+ module Webhooks
3
+ describe WebhookExecutionResult do
4
+ subject { WebhookExecutionResult::new(request, response, nil) }
5
+ let(:request) do
6
+ Net::HTTP::Get.new("http://example.org?foo=bar")
7
+ end
8
+
9
+ context "When 'webhook_http_code_success' has [200, 201]" do
10
+ before do
11
+ allow(PactBroker.configuration).to receive(:webhook_http_code_success).and_return([200, 201])
12
+ end
13
+
14
+ context "and response is '200'" do
15
+ let(:response) { double(code: '200') }
16
+
17
+ it "then it should be success" do
18
+ expect(subject.success?).to be_truthy
19
+ end
20
+ end
21
+
22
+ context "and response is '400'" do
23
+ let(:response) { double(code: '400') }
24
+
25
+ it "then it should fail" do
26
+ expect(subject.success?).to be_falsey
27
+ end
28
+ end
29
+ end
30
+
31
+
32
+ context "When 'webhook_http_code_success' has [400, 401]" do
33
+ before do
34
+ allow(PactBroker.configuration).to receive(:webhook_http_code_success).and_return([400, 401])
35
+ end
36
+
37
+ context "and response is '200'" do
38
+ let(:response) { double(code: '200') }
39
+
40
+ it "then it should fail" do
41
+ expect(subject.success?).to be_falsey
42
+ end
43
+ end
44
+
45
+ context "and response is '400'" do
46
+ let(:response) { double(code: '400') }
47
+
48
+ it "then it should be success" do
49
+ expect(subject.success?).to be_truthy
50
+ end
51
+ end
52
+ end
53
+
54
+ end
55
+ end
56
+ end