Skip to content

Commit

Permalink
fix: return empty body when group csv is requested for a pacticipant …
Browse files Browse the repository at this point in the history
…that does not have any integrations
  • Loading branch information
bethesque committed Nov 25, 2020
1 parent 2a6929b commit fb4e28c
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 8 deletions.
6 changes: 5 additions & 1 deletion lib/pact_broker/api/resources/group.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,11 @@ def resource_exists?
end

def to_csv
PactBroker::Api::Decorators::RelationshipsCsvDecorator.new(group).to_csv
if group
PactBroker::Api::Decorators::RelationshipsCsvDecorator.new(group).to_csv
else
""
end
end

def policy_name
Expand Down
16 changes: 9 additions & 7 deletions spec/lib/pact_broker/api/resources/group_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,13 @@
require 'rack/test'

module PactBroker::Api

module Resources

describe Group do

include Rack::Test::Methods

let(:app) { PactBroker::API }

describe "GET" do

let(:group) { double('group') }
let(:decorator) { instance_double(PactBroker::Api::Decorators::RelationshipsCsvDecorator) }
let(:csv) { 'csv' }
Expand Down Expand Up @@ -60,7 +56,6 @@ module Resources
subject
expect(last_response.body).to eq csv
end

end

context "when the pacticipant does not exist" do
Expand All @@ -72,9 +67,16 @@ module Resources
end
end

end
context "when there is no group because the pacticipant isn't integrated with any other pacticipants" do
let(:group) { nil }

it "returns an empty body" do
expect(subject.status).to eq 200
expect(last_response.headers['Content-Type']).to eq 'text/csv;charset=utf-8'
expect(subject.body).to eq ""
end
end
end
end
end

end

0 comments on commit fb4e28c

Please sign in to comment.