Skip to content

Commit

Permalink
feat: add request and response to message
Browse files Browse the repository at this point in the history
  • Loading branch information
bethesque committed Feb 8, 2018
1 parent 6573bd4 commit 93839cf
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 2 deletions.
2 changes: 1 addition & 1 deletion lib/pact/consumer_contract/consumer_contract.rb
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ def self.from_hash(hash)
elsif hash[:messages]
hash[:messages].collect { |hash| Message.from_hash(hash)}
else
[]
[] # or raise an error?
end

new(
Expand Down
8 changes: 8 additions & 0 deletions lib/pact/consumer_contract/interaction.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,14 @@ def to_hash
}
end

def http?
true
end

def message?
false
end

def validate!
raise Pact::InvalidInteractionError.new(self) unless description && request && response
end
Expand Down
39 changes: 38 additions & 1 deletion lib/pact/consumer_contract/message.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
require 'pact/shared/active_support_support'
require 'pact/matching_rules'
require 'pact/errors'
require 'pact/consumer/request'
require 'pact/consumer_contract/response'

module Pact
class Message
Expand All @@ -13,8 +15,8 @@ class Message

def initialize attributes = {}
@description = attributes[:description]
@request = attributes[:content]
@provider_state = attributes[:provider_state] || attributes[:providerState]
@content = attributes[:content]
end

def self.from_hash hash
Expand All @@ -31,6 +33,41 @@ def to_hash
}
end


def request
@request ||= Pact::Consumer::Request::Actual.from_hash(
path: '/',
method: 'POST',
query: nil,
headers: {'Content-Type' => 'application/json'},
body: {
description: description,
providerStates: [{
name: provider_state
}]
}
)
end

# custom media type?
def response
@response ||= Pact::Response.new(
status: 200,
headers: {'Content-Type' => 'application/json'},
body: {
content: content
}
)
end

def http?
false
end

def message?
true
end

def validate!
raise Pact::InvalidMessageError.new(self) unless description && content
end
Expand Down
3 changes: 3 additions & 0 deletions lib/pact/consumer_contract/message/content.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ class Content < Hash
include ActiveSupportSupport
include SymbolizeKeys

def initialize hash
merge!(hash)
end
end
end
end

0 comments on commit 93839cf

Please sign in to comment.