wiremock_mapper 2.2.0 → 3.0.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
  SHA1:
3
- metadata.gz: c3fdaf71440c51a4648dcc4534f688c62abe7755
4
- data.tar.gz: 7af614da1cda843e0748057ac7f45e50180b091d
3
+ metadata.gz: c8b8dde11f7b190ebf968785989ed808421d8856
4
+ data.tar.gz: '08a392c0088c3190258fd8894e06a6301a603e35'
5
5
  SHA512:
6
- metadata.gz: 63e5efb18734e6e456a31b7843565f86c865a189b340348acc0608bf89e323ee3b5ac8cc9a1e708838093498ac75cd8bee08ddfad15836249126e50e81d531a7
7
- data.tar.gz: f9102da2871d5be756d3c895c790c2ec4b1ddee258299610a2bc82b8a3cc725b7af4aee647f955e14dac2f1e40b86eb026ce3c5497c946193e71134160ba7545
6
+ metadata.gz: 88ad4b6f724bb95ff9af529bb39c371ba1bf1a613ebeba7f7ee83aa07af3b5d6fbe2105d3aff875075a802b8add0a13a77b2295ce05e5a4927a2aba2d2e54c54
7
+ data.tar.gz: 76b57620e1af66676ab01f67e0b7f2a516656e50fe12e863dfcfac8f69faac647ab84a368a100f91c0797f6be9cc69561b346097465685f50772cf32bae04e9b
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']
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
@@ -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
@@ -31,6 +32,37 @@ describe WireMockMapper do
31
32
  expect(stub).to have_been_requested
32
33
  end
33
34
 
35
+ it 'posts custom header to the wiremock url' do
36
+ url = 'http://nowhere.com'
37
+ expected_request_body = { request: { 'method' => 'POST',
38
+ 'url' => '/some/url',
39
+ 'headers' => { 'some_global_header' => { 'equalTo' => 'global value' },
40
+ 'some_header' => { 'equalTo' => 'some header value' } },
41
+ 'bodyPatterns' => [
42
+ { 'matches' => 'some request body' }
43
+ ] },
44
+ response: { 'body' => 'some response body' } }
45
+
46
+ stub = stub_request(:post, "#{url}/__admin/mappings").with(body: expected_request_body)
47
+ .to_return(body: { id: 'whatevs' }.to_json)
48
+
49
+ WireMockMapper::Configuration.create_global_mapping do |request|
50
+ request.with_header('some_global_header').equal_to('global value')
51
+ end
52
+
53
+ WireMockMapper::Configuration.set_wiremock_headers({ 'header1' => 'header-value1' })
54
+
55
+ WireMockMapper.create_mapping(url) do |request, respond|
56
+ request.is_a_post
57
+ .with_url.equal_to('/some/url')
58
+ .with_header('some_header').equal_to('some header value')
59
+ .with_body.matching('some request body')
60
+ respond.with_body('some response body')
61
+ end
62
+
63
+ expect(stub).to have_requested(:post, "#{url}/__admin/mappings").with(headers: { 'header1' => 'header-value1' })
64
+ end
65
+
34
66
  it 'posts the correct json with configured global mappings to the wiremock url' do
35
67
  url = 'http://nowhere.com'
36
68
  expected_request_body = { request: { 'method' => 'POST',
@@ -129,6 +161,19 @@ describe WireMockMapper do
129
161
 
130
162
  expect(stub).to have_been_requested
131
163
  end
164
+
165
+ it 'issues a DELETE with custom headers for the supplied mapping id' do
166
+ mapping_id = 'james-james-james'
167
+ url = 'http://nowhere.com'
168
+ stub = stub_request(:delete, "#{url}/__admin/mappings/#{mapping_id}")
169
+
170
+ WireMockMapper::Configuration.set_wiremock_headers({ 'header2' => 'header-value2' })
171
+
172
+ WireMockMapper.delete_mapping(mapping_id, url)
173
+
174
+ expect(stub).to have_requested(:delete, "#{url}/__admin/mappings/#{mapping_id}")
175
+ .with(headers: { 'header2' => 'header-value2' })
176
+ end
132
177
  end
133
178
 
134
179
  describe 'clear_mappings' do
@@ -139,5 +184,39 @@ describe WireMockMapper do
139
184
 
140
185
  expect(stub).to have_been_requested
141
186
  end
187
+
188
+ it 'POSTS with custom headers to the wiremock __admin/mappings/reset path' do
189
+ url = 'http://nowhere.com'
190
+ stub = stub_request(:post, "#{url}/__admin/mappings/reset")
191
+
192
+ WireMockMapper::Configuration.set_wiremock_headers({ 'header3' => 'header-value3' })
193
+
194
+ WireMockMapper.clear_mappings(url)
195
+
196
+ expect(stub).to have_requested(:post,
197
+ "#{url}/__admin/mappings/reset").with(headers: { 'header3' => 'header-value3' })
198
+ end
199
+ end
200
+
201
+ describe 'reset_scenarios' do
202
+ it 'POSTS to the wiremock __admin/scenarios/reset path' do
203
+ url = 'http://nowhere.com'
204
+ stub = stub_request(:post, "#{url}/__admin/scenarios/reset")
205
+ WireMockMapper.reset_scenarios(url)
206
+
207
+ expect(stub).to have_been_requested
208
+ end
209
+
210
+ it 'POSTS with custom headers to the wiremock __admin/scenarios/reset path' do
211
+ url = 'http://nowhere.com'
212
+ stub = stub_request(:post, "#{url}/__admin/scenarios/reset")
213
+
214
+ WireMockMapper::Configuration.set_wiremock_headers({ 'header3' => 'header-value3' })
215
+
216
+ WireMockMapper.reset_scenarios(url)
217
+
218
+ expect(stub).to have_requested(:post,
219
+ "#{url}/__admin/scenarios/reset").with(headers: { 'header3' => 'header-value3' })
220
+ end
142
221
  end
143
222
  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.0'
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.0
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: 2022-11-05 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: