diff --git a/spec/features/create_webhook_spec.rb b/spec/features/create_webhook_spec.rb index 7f37e864d..c0de0e4ae 100644 --- a/spec/features/create_webhook_spec.rb +++ b/spec/features/create_webhook_spec.rb @@ -3,7 +3,7 @@ describe "Creating a webhook" do before do - TestDataBuilder.new.create_pact_with_hierarchy("Some Consumer", "1", "Some Provider") + TestDataBuilder.new.create_pact_with_hierarchy("Some Consumer", "1", "Some Provider").and_return(:pact) end let(:path) { "/webhooks/provider/Some%20Provider/consumer/Some%20Consumer" } diff --git a/spec/features/delete_pact_spec.rb b/spec/features/delete_pact_spec.rb index eeb6ac355..1a93eec2e 100644 --- a/spec/features/delete_pact_spec.rb +++ b/spec/features/delete_pact_spec.rb @@ -8,7 +8,7 @@ context "when the pact exists" do before do - TestDataBuilder.new.create_pact_with_hierarchy "A Consumer", "1.2.3", "A Provider" + TestDataBuilder.new.create_pact_with_hierarchy("A Consumer", "1.2.3", "A Provider").and_return(:pact) end it "deletes the pact" do diff --git a/spec/features/get_pact_spec.rb b/spec/features/get_pact_spec.rb index c462b4b5b..c1ac35bf9 100644 --- a/spec/features/get_pact_spec.rb +++ b/spec/features/get_pact_spec.rb @@ -7,7 +7,7 @@ let(:path) { "/pacts/provider/a%20provider/consumer/a%20consumer/version/1.2.3A" } before do - TestDataBuilder.new.create_pact_with_hierarchy "A Consumer", "1.2.3a", "A Provider" + TestDataBuilder.new.create_pact_with_hierarchy("A Consumer", "1.2.3a", "A Provider").and_return(:pact) end context "when case sensitivity is turned on" do diff --git a/spec/features/merge_pact_spec.rb b/spec/features/merge_pact_spec.rb index 157f4d0ea..e58ffe416 100644 --- a/spec/features/merge_pact_spec.rb +++ b/spec/features/merge_pact_spec.rb @@ -29,7 +29,7 @@ let(:merged_pact_content) { load_fixture('a_consumer-a_provider-merged.json') } before do - TestDataBuilder.new.create_pact_with_hierarchy "A Consumer", "1.2.3", "A Provider", existing_pact_content + TestDataBuilder.new.create_pact_with_hierarchy("A Consumer", "1.2.3", "A Provider", existing_pact_content).and_return(:pact) end it "returns a 200 Success" do diff --git a/spec/features/publish_pact_spec.rb b/spec/features/publish_pact_spec.rb index 3993b47d1..301066a17 100644 --- a/spec/features/publish_pact_spec.rb +++ b/spec/features/publish_pact_spec.rb @@ -23,7 +23,7 @@ context "when a pact for this consumer version does exist" do before do - TestDataBuilder.new.create_pact_with_hierarchy "A Consumer", "1.2.3", "A Provider" + TestDataBuilder.new.create_pact_with_hierarchy("A Consumer", "1.2.3", "A Provider").and_return(:pact) end it "returns a 200 Success" do diff --git a/spec/integration/app_spec.rb b/spec/integration/app_spec.rb index 231ddcaf1..9ece08dba 100644 --- a/spec/integration/app_spec.rb +++ b/spec/integration/app_spec.rb @@ -7,7 +7,7 @@ module PactBroker describe App do before do - TestDataBuilder.new.create_pact_with_hierarchy 'Some Consumer', '1.0', 'Some Provider' + TestDataBuilder.new.create_pact_with_hierarchy('Some Consumer', '1.0', 'Some Provider').and_return(:pact) end let(:hal_browser_enabled) { true } diff --git a/spec/integration/endpoints/group.rb b/spec/integration/endpoints/group.rb index 6f040b7df..07cb2b239 100644 --- a/spec/integration/endpoints/group.rb +++ b/spec/integration/endpoints/group.rb @@ -6,7 +6,7 @@ describe "GET" do before do - TestDataBuilder.new.create_pact_with_hierarchy "Consumer", "1.2.3", "Provider" + TestDataBuilder.new.create_pact_with_hierarchy("Consumer", "1.2.3", "Provider").and_return(:pact) get "/groups/Consumer" end diff --git a/spec/lib/pact_broker/api/decorators/latest_pact_decorator_spec.rb b/spec/lib/pact_broker/api/decorators/latest_pact_decorator_spec.rb index ac995e753..06d43fbe0 100644 --- a/spec/lib/pact_broker/api/decorators/latest_pact_decorator_spec.rb +++ b/spec/lib/pact_broker/api/decorators/latest_pact_decorator_spec.rb @@ -9,7 +9,8 @@ module Decorators describe LatestPactDecorator do - let(:pact) { RepresentablePact.new(TestDataBuilder.new.create_pact_with_hierarchy 'Consumer', '1.2.3', 'Provider') } + let(:pact_domain) { TestDataBuilder.new.create_pact_with_hierarchy('Consumer', '1.2.3', 'Provider').and_return(:pact) } + let(:pact) { RepresentablePact.new(pact_domain) } let(:base_url) { 'http://example.org' } subject { JSON.parse LatestPactDecorator.new(pact).to_json(user_options: { base_url: base_url }), symbolize_names: true} diff --git a/spec/lib/pact_broker/api/decorators/relationships_csv_decorator_spec.rb b/spec/lib/pact_broker/api/decorators/relationships_csv_decorator_spec.rb index 84c15916e..f100f2e70 100644 --- a/spec/lib/pact_broker/api/decorators/relationships_csv_decorator_spec.rb +++ b/spec/lib/pact_broker/api/decorators/relationships_csv_decorator_spec.rb @@ -9,7 +9,7 @@ module Decorators describe RelationshipsCsvDecorator do - let(:pact) { TestDataBuilder.new.create_pact_with_hierarchy "My Consumer", "1.0", "My Provider"} + let(:pact) { TestDataBuilder.new.create_pact_with_hierarchy("My Consumer", "1.0", "My Provider").and_return(:pact) } let(:pacts) { [pact]} diff --git a/spec/lib/pact_broker/api/decorators/representable_pact_spec.rb b/spec/lib/pact_broker/api/decorators/representable_pact_spec.rb index a0e27fc3b..29538a6b0 100644 --- a/spec/lib/pact_broker/api/decorators/representable_pact_spec.rb +++ b/spec/lib/pact_broker/api/decorators/representable_pact_spec.rb @@ -4,7 +4,7 @@ module PactBroker::Api::Decorators describe RepresentablePact do - let(:pact) { TestDataBuilder.new.create_pact_with_hierarchy 'Consumer', '1.2.3', 'Provider' } + let(:pact) { TestDataBuilder.new.create_pact_with_hierarchy('Consumer', '1.2.3', 'Provider').and_return(:pact) } subject { RepresentablePact.new(pact) } diff --git a/spec/lib/pact_broker/pacts/repository_spec.rb b/spec/lib/pact_broker/pacts/repository_spec.rb index 9625efccd..92af3c26f 100644 --- a/spec/lib/pact_broker/pacts/repository_spec.rb +++ b/spec/lib/pact_broker/pacts/repository_spec.rb @@ -90,7 +90,7 @@ module Pacts describe "update" do let(:existing_pact) do - TestDataBuilder.new.create_pact_with_hierarchy "A Consumer", "1.2.3", "A Provider", original_json_content + TestDataBuilder.new.create_pact_with_hierarchy("A Consumer", "1.2.3", "A Provider", original_json_content).and_return(:pact) end before do diff --git a/spec/lib/pact_broker/verifications/service_spec.rb b/spec/lib/pact_broker/verifications/service_spec.rb index 85555697e..a92944e38 100644 --- a/spec/lib/pact_broker/verifications/service_spec.rb +++ b/spec/lib/pact_broker/verifications/service_spec.rb @@ -23,7 +23,7 @@ module Verifications describe "#create" do let(:params) { {'success' => true, 'providerApplicationVersion' => '4.5.6'} } - let(:pact) { TestDataBuilder.new.create_pact_with_hierarchy } + let(:pact) { TestDataBuilder.new.create_pact_with_hierarchy.and_return(:pact) } let(:create_verification) { subject.create 3, params, pact } it "logs the creation" do diff --git a/spec/support/test_data_builder.rb b/spec/support/test_data_builder.rb index f7c5b0a6b..2c19fa235 100644 --- a/spec/support/test_data_builder.rb +++ b/spec/support/test_data_builder.rb @@ -87,10 +87,11 @@ def create_condor_pricing_service_pact end def create_pact_with_hierarchy consumer_name = "Consumer", consumer_version = "1.2.3", provider_name = "Provider", json_content = default_json_content - provider = PactBroker::Domain::Pacticipant.create(:name => provider_name) - consumer = PactBroker::Domain::Pacticipant.create(:name => consumer_name) - version = PactBroker::Domain::Version.create(:number => consumer_version, :pacticipant => consumer) - PactBroker::Pacts::Repository.new.create(version_id: version.id, consumer_id: consumer.id, provider_id: provider.id, json_content: json_content) + create_consumer consumer_name + create_provider provider_name + create_consumer_version consumer_version + create_pact json_content: json_content + self end def create_version_with_hierarchy pacticipant_name, pacticipant_version @@ -161,9 +162,10 @@ def revise_pact json_content = nil end def create_webhook params = {} + uuid = params[:uuid] || PactBroker::Webhooks::Service.next_uuid default_params = {method: 'POST', url: 'http://example.org', headers: {'Content-Type' => 'application/json'}} request = PactBroker::Domain::WebhookRequest.new(default_params.merge(params)) - @webhook = PactBroker::Webhooks::Repository.new.create PactBroker::Webhooks::Service.next_uuid, PactBroker::Domain::Webhook.new(request: request), @consumer, @provider + @webhook = PactBroker::Webhooks::Repository.new.create uuid, PactBroker::Domain::Webhook.new(request: request), @consumer, @provider self end @@ -174,7 +176,8 @@ def create_triggered_webhook params = {} end def create_webhook_execution params = {} - webhook_execution_result = PactBroker::Domain::WebhookExecutionResult.new(OpenStruct.new(code: "200"), "logs", nil) + logs = params[:logs] || "logs" + webhook_execution_result = PactBroker::Domain::WebhookExecutionResult.new(OpenStruct.new(code: "200"), logs, nil) @webhook_execution = PactBroker::Webhooks::Repository.new.create_execution @triggered_webhook, webhook_execution_result created_at = params[:created_at] || @pact.created_at + Rational(1, 86400) set_created_at_if_set created_at, :webhook_executions, {id: @webhook_execution.id}