Skip to content

Commit

Permalink
test: change TestDataBuilder to return self from create_pact_with_hei…
Browse files Browse the repository at this point in the history
…rarchy
  • Loading branch information
bethesque committed Aug 21, 2017
1 parent 35f66d5 commit dc283ad
Show file tree
Hide file tree
Showing 13 changed files with 22 additions and 18 deletions.
2 changes: 1 addition & 1 deletion spec/features/create_webhook_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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" }
Expand Down
2 changes: 1 addition & 1 deletion spec/features/delete_pact_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion spec/features/get_pact_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion spec/features/merge_pact_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion spec/features/publish_pact_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion spec/integration/app_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
Expand Down
2 changes: 1 addition & 1 deletion spec/integration/endpoints/group.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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]}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) }

Expand Down
2 changes: 1 addition & 1 deletion spec/lib/pact_broker/pacts/repository_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion spec/lib/pact_broker/verifications/service_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
15 changes: 9 additions & 6 deletions spec/support/test_data_builder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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

Expand All @@ -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}
Expand Down

0 comments on commit dc283ad

Please sign in to comment.