Sha256: bc5b053dc2baf6dfb63ae0edda70dfda1405b3cd78fdd952ab40675b4ea14acf

Contents?: true

Size: 1.14 KB

Versions: 88

Compression:

Stored size: 1.14 KB

Contents

require 'pact_broker/pacts/sort_content'

module PactBroker
  module Pacts
    describe SortContent do
      let(:pact_content_1) do
        {
          'a' => 1,
          'interactions' => [{ 'a' => 1, 'b' => 2 }, { 'a' => [2, 1, 3], 'b' => 3 }]
        }
      end

      let(:pact_content_2) do
        {
          'interactions' => [{ 'b' => 3, 'a' => [2, 1, 3]}, { 'b' => 2, 'a' => 1 }],
          'a' => 1
        }
      end

      let(:expected_sorted_content) do
        '{"a":1,"interactions":[{"a":1,"b":2},{"a":[2,1,3],"b":3}]}'
      end

      it "sorts the interactions/messages and keys in a deterministic way" do
        expect(SortContent.call(pact_content_1).to_json).to eq(expected_sorted_content)
        expect(SortContent.call(pact_content_2).to_json).to eq(expected_sorted_content)
      end

      context "when there is no messages or interactions key" do
        let(:other_content) do
          {
            'z' => 1,
            'a' => 1,
            'b' => 1,
          }
        end

        it "does not change the content" do
          expect(SortContent.call(other_content)).to eq other_content
        end
      end
    end
  end
end

Version data entries

88 entries across 88 versions & 1 rubygems

Version Path
pact_broker-2.79.1 spec/lib/pact_broker/pacts/sort_content_spec.rb
pact_broker-2.79.0 spec/lib/pact_broker/pacts/sort_content_spec.rb
pact_broker-2.78.1 spec/lib/pact_broker/pacts/sort_content_spec.rb
pact_broker-2.78.0 spec/lib/pact_broker/pacts/sort_content_spec.rb
pact_broker-2.77.0 spec/lib/pact_broker/pacts/sort_content_spec.rb
pact_broker-2.76.2 spec/lib/pact_broker/pacts/sort_content_spec.rb
pact_broker-2.76.1 spec/lib/pact_broker/pacts/sort_content_spec.rb
pact_broker-2.76.0 spec/lib/pact_broker/pacts/sort_content_spec.rb
pact_broker-2.75.0 spec/lib/pact_broker/pacts/sort_content_spec.rb
pact_broker-2.74.1 spec/lib/pact_broker/pacts/sort_content_spec.rb
pact_broker-2.74.0 spec/lib/pact_broker/pacts/sort_content_spec.rb
pact_broker-2.73.0 spec/lib/pact_broker/pacts/sort_content_spec.rb
pact_broker-2.72.0 spec/lib/pact_broker/pacts/sort_content_spec.rb
pact_broker-2.71.0 spec/lib/pact_broker/pacts/sort_content_spec.rb
pact_broker-2.70.0 spec/lib/pact_broker/pacts/sort_content_spec.rb
pact_broker-2.69.0 spec/lib/pact_broker/pacts/sort_content_spec.rb
pact_broker-2.68.1 spec/lib/pact_broker/pacts/sort_content_spec.rb
pact_broker-2.68.0 spec/lib/pact_broker/pacts/sort_content_spec.rb
pact_broker-2.67.0 spec/lib/pact_broker/pacts/sort_content_spec.rb
pact_broker-2.66.0 spec/lib/pact_broker/pacts/sort_content_spec.rb