wiremock_mapper 2.2.0 → 3.0.1

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
  SHA1:
3
- metadata.gz: c3fdaf71440c51a4648dcc4534f688c62abe7755
4
- data.tar.gz: 7af614da1cda843e0748057ac7f45e50180b091d
3
+ metadata.gz: dd13a0f1eff1e53fd61ea5b266700e90b81e20f1
4
+ data.tar.gz: 4f80be02c3be9e61ccec869dfb977ad9bd069815
5
5
  SHA512:
6
- metadata.gz: 63e5efb18734e6e456a31b7843565f86c865a189b340348acc0608bf89e323ee3b5ac8cc9a1e708838093498ac75cd8bee08ddfad15836249126e50e81d531a7
7
- data.tar.gz: f9102da2871d5be756d3c895c790c2ec4b1ddee258299610a2bc82b8a3cc725b7af4aee647f955e14dac2f1e40b86eb026ce3c5497c946193e71134160ba7545
6
+ metadata.gz: d2705c02ff0d9879b7efcf9397af14d8480274a0846168facc8df1d6a19ca7864a8a6035266cd95318370c15a0542f629fb71f839f3f245bba795a416a5a4de8
7
+ data.tar.gz: 23d280483e43063164ca19ad43f00b8c698c615513d036d49693074151db5810c2ff9400e8a399bbbee95fd9a847e71df2d2454f4d36770233ab330a9926c638
data/.rubocop.yml CHANGED
@@ -17,3 +17,6 @@ Style/Documentation:
17
17
 
18
18
  Style/FrozenStringLiteralComment:
19
19
  Enabled: false
20
+
21
+ Gemspec/RequiredRubyVersion:
22
+ Enabled: false
data/Rakefile CHANGED
@@ -3,7 +3,7 @@ require 'rubocop/rake_task'
3
3
 
4
4
  RSpec::Core::RakeTask.new(:spec)
5
5
 
6
- task default: [:rubocop, :spec]
6
+ task default: %i[rubocop spec]
7
7
 
8
8
  RuboCop::RakeTask.new(:rubocop) do |task|
9
9
  task.patterns = ['lib/**/*.rb', 'spec/**/*.rb']
@@ -52,7 +52,8 @@ module WireMockMapper
52
52
  # @param transformer name [String]
53
53
  # @return [ResponseBuilder] response builder for chaining
54
54
  def with_transformer(transformer)
55
- @options[:transformer] = transformer
55
+ @options[:transformers] ||= []
56
+ @options[:transformers] << transformer
56
57
  self
57
58
  end
58
59
 
data/lib/configuration.rb CHANGED
@@ -5,13 +5,14 @@ require_relative 'builders/scenario_builder'
5
5
  module WireMockMapper
6
6
  class Configuration
7
7
  @wiremock_url = ''
8
+ @wiremock_headers = {}
8
9
 
9
10
  @request_builder = Builders::RequestBuilder.new
10
11
  @response_builder = Builders::ResponseBuilder.new
11
12
  @scenario_builder = Builders::ScenarioBuilder.new
12
13
 
13
14
  class << self
14
- attr_reader :request_builder, :response_builder, :wiremock_url, :scenario_builder
15
+ attr_reader :request_builder, :response_builder, :wiremock_url, :wiremock_headers, :scenario_builder
15
16
 
16
17
  # Add mappings to include for all future mappings
17
18
  def create_global_mapping
@@ -29,6 +30,12 @@ module WireMockMapper
29
30
  def set_wiremock_url(url)
30
31
  @wiremock_url = url
31
32
  end
33
+
34
+ # Set the WireMock headers
35
+ # @param headers [hash] all the header that we need to set for wiremock
36
+ def set_wiremock_headers(headers)
37
+ @wiremock_headers = headers
38
+ end
32
39
  end
33
40
  end
34
41
  end
@@ -40,6 +40,10 @@ module WireMockMapper
40
40
  WIREMOCK_CLEAR_MAPPINGS_PATH = "#{WIREMOCK_MAPPINGS_PATH}/reset".freeze
41
41
  WIREMOCK_RESET_SCENARIOS_PATH = '__admin/scenarios/reset'.freeze
42
42
 
43
+ def headers
44
+ { 'Content-Type' => 'application/json' }.merge(Configuration.wiremock_headers)
45
+ end
46
+
43
47
  def deep_clone(object)
44
48
  Marshal.load(Marshal.dump(object))
45
49
  end
@@ -48,7 +52,7 @@ module WireMockMapper
48
52
  uri = URI([url, WIREMOCK_CLEAR_MAPPINGS_PATH].join('/'))
49
53
  http = Net::HTTP.new(uri.host, uri.port)
50
54
  http.use_ssl = true if uri.port == 443
51
- request = Net::HTTP::Post.new(uri.path)
55
+ request = Net::HTTP::Post.new(uri.path, headers)
52
56
  http.request(request)
53
57
  end
54
58
 
