|
| 1 | +require 'pact_broker/api/decorators/extended_pact_decorator' |
| 2 | + |
| 3 | +module PactBroker |
| 4 | + module Api |
| 5 | + module Decorators |
| 6 | + describe ExtendedPactDecorator do |
| 7 | + before do |
| 8 | + allow(decorator).to receive(:templated_diff_url).and_return('templated-diff-url') |
| 9 | + allow(decorator).to receive(:verification_publication_url).and_return('verification-publication-url') |
| 10 | + end |
| 11 | + let(:content_hash) { |
| 12 | + { |
| 13 | + 'consumer' => {'name' => 'Consumer'}, |
| 14 | + 'provider' => {'name' => 'Provider'}, |
| 15 | + 'interactions' => [], |
| 16 | + 'metadata' => {} |
| 17 | + } |
| 18 | + } |
| 19 | + |
| 20 | + let(:base_url) { 'http://example.org' } |
| 21 | + let(:created_at) { Time.new(2014, 3, 4) } |
| 22 | + let(:pact) { double('pact', |
| 23 | + content_hash: content_hash, |
| 24 | + created_at: created_at, |
| 25 | + consumer: consumer, |
| 26 | + provider: provider, |
| 27 | + consumer_version: consumer_version, |
| 28 | + consumer_version_number: '1234', |
| 29 | + pact_version_sha: '9999', |
| 30 | + revision_number: 2, |
| 31 | + name: 'A Pact', |
| 32 | + head_tag_names: head_tag_names |
| 33 | + )} |
| 34 | + let(:head_tag_names) { ['prod'] } |
| 35 | + let(:consumer) { instance_double(PactBroker::Domain::Pacticipant, name: 'A Consumer')} |
| 36 | + let(:provider) { instance_double(PactBroker::Domain::Pacticipant, name: 'A Provider')} |
| 37 | + let(:consumer_version) { instance_double(PactBroker::Domain::Version, number: '1234', pacticipant: consumer)} |
| 38 | + let(:metadata) { "abcd" } |
| 39 | + let(:decorator) { ExtendedPactDecorator.new(pact) } |
| 40 | + let(:json) { decorator.to_json(user_options: { base_url: base_url, metadata: metadata }) } |
| 41 | + subject { JSON.parse(json, symbolize_names: true) } |
| 42 | + |
| 43 | + it "includes an array of tags" do |
| 44 | + expect(subject[:_embedded][:tags].first).to include name: 'prod', latest: true |
| 45 | + # Can't seem to stub the verification_publication_url method on the TagDecorator |
| 46 | + expect(subject[:_embedded][:tags].first[:_links][:'pb:latest-pact'][:href]).to eq "http://example.org/pacts/provider/A%20Provider/consumer/A%20Consumer/latest/prod" |
| 47 | + end |
| 48 | + |
| 49 | + it "includes the pact contents under the contract key" do |
| 50 | + expect(subject[:contract]).to eq JSON.parse(content_hash.to_json, symbolize_names: true) |
| 51 | + end |
| 52 | + |
| 53 | + it "does not include the contract contents in the root" do |
| 54 | + expect(subject).to_not have_key(:interactions) |
| 55 | + end |
| 56 | + end |
| 57 | + end |
| 58 | + end |
| 59 | +end |
0 commit comments