Sha256: 4f95f8081cfca4ec389462c0dc122a16e5358122a999c7ece11b0be1cba22bd0

Contents?: true

Size: 1.96 KB

Versions: 1

Compression:

Stored size: 1.96 KB

Contents

require 'spec_helper'
require 'pact_broker/api/decorators/pact_version_decorator'

module PactBroker

  module Api

    module Decorators

      describe PactVersionDecorator do

        let(:json_content) {
          {
            'consumer' => {'name' => 'Consumer'},
            'provider' => {'name' => 'Provider'},
            'interactions' => [],
            'metadata' => {}
          }.to_json
        }

        let(:base_url) { 'http://example.org' }
        let(:created_at) { Time.new(2014, 3, 4) }
        let(:updated_at) { Time.new(2014, 3, 5) }
        let(:pact) { double('pact', json_content: json_content, created_at: created_at, updated_at: updated_at, consumer: consumer, provider: provider, consumer_version: consumer_version, name: 'pact_name')}
        let(:consumer) { instance_double(PactBroker::Domain::Pacticipant, name: 'Consumer')}
        let(:provider) { instance_double(PactBroker::Domain::Pacticipant, name: 'Provider')}
        let(:consumer_version) { instance_double(PactBroker::Domain::Version, number: '1234', pacticipant: consumer)}
        let(:decorator_context) { DecoratorContext.new(base_url, '') }

        let(:json) { PactVersionDecorator.new(pact).to_json(decorator_context) }

        subject { JSON.parse(json, symbolize_names: true) }

        it "includes a link to the pact" do
          expect(subject[:_links][:self][:href]).to eq 'http://example.org/pacts/provider/Provider/consumer/Consumer/version/1234'
        end

        it "includes the consumer version number" do
          expect(subject[:_embedded][:consumerVersion][:number]).to eq "1234"
        end

        it "includes a link to the version" do
          expect(subject[:_embedded][:consumerVersion][:_links][:self][:href]).to eq "http://example.org/pacticipants/Consumer/versions/1234"
        end

        it "includes timestamps" do
          expect(subject[:createdAt]).to_not be_nil
          expect(subject[:updatedAt]).to_not be_nil
        end

      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
pact_broker-1.3.2.rc1 spec/lib/pact_broker/api/decorators/pact_version_decorator_spec.rb