Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat([PoC]): Contract for sequence of messages. #21

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion lib/pact/consumer_contract/message.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,15 @@ class Message
include Pact::ActiveSupportSupport
include Pact::SymbolizeKeys

attr_accessor :description, :contents, :provider_state, :provider_states, :metadata, :_id, :index
attr_accessor :description, :descriptions, :contents, :events, :provider_state, :provider_states, :metadata, :_id, :index

def initialize attributes = {}
@description = attributes[:description]
@descriptions = []
@provider_state = attributes[:provider_state] || attributes[:providerState]
@provider_states = attributes[:provider_states] || []
@contents = attributes[:contents]
@events = []
@metadata = attributes[:metadata]
@_id = attributes[:_id]
@index = attributes[:index]
Expand Down
5 changes: 4 additions & 1 deletion lib/pact/message/consumer/interaction_builder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ def initialize &block
end

def is_expected_to_send description
@interaction.descriptions << description
@interaction.description = description
self
end
Expand All @@ -32,7 +33,9 @@ def with_metadata(object)
end

def with_content(object)
interaction.contents = Pact::Message::Contents.from_hash(object)
message_content = Pact::Message::Contents.from_hash(object)
interaction.events << message_content
interaction.contents = message_content
@callback.call interaction
self
end
Expand Down
6 changes: 4 additions & 2 deletions lib/pact/message/consumer/interaction_decorator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ def initialize message, decorator_options = {}
end

def as_json options = {}
hash = { :description => message.description }
hash = { :description => message.descriptions.join(';') }
hash[:providerStates] = provider_states
hash[:contents] = extract_contents
hash[:matchingRules] = extract_matching_rules
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

📝 matchingRules is still only for a single message

Expand All @@ -36,7 +36,9 @@ def decorate_contents
end

def extract_contents
Pact::Reification.from_term(message.contents.contents)
message.events.map do |message_content|
Pact::Reification.from_term(message_content.contents)
end
Comment on lines +39 to +41
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

📓 It will return an array even for a single record, so when we have only one message content, we show an array [content] in Contract, when we have multiple messages, we show an array of arrays [[Content]]

end

def provider_states
Expand Down