Class: Pact::InteractionV2Parser

Inherits:
Object
  • Object
show all
Includes:
SymbolizeKeys
Defined in:
lib/pact/consumer_contract/interaction_v2_parser.rb

Class Method Summary collapse

Methods included from SymbolizeKeys

included, #symbolize_keys

Class Method Details

.call(hash, options) ⇒ Object



14
15
16
17
18
19
20
21
22
23
# File 'lib/pact/consumer_contract/interaction_v2_parser.rb', line 14

def self.call hash, options
  request = parse_request(hash['request'], options)
  response = parse_response(hash['response'], options)
  provider_states = parse_provider_states(hash['providerState'] || hash['provider_state'])
   = (hash['metadata'])
  Interaction.new(symbolize_keys(hash).merge(request: request,
                                             response: response,
                                             provider_states: provider_states,
                                             metadata: ))
end

.parse_metadata(metadata_hash) ⇒ Object



53
54
55
# File 'lib/pact/consumer_contract/interaction_v2_parser.rb', line 53

def self. 
  symbolize_keys()
end

.parse_provider_states(provider_state_name) ⇒ Object



49
50
51
# File 'lib/pact/consumer_contract/interaction_v2_parser.rb', line 49

def self.parse_provider_states provider_state_name
  provider_state_name ? [Pact::ProviderState.new(provider_state_name)] : []
end

.parse_request(request_hash, options) ⇒ Object



25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/pact/consumer_contract/interaction_v2_parser.rb', line 25

def self.parse_request request_hash, options
  original_query_string = request_hash['query']
  query_is_string = original_query_string.is_a?(String)
  if query_is_string
    request_hash = request_hash.dup
    request_hash['query'] = Pact::Query.parse_string(request_hash['query'])
  end
  # The query has to be a hash at this stage for the matching rules to be applied
  request_hash = Pact::MatchingRules.merge(request_hash, request_hash['matchingRules'], options)
  # The original query string needs to be passed in to the constructor so it can be used
  # when the request is replayed. Otherwise, we loose the square brackets because they get lost
  # in the translation between string => structured object, as we don't know/store which
  # query string convention was used.
  if query_is_string
    request_hash['query'] = Pact::QueryHash.new(request_hash['query'], original_query_string, Pact::Query.parsed_as_nested?(request_hash['query']))
  end
  Pact::Request::Expected.from_hash(request_hash)
end

.parse_response(response_hash, options) ⇒ Object



44
45
46
47
# File 'lib/pact/consumer_contract/interaction_v2_parser.rb', line 44

def self.parse_response response_hash, options
  response_hash = Pact::MatchingRules.merge(response_hash, response_hash['matchingRules'], options)
  Pact::Response.from_hash(response_hash)
end