Sha256: f16ecfe4f69fe184a8856815c0f67d0c47355d3c5559a816bac8f3a11f3cb0d6

Contents?: true

Size: 1.94 KB

Versions: 1

Compression:

Stored size: 1.94 KB

Contents

require 'pact_broker/repositories'

module PactBroker
  module Matrix
    module Service

      extend self
      extend PactBroker::Repositories
      extend PactBroker::Services

      def find criteria, options = {}
        matrix_repository.find criteria, options
      end

      def find_for_consumer_and_provider params
        matrix_repository.find_for_consumer_and_provider params[:consumer_name], params[:provider_name]
      end

      def find_compatible_pacticipant_versions criteria
        matrix_repository.find_compatible_pacticipant_versions criteria
      end

      def validate_selectors selectors
        error_messages = []

        selectors.each do | selector |
          if selector[:pacticipant_name].nil? && selector[:pacticipant_version_number].nil?
            error_messages << "Please specify the pacticipant name and version"
          elsif selector[:pacticipant_name].nil?
            error_messages << "Please specify the pacticipant name"
          end
        end

        selectors.collect{ |selector| selector[:pacticipant_name] }.compact.each do | pacticipant_name |
          unless pacticipant_service.find_pacticipant_by_name(pacticipant_name)
            error_messages << "Pacticipant '#{pacticipant_name}' not found"
          end
        end

        if error_messages.empty?
          selectors.each do | selector |
            if selector[:pacticipant_version_number]
              version = version_service.find_by_pacticipant_name_and_number(pacticipant_name: selector[:pacticipant_name], pacticipant_version_number: selector[:pacticipant_version_number])
              error_messages << "No pact or verification found for #{selector[:pacticipant_name]} version #{selector[:pacticipant_version_number]}" if version.nil?
            end
          end
        end

        if selectors.size == 0
          error_messages << "Please provide 1 or more version selectors."
        end

        error_messages
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
pact_broker-2.7.0.beta.2 lib/pact_broker/matrix/service.rb