Skip to content

Commit

Permalink
test: add test for ProviderPactsDecorator
Browse files Browse the repository at this point in the history
  • Loading branch information
bethesque committed May 1, 2018
1 parent d7011b2 commit 38a8e06
Showing 1 changed file with 57 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
require 'pact_broker/api/decorators/provider_pacts_decorator'

module PactBroker
module Api
module Decorators
describe ProviderPactsDecorator do

let(:pacts) { [pact]}
let(:pact) do
double('pact', name: 'Pact name', consumer_name: 'Foo')
end
let(:user_options) do
{
base_url: 'http://example.org',
resource_url: 'http://example.org/provider-pacts',
title: 'title'
}
end

before do
allow_any_instance_of(ProviderPactsDecorator).to receive(:pact_url).and_return('pact_url')
end

subject { JSON.parse ProviderPactsDecorator.new(pacts).to_json(user_options: user_options), symbolize_names: true }

let(:expected) do
{
:_links => {
:self=> {
:href=> "http://example.org/provider-pacts",
:title => "title"
},
:provider => {
:href => "http://example.org/pacticipants/",
:title => nil
},
:"pb:pacts" =>[{
:href => "pact_url",
:title => "Pact name",
:name => "Foo" }],
:pacts => [{
:href => "pact_url",
:title => "DEPRECATED - please use the pb:pacts relation",
:name => "Foo"
}
]
}
}
end

it "matches the expected JSON" do
expect(subject).to match_pact(expected)
end
end
end
end
end

0 comments on commit 38a8e06

Please sign in to comment.