From 38a8e06e16edd158fc8b63ad8c8a2b6b54f376f0 Mon Sep 17 00:00:00 2001 From: Beth Skurrie Date: Tue, 1 May 2018 11:11:12 +1000 Subject: [PATCH] test: add test for ProviderPactsDecorator --- .../provider_pacts_decorator_spec.rb | 57 +++++++++++++++++++ 1 file changed, 57 insertions(+) create mode 100644 spec/lib/pact_broker/api/decorators/provider_pacts_decorator_spec.rb diff --git a/spec/lib/pact_broker/api/decorators/provider_pacts_decorator_spec.rb b/spec/lib/pact_broker/api/decorators/provider_pacts_decorator_spec.rb new file mode 100644 index 000000000..c44409306 --- /dev/null +++ b/spec/lib/pact_broker/api/decorators/provider_pacts_decorator_spec.rb @@ -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