@@ -56,7 +60,7 @@ module WireMockMapper
56
60
  uri = URI([url, WIREMOCK_MAPPINGS_PATH, mapping_id].join('/'))
57
61
  http = Net::HTTP.new(uri.host, uri.port)
58
62
  http.use_ssl = true if uri.port == 443
59
- request = Net::HTTP::Delete.new(uri.path)
63
+ request = Net::HTTP::Delete.new(uri.path, headers)
60
64
  http.request(request)
61
65
  end
62
66
 
@@ -64,7 +68,7 @@ module WireMockMapper
64
68
  uri = URI([url, WIREMOCK_MAPPINGS_PATH].join('/'))
65
69
  http = Net::HTTP.new(uri.host, uri.port)
66
70
  http.use_ssl = true if uri.port == 443
67
- request = Net::HTTP::Post.new(uri.path, 'Content-Type' => 'application/json')
71
+ request = Net::HTTP::Post.new(uri.path, headers)
68
72
  request.body = body.to_json
69
73
  http.request(request)
70
74
  end
@@ -73,7 +77,7 @@ module WireMockMapper
73
77
  uri = URI([url, WIREMOCK_RESET_SCENARIOS_PATH].join('/'))
74
78
  http = Net::HTTP.new(uri.host, uri.port)
75
79
  http.use_ssl = true if uri.port == 443
76
- request = Net::HTTP::Post.new(uri.path)
80
+ request = Net::HTTP::Post.new(uri.path, headers)
77
81
  http.request(request)
78
82
  end
79
83
  end
@@ -24,4 +24,11 @@ describe WireMockMapper::Configuration do
24
24
  expect(WireMockMapper::Configuration.wiremock_url).to eq('http://whereever.com')
25
25
  end
26
26
  end
27
+
28
+ describe 'wiremock_headers' do
29
+ it 'sets the wiremock headers' do
30
+ WireMockMapper::Configuration.set_wiremock_headers({ 'Authorization' => 'Bearer ABC123' })
31
+ expect(WireMockMapper::Configuration.wiremock_headers).to eq({ 'Authorization' => 'Bearer ABC123' })
32
+ end
33
+ end
27
34
  end
@@ -60,7 +60,14 @@ describe WireMockMapper::Builders::ResponseBuilder do
60
60
  it 'adds the transformer for wiremock to use' do
61
61
  builder.with_transformer('optimus prime')
62
62
  result = builder.to_hash
63
- expect(result[:transformer]).to eq('optimus prime')
63
+ expect(result[:transformers]).to eq(['optimus prime'])
64
+ end
65
+
66
+ it 'adds multiple transformers for wiremock to use' do
67
+ builder.with_transformer('optimus prime')
68
+ .with_transformer('megatron')
69
+ result = builder.to_hash
70
+ expect(result[:transformers]).to eq(['optimus prime', 'megatron'])
64
71
  end
65
72
  end
66
73
  end
@@ -3,6 +3,7 @@ require 'spec_helper'
3
3
  describe WireMockMapper do
4
4
  before(:each) do
5
5
  WireMockMapper::Configuration.reset_global_mappings
6
+ WireMockMapper::Configuration.set_wiremock_headers({})
6
7
  end
7
8
 
8
9
  describe 'create_mapping' do
@@ -14,7 +15,7 @@ describe WireMockMapper do
14
15
  'bodyPatterns' => [
15
16
  { 'matches' => 'some request body' }
16
17
  ] },
17
- response: { 'body' => 'some response body' } }
18
+ response: { 'body' => 'some response body', 'transformers' => ['response-template'] } }
18
19
 
19
20
  stub = stub_request(:post, "#{url}/__admin/mappings").with(body: expected_request_body)
20
21
  .to_return(body: { id: 'whatevs' }.to_json)
@@ -26,11 +27,43 @@ describe WireMockMapper do
26
27
  .with_body.matching('some request body')
27
28
 
28
29
  respond.with_body('some response body')
30
+ .with_transformer('response-template')
29
31
  end
30
32
 
31
33
  expect(stub).to have_been_requested
32
34
  end
33
35
 
36
+ it 'posts custom header to the wiremock url' do
37
+ url = 'http://nowhere.com'
38
+ expected_request_body = { request: { 'method' => 'POST',
39
+ 'url' => '/some/url',
40
+ 'headers' => { 'some_global_header' => { 'equalTo' => 'global value' },
41
+ 'some_header' => { 'equalTo' => 'some header value' } },
42
+ 'bodyPatterns' => [
43
+ { 'matches' => 'some request body' }
44
+ ] },
45
+ response: { 'body' => 'some response body' } }
46
+
47
+ stub = stub_request(:post, "#{url}/__admin/mappings").with(body: expected_request_body)
48
+ .to_return(body: { id: 'whatevs' }.to_json)
49
+
50
+ WireMockMapper::Configuration.create_global_mapping do |request|
51
+ request.with_header('some_global_header').equal_to('global value')
52
+ end
53
+
54
+ WireMockMapper::Configuration.set_wiremock_headers({ 'header1' => 'header-value1' })
55
+
56
+ WireMockMapper.create_mapping(url) do |request, respond|
57
+ request.is_a_post
58
+ .with_url.equal_to('/some/url')
59
+ .with_header('some_header').equal_to('some header value')
60
+ .with_body.matching('some request body')
61
+ respond.with_body('some response body')
62
+ end
63
+
64
+ expect(stub).to have_requested(:post, "#{url}/__admin/mappings").with(headers: { 'header1' => 'header-value1' })
65
+ end
66
+
34
67
  it 'posts the correct json with configured global mappings to the wiremock url' do
