Sha256: 1ea8e121b82bba94f18419b36c62d7d4177ead4878ae5897be5efc5ffd286f26

Contents?: true

Size: 1.45 KB

Versions: 12

Compression:

Stored size: 1.45 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

      context "when interactions is a string" do
        let(:other_content) do
          {
            "a" => 1,
            "interactions" => "interactions"
          }
        end

        it "does not blow up" do
          expect(SortContent.call(other_content)).to eq other_content
        end
      end
    end
  end
end

Version data entries

12 entries across 12 versions & 1 rubygems

Version Path
pact_broker-2.89.1 spec/lib/pact_broker/pacts/sort_content_spec.rb
pact_broker-2.89.0 spec/lib/pact_broker/pacts/sort_content_spec.rb
pact_broker-2.88.0 spec/lib/pact_broker/pacts/sort_content_spec.rb
pact_broker-2.87.0 spec/lib/pact_broker/pacts/sort_content_spec.rb
pact_broker-2.86.0 spec/lib/pact_broker/pacts/sort_content_spec.rb
pact_broker-2.85.1 spec/lib/pact_broker/pacts/sort_content_spec.rb
pact_broker-2.85.0 spec/lib/pact_broker/pacts/sort_content_spec.rb
pact_broker-2.84.0 spec/lib/pact_broker/pacts/sort_content_spec.rb
pact_broker-2.83.0 spec/lib/pact_broker/pacts/sort_content_spec.rb
pact_broker-2.82.0 spec/lib/pact_broker/pacts/sort_content_spec.rb
pact_broker-2.81.0 spec/lib/pact_broker/pacts/sort_content_spec.rb
pact_broker-2.80.0 spec/lib/pact_broker/pacts/sort_content_spec.rb