Sha256: 60a2311da65b04e00b0d88faaab97a506222c8ee8f277cd64881415d6a20714c

Contents?: true

Size: 1.91 KB

Versions: 4

Compression:

Stored size: 1.91 KB

Contents

require 'pact/provider/verification_results/verification_result'
module Pact
  module Provider
    module VerificationResults
      class Create

        def self.call pact_source, test_results_hash
          new(pact_source, test_results_hash).call
        end

        def initialize pact_source, test_results_hash
          @pact_source = pact_source
          @test_results_hash = test_results_hash
        end

        def call
          VerificationResult.new(publishable?, !any_failures?, Pact.configuration.provider.application_version, test_results_hash_for_pact_uri)
        end

        private

        def pact_uri
          @pact_uri ||= pact_source.uri
        end

        def any_failures?
          count_failures_for_pact_uri > 0
        end

        def publishable?
          executed_interactions_count == all_interactions_count && all_interactions_count > 0
        end

        def examples_for_pact_uri
          @examples_for_pact_uri ||= test_results_hash[:tests].select{ |e| e[:pact_uri] == pact_uri }
        end

        def count_failures_for_pact_uri
          examples_for_pact_uri.count{ |e| e[:status] != 'passed' }
        end

        def executed_interactions_count
          examples_for_pact_uri
            .collect { |e| e[:pact_interaction].object_id }
            .uniq
            .count
        end

        def all_interactions_count
          pact_source.pact_hash['interactions'].count
        end

        def test_results_hash_for_pact_uri
          {
            tests: examples_for_pact_uri.collect{ |e| clean_example(e) },
            summary: {
              testCount: examples_for_pact_uri.size,
              failureCount: count_failures_for_pact_uri
            }
          }
        end

        def clean_example(example)
          example.reject{ |k, v| k == :pact_uri || k == :pact_interaction }
        end

        attr_reader :pact_source, :test_results_hash
      end
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
pact-1.21.0 lib/pact/provider/verification_results/create.rb
pact-1.20.1 lib/pact/provider/verification_results/create.rb
pact-1.20.0 lib/pact/provider/verification_results/create.rb
pact-1.19.2 lib/pact/provider/verification_results/create.rb