35
68
  url = 'http://nowhere.com'
36
69
  expected_request_body = { request: { 'method' => 'POST',
@@ -129,6 +162,19 @@ describe WireMockMapper do
129
162
 
130
163
  expect(stub).to have_been_requested
131
164
  end
165
+
166
+ it 'issues a DELETE with custom headers for the supplied mapping id' do
167
+ mapping_id = 'james-james-james'
168
+ url = 'http://nowhere.com'
169
+ stub = stub_request(:delete, "#{url}/__admin/mappings/#{mapping_id}")
170
+
171
+ WireMockMapper::Configuration.set_wiremock_headers({ 'header2' => 'header-value2' })
172
+
173
+ WireMockMapper.delete_mapping(mapping_id, url)
174
+
175
+ expect(stub).to have_requested(:delete, "#{url}/__admin/mappings/#{mapping_id}")
176
+ .with(headers: { 'header2' => 'header-value2' })
177
+ end
132
178
  end
133
179
 
134
180
  describe 'clear_mappings' do
@@ -139,5 +185,39 @@ describe WireMockMapper do
139
185
 
140
186
  expect(stub).to have_been_requested
141
187
  end
188
+
189
+ it 'POSTS with custom headers to the wiremock __admin/mappings/reset path' do
190
+ url = 'http://nowhere.com'
191
+ stub = stub_request(:post, "#{url}/__admin/mappings/reset")
192
+
193
+ WireMockMapper::Configuration.set_wiremock_headers({ 'header3' => 'header-value3' })
194
+
195
+ WireMockMapper.clear_mappings(url)
196
+
197
+ expect(stub).to have_requested(:post,
198
+ "#{url}/__admin/mappings/reset").with(headers: { 'header3' => 'header-value3' })
199
+ end
200
+ end
201
+
202
+ describe 'reset_scenarios' do
203
+ it 'POSTS to the wiremock __admin/scenarios/reset path' do
204
+ url = 'http://nowhere.com'
205
+ stub = stub_request(:post, "#{url}/__admin/scenarios/reset")
206
+ WireMockMapper.reset_scenarios(url)
207
+
208
+ expect(stub).to have_been_requested
209
+ end
210
+
211
+ it 'POSTS with custom headers to the wiremock __admin/scenarios/reset path' do
212
+ url = 'http://nowhere.com'
213
+ stub = stub_request(:post, "#{url}/__admin/scenarios/reset")
214
+
215
+ WireMockMapper::Configuration.set_wiremock_headers({ 'header3' => 'header-value3' })
216
+
217
+ WireMockMapper.reset_scenarios(url)
218
+
219
+ expect(stub).to have_requested(:post,
220
+ "#{url}/__admin/scenarios/reset").with(headers: { 'header3' => 'header-value3' })
221
+ end
142
222
  end
143
223
  end
@@ -1,8 +1,8 @@
1
- $LOAD_PATH.unshift(File.expand_path('../lib', __FILE__))
1
+ $LOAD_PATH.unshift(File.expand_path('lib', __dir__))
2
2
 
3
3
  Gem::Specification.new do |spec|
4
4
  spec.name = 'wiremock_mapper'
5
- spec.version = '2.2.0'
5
+ spec.version = '3.0.1'
6
6
  spec.platform = Gem::Platform::RUBY
7
7
  spec.required_ruby_version = '>= 2.0.0'
8
8
  spec.authors = ['Isaac Datlof']
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: wiremock_mapper
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.2.0
4
+ version: 3.0.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Isaac Datlof
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-06-03 00:00:00.000000000 Z
11
+ date: 2023-09-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: codeclimate-test-reporter
@@ -173,7 +173,7 @@ homepage: http://github.com/ike18t/wiremock_mapper
173
173
  licenses:
174
174
  - MIT
175
175
  metadata: {}
176
- post_install_message:
176
+ post_install_message:
177
177
  rdoc_options: []
178
178
  require_paths:
179
179
  - lib
@@ -188,9 +188,9 @@ required_rubygems_version: !ruby/object:Gem::Requirement
188
188
  - !ruby/object:Gem::Version
189
189
  version: '0'
190
190
  requirements: []
191
- rubyforge_project:
191
+ rubyforge_project:
192
192
  rubygems_version: 2.6.8
193
- signing_key:
193
+ signing_key:
194
194
  specification_version: 4
195
195
  summary: Ruby DSL for setting up WireMock mappings
196
196
  test_files: