-
Notifications
You must be signed in to change notification settings - Fork 46
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(v3): parse array of provider states with params
- Loading branch information
Showing
10 changed files
with
180 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
module Pact | ||
class ProviderState | ||
|
||
attr_reader :name, :params | ||
|
||
def initialize name, params = {} | ||
@name = name | ||
@params = params | ||
end | ||
|
||
def self.from_hash(hash) | ||
new(hash["name"], hash["params"]) | ||
end | ||
|
||
def ==(other) | ||
other.is_a?(Pact::ProviderState) && other.name == self.name && other.params == self.params | ||
end | ||
|
||
def to_hash | ||
{ | ||
"name" => name, | ||
"params" => params | ||
} | ||
end | ||
|
||
def to_json(opts = {}) | ||
as_json(opts).to_json(opts) | ||
end | ||
|
||
def as_json(opts = {}) | ||
to_hash | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
54 changes: 54 additions & 0 deletions
54
spec/lib/pact/consumer_contract/interaction_v2_parser_spec.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
require 'pact/consumer_contract/interaction_v2_parser' | ||
|
||
module Pact | ||
describe InteractionV2Parser do | ||
describe ".call" do | ||
let(:interaction_hash) do | ||
{ | ||
"description" => "description", | ||
"request" => { "method" => "GET", "path" => "/" }, | ||
"response" => { "status" => 200 }, | ||
"providerState" => "foo" | ||
} | ||
end | ||
|
||
let(:options) do | ||
{ | ||
pact_specification_version: Pact::SpecificationVersion.new("3.0") | ||
} | ||
end | ||
|
||
subject { InteractionV2Parser.call(interaction_hash, options) } | ||
|
||
describe "provider_states" do | ||
it "returns an array of provider states with size 1" do | ||
expect(subject.provider_states.size).to eq 1 | ||
end | ||
|
||
it "sets the name of the provider state to the string provided" do | ||
expect(subject.provider_states.first.name) | ||
end | ||
|
||
it "sets the params to an empty hash" do | ||
expect(subject.provider_states.first.params).to eq({}) | ||
end | ||
|
||
context "when the providerState is nil" do | ||
before do | ||
interaction_hash["providerState"] = nil | ||
end | ||
|
||
it "returns an empty list" do | ||
expect(subject.provider_states).to be_empty | ||
end | ||
end | ||
end | ||
|
||
describe "provider_state" do | ||
it "sets the name from the hash" do | ||
expect(subject.provider_state).to eq "foo" | ||
end | ||
end | ||
end | ||
end | ||
end |
48 changes: 48 additions & 0 deletions
48
spec/lib/pact/consumer_contract/interaction_v3_parser_spec.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
require 'pact/consumer_contract/interaction_v3_parser' | ||
|
||
module Pact | ||
describe InteractionV3Parser do | ||
describe ".call" do | ||
|
||
let(:interaction_hash) do | ||
{ | ||
"description" => "description", | ||
"request" => { "method" => "GET", "path" => "/" }, | ||
"response" => { "status" => 200 }, | ||
"providerStates" => [{ | ||
"name" => "foo", | ||
"params" => {"a" => "b"} | ||
}] | ||
} | ||
end | ||
|
||
let(:options) do | ||
{ | ||
pact_specification_version: Pact::SpecificationVersion.new("3.0") | ||
} | ||
end | ||
|
||
subject { InteractionV3Parser.call(interaction_hash, options) } | ||
|
||
describe "provider_states" do | ||
it "parses the array of provider states" do | ||
expect(subject.provider_states.size).to eq 1 | ||
end | ||
|
||
it "parses the name of each" do | ||
expect(subject.provider_states.first.name) | ||
end | ||
|
||
it "parses the params of each" do | ||
expect(subject.provider_states.first.params).to eq "a" => "b" | ||
end | ||
end | ||
|
||
describe "provider_state" do | ||
it "sets the provider_state string to the name of the first providerState for backwards compatibility while we implement v3" do | ||
expect(subject.provider_state).to eq "foo" | ||
end | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters