Skip to content

Commit

Permalink
Added HTML content type for request to get a specific version of a pact.
Browse files Browse the repository at this point in the history
  • Loading branch information
bethesque committed Apr 10, 2017
1 parent 859f545 commit 990575f
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 1 deletion.
7 changes: 6 additions & 1 deletion lib/pact_broker/api/resources/pact.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ class Pact < BaseResource
include PacticipantResourceMethods

def content_types_provided
[["application/json", :to_json]]
[["application/json", :to_json],
["text/html", :to_html]]
end

def content_types_accepted
Expand Down Expand Up @@ -76,6 +77,10 @@ def to_json
PactBroker::Api::Decorators::PactDecorator.new(pact).to_json(user_options: { base_url: base_url })
end

def to_html
PactBroker.configuration.html_pact_renderer.call(pact)
end

def delete_resource
pact_service.delete(pact_params)
true
Expand Down
42 changes: 42 additions & 0 deletions spec/lib/pact_broker/api/resources/pact_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
require 'pact_broker/api/resources/pact'
require 'rack/test'
require 'pact_broker/pacts/service'
require 'pact_broker/pacticipants/service'


module PactBroker::Api

Expand All @@ -14,6 +16,46 @@ module Resources
let(:app) { PactBroker::API }
let(:json) { {some: 'json'}.to_json }

describe "GET" do

context "Accept: text/html" do

let(:json_content) { 'json_content' }
let(:pact) { double("pact", json_content: json_content)}
let(:html) { 'html' }
let(:pact_id_params) { {provider_name: "provider_name", consumer_name: "consumer_name", consumer_version_number: "1.2.3"} }

before do
allow(PactBroker::Pacts::Service).to receive(:find_pact).and_return(pact)
allow(PactBroker.configuration.html_pact_renderer).to receive(:call).and_return(html)
end

subject { get "/pacts/provider/provider_name/consumer/consumer_name/versions/1.2.3",{}, {'HTTP_ACCEPT' => "text/html"} }

it "find the pact" do
expect(PactBroker::Pacts::Service).to receive(:find_pact).with(hash_including(pact_id_params))
subject
end

it "uses the configured HTML renderer" do
expect(PactBroker.configuration.html_pact_renderer).to receive(:call).with(pact)
subject
end

it "returns a HTML body" do
subject
expect(last_response.body).to eq html
end

it "returns a content type of HTML" do
subject
expect(last_response.headers['Content-Type']).to eq 'text/html;charset=utf-8'
end

end
end


shared_examples "an update endpoint" do |http_method|
subject { self.send http_method, "/pacts/provider/Provider/consumer/Consumer/version/1.2", json, {'CONTENT_TYPE' => "application/json"} ; last_response }

Expand Down

0 comments on commit 990575f

Please sign in to comment.