pact_broker-client 1.59.0 → 1.60.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 2804ada47fb99f8b84e46b666b3c020e69dd141910e2c4e43f1c90e0a74ebc90
4
- data.tar.gz: 55cd1049f68154283ce136834a67aef813bae036139730e89c2c11d8a74a7d7e
3
+ metadata.gz: 8cd60c123fbe4481515d784d73f97296280109f50252c150c1c0c083813cb34b
4
+ data.tar.gz: 3b8371bd71d74a2b9ada1b3ba2d54a24f5ae6349ce2c6a44075e72546f6dbf6e
5
5
  SHA512:
6
- metadata.gz: ae440024fcc4e5aab79d3b23c42e4419d36c4c5a35c1d09964c2887c47a2c8dbd4a3043d510536ed2a31935cb1adccc4554ba4a2a36d9b6af369ae322f84b1be
7
- data.tar.gz: 7d555adb6428fe3cf3a3e642ca18ff202f9976036b4de02c683a25bbf56eaa64c5cb9cd3946c55ed8baff25a0a675c2e8a8a84497b2786c2b9fca1f26eef50c3
6
+ metadata.gz: 828e7e3d9eae551b586bff597b7229c5174ab4000fda79cab8567163b7b3c7443c535c35f504f530dc611bee0708240e27a8756bd394f5b9780047b3f8fc2391
7
+ data.tar.gz: 9d64d148a588d7aa240decdab057c2352409944036d35f6d7ff67a18f673107b7324d383a96bdaaa67b14e837556d04b87f91b5126c77e8103e4a3cffd153ff2
@@ -31,7 +31,7 @@ jobs:
31
31
  - uses: actions/checkout@v2
32
32
  with:
33
33
  fetch-depth: 0
34
- - uses: pact-foundation/release-gem@v0.0.12
34
+ - uses: pact-foundation/release-gem@v0.0.13
35
35
  id: release
36
36
  env:
37
37
  GEM_HOST_API_KEY: '${{ secrets.RUBYGEMS_API_KEY }}'
data/CHANGELOG.md CHANGED
@@ -1,3 +1,10 @@
1
+ <a name="v1.60.0"></a>
2
+ ### v1.60.0 (2022-05-03)
3
+
4
+ #### Features
5
+
6
+ * support merging message pacts when publishing ([732b22d](/../../commit/732b22d))
7
+
1
8
  <a name="v1.59.0"></a>
2
9
  ### v1.59.0 (2022-03-11)
3
10
 
@@ -18,29 +18,40 @@ module PactBroker
18
18
  def merge original, additional
19
19
  new_pact = JSON.parse(original.to_json, symbolize_names: true)
20
20
 
21
- additional[:interactions].each do |new_interaction|
21
+ merge_interactions_or_messages(new_pact, original, additional, :interactions)
22
+ merge_interactions_or_messages(new_pact, original, additional, :messages)
23
+
24
+ new_pact
25
+ end
26
+
27
+ private
28
+
29
+ def merge_interactions_or_messages(new_pact, original, additional, key)
30
+ return unless additional[key] || original[key]
31
+
32
+ additional_messages_or_interactions = additional[key] || []
33
+ original_messages_or_interactions = original[key] || []
34
+ new_pact[key] ||= []
35
+
36
+ additional_messages_or_interactions.each do |new_interaction|
22
37
  # check to see if this interaction matches an existing interaction
23
- overwrite_index = original[:interactions].find_index do |original_interaction|
38
+ overwrite_index = original_messages_or_interactions.find_index do |original_interaction|
24
39
  same_description_and_state?(original_interaction, new_interaction)
25
40
  end
26
41
 
27
42
  # overwrite existing interaction if a match is found, otherwise appends the new interaction
28
43
  if overwrite_index
29
- if new_interaction == original[:interactions][overwrite_index]
30
- new_pact[:interactions][overwrite_index] = new_interaction
44
+ if new_interaction == original_messages_or_interactions[overwrite_index]
45
+ new_pact[key][overwrite_index] = new_interaction
31
46
  else
32
- raise PactMergeError, almost_duplicate_message(original[:interactions][overwrite_index], new_interaction)
47
+ raise PactMergeError, almost_duplicate_message(original_messages_or_interactions[overwrite_index], new_interaction)
33
48
  end
34
49
  else
35
- new_pact[:interactions] << new_interaction
50
+ new_pact[key] << new_interaction
36
51
  end
37
52
  end
38
-
39
- new_pact
40
53
  end
41
54
 
42
- private
43
-
44
55
  def almost_duplicate_message(original, new_interaction)
45
56
  "Two interactions have been found with same description (#{new_interaction[:description].inspect}) and provider state (#{new_interaction[:providerState].inspect}) but a different request or response. " +
46
57
  "Please use a different description or provider state, or hard-code any random data.\n\n" +
@@ -1,5 +1,5 @@
1
1
  module PactBroker
2
2
  module Client
3
- VERSION = '1.59.0'
3
+ VERSION = '1.60.0'
4
4
  end
5
5
  end
@@ -4,63 +4,166 @@ module PactBroker
4
4
  module Client
5
5
  describe MergePacts do
6
6
  describe ".call" do
7
- let(:pact_hash_1) do
8
- {
9
- other: 'info',
10
- interactions: [
11
- {providerState: 1, description: 1, foo: 'bar' }
12
- ]
13
- }
14
- end
7
+ describe "with a pact with interactions" do
8
+ let(:pact_hash_1) do
9
+ {
10
+ other: 'info',
11
+ interactions: [
12
+ { providerState: 1, description: 1, foo: 'bar' }
13
+ ]
14
+ }
15
+ end
15
16
 
16
- let(:pact_hash_2) do
17
- {
18
- interactions: [
19
- {providerState: 2, description: 2, foo: 'wiffle' }
20
- ]
21
- }
22
- end
17
+ let(:pact_hash_2) do
18
+ {
19
+ interactions: [
20
+ { providerState: 2, description: 2, foo: 'wiffle' }
21
+ ]
22
+ }
23
+ end
23
24
 
24
- let(:pact_hash_3) do
25
- {
26
- interactions: [
27
- {providerState: 3, description: 3, foo: 'meep' },
28
- {providerState: 1, description: 1, foo: 'bar' }
29
- ]
30
- }
31
- end
25
+ let(:pact_hash_3) do
26
+ {
27
+ interactions: [
28
+ { providerState: 3, description: 3, foo: 'meep' },
29
+ { providerState: 1, description: 1, foo: 'bar' }
30
+ ]
31
+ }
32
+ end
32
33
 
33
- let(:pact_hashes) { [pact_hash_1, pact_hash_2, pact_hash_3] }
34
-
35
- let(:expected_merge) do
36
- {
37
- other: 'info',
38
- interactions: [
39
- {providerState: 1, description: 1, foo: 'bar' },
40
- {providerState: 2, description: 2, foo: 'wiffle' },
41
- {providerState: 3, description: 3, foo: 'meep' }
42
- ]
43
- }
44
- end
34
+ let(:pact_hashes) { [pact_hash_1, pact_hash_2, pact_hash_3] }
35
+
36
+ let(:expected_merge) do
37
+ {
38
+ other: 'info',
39
+ interactions: [
40
+ { providerState: 1, description: 1, foo: 'bar' },
41
+ { providerState: 2, description: 2, foo: 'wiffle' },
42
+ { providerState: 3, description: 3, foo: 'meep' }
43
+ ]
44
+ }
45
+ end
46
+
47
+ subject { MergePacts.call(pact_hashes) }
45
48
 
46
- subject { MergePacts.call(pact_hashes) }
49
+ it "merges the interactions by consumer/provider" do
50
+ expect(subject).to eq expected_merge
51
+ end
52
+
53
+ context "when an interaction is found with the same state and description but has a difference elsewhere" do
54
+ let(:pact_hash_3) do
55
+ {
56
+ interactions: [
57
+ { providerState: 3, description: 3, foo: 'meep' },
58
+ { providerState: 1, description: 1, foo: 'different' }
59
+ ]
60
+ }
61
+ end
47
62
 
48
- it "merges the interactions by consumer/provider" do
49
- expect(subject).to eq expected_merge
63
+ it "raises an error" do
64
+ expect { subject }.to raise_error PactMergeError, /foo.*different/
65
+ end
66
+ end
50
67
  end
51
68
 
52
- context "when an interaction is found with the same state and description but has a difference elsewhere" do
69
+ describe "with a pact with messages" do
70
+ let(:pact_hash_1) do
71
+ {
72
+ other: 'info',
73
+ messages: [
74
+ { providerState: 1, description: 1, foo: 'bar' }
75
+ ]
76
+ }
77
+ end
78
+
79
+ let(:pact_hash_2) do
80
+ {
81
+ messages: [
82
+ { providerState: 2, description: 2, foo: 'wiffle' }
83
+ ]
84
+ }
85
+ end
86
+
53
87
  let(:pact_hash_3) do
88
+ {
89
+ messages: [
90
+ { providerState: 3, description: 3, foo: 'meep' },
91
+ { providerState: 1, description: 1, foo: 'bar' }
92
+ ]
93
+ }
94
+ end
95
+
96
+ let(:pact_hashes) { [pact_hash_1, pact_hash_2, pact_hash_3] }
97
+
98
+ let(:expected_merge) do
99
+ {
100
+ other: 'info',
101
+ messages: [
102
+ { providerState: 1, description: 1, foo: 'bar' },
103
+ { providerState: 2, description: 2, foo: 'wiffle' },
104
+ { providerState: 3, description: 3, foo: 'meep' }
105
+ ]
106
+ }
107
+ end
108
+
109
+ subject { MergePacts.call(pact_hashes) }
110
+
111
+ it "merges the messages by consumer/provider" do
112
+ expect(subject).to eq expected_merge
113
+ end
114
+
115
+ context "when an interaction is found with the same state and description but has a difference elsewhere" do
116
+ let(:pact_hash_3) do
117
+ {
118
+ messages: [
119
+ { providerState: 3, description: 3, foo: 'meep' },
120
+ { providerState: 1, description: 1, foo: 'different' }
121
+ ]
122
+ }
123
+ end
124
+
125
+ it "raises an error" do
126
+ expect { subject }.to raise_error PactMergeError, /foo.*different/
127
+ end
128
+ end
129
+ end
130
+
131
+ describe "with a pact with messages and a pact with interactions" do
132
+ let(:pact_hash_1) do
133
+ {
134
+ other: 'info',
135
+ messages: [
136
+ { providerState: 1, description: 1, foo: 'bar' }
137
+ ]
138
+ }
139
+ end
140
+
141
+ let(:pact_hash_2) do
54
142
  {
55
143
  interactions: [
56
- {providerState: 3, description: 3, foo: 'meep' },
57
- {providerState: 1, description: 1, foo: 'different' }
144
+ { providerState: 2, description: 2, foo: 'wiffle' }
58
145
  ]
59
146
  }
60
147
  end
61
148
 
62
- it "raises an error" do
63
- expect { subject }.to raise_error PactMergeError, /foo.*different/
149
+ let(:pact_hashes) { [pact_hash_1, pact_hash_2] }
150
+
151
+ let(:expected_merge) do
152
+ {
153
+ other: 'info',
154
+ messages: [
155
+ { providerState: 1, description: 1, foo: 'bar' }
156
+ ],
157
+ interactions: [
158
+ { providerState: 2, description: 2, foo: 'wiffle' }
159
+ ]
160
+ }
161
+ end
162
+
163
+ subject { MergePacts.call(pact_hashes) }
164
+
165
+ it "merges the messages by consumer/provider" do
166
+ expect(subject).to eq expected_merge
64
167
  end
65
168
  end
66
169
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pact_broker-client
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.59.0
4
+ version: 1.60.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Beth Skurrie
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-03-15 00:00:00.000000000 Z
11
+ date: 2022-05-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: httparty
@@ -425,7 +425,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
425
425
  - !ruby/object:Gem::Version
426
426
  version: '0'
427
427
  requirements: []
428
- rubygems_version: 3.3.9
428
+ rubygems_version: 3.3.12
429
429
  signing_key:
430
430
  specification_version: 4
431
431
  summary: See description