|
1 | | -require_relative '../lib/ruby_http_client' |
| 1 | +require 'ruby_http_client' |
2 | 2 | require 'minitest/autorun' |
3 | 3 |
|
4 | 4 | class MockResponse |
@@ -95,6 +95,63 @@ def test_build_request |
95 | 95 | assert_equal(response.headers, 'headers' => 'test') |
96 | 96 | end |
97 | 97 |
|
| 98 | + def test_build_request_post_empty_content_type |
| 99 | + headers = { |
| 100 | + } |
| 101 | + client = MockRequest.new( |
| 102 | + host: 'https://localhost', |
| 103 | + request_headers: headers, |
| 104 | + version: 'v3' |
| 105 | + ) |
| 106 | + args = [{'request_body' => {"hogekey" => "hogevalue"}}] |
| 107 | + client.build_request('post', args) |
| 108 | + assert_equal('application/json', client.request['Content-Type']) |
| 109 | + assert_equal('{"hogekey":"hogevalue"}', client.request.body) |
| 110 | + end |
| 111 | + |
| 112 | + def test_build_request_get_application_json |
| 113 | + headers = { |
| 114 | + 'Content-Type' => 'application/json' |
| 115 | + } |
| 116 | + client = MockRequest.new( |
| 117 | + host: 'https://localhost', |
| 118 | + request_headers: headers, |
| 119 | + version: 'v3' |
| 120 | + ) |
| 121 | + client.build_request('get', nil) |
| 122 | + assert_equal('application/json', client.request['Content-Type']) |
| 123 | + assert_equal(nil, client.request.body) |
| 124 | + end |
| 125 | + |
| 126 | + def test_build_request_post_empty_body |
| 127 | + headers = { |
| 128 | + 'Content-Type' => 'application/json' |
| 129 | + } |
| 130 | + client = MockRequest.new( |
| 131 | + host: 'https://localhost', |
| 132 | + request_headers: headers, |
| 133 | + version: 'v3' |
| 134 | + ) |
| 135 | + client.build_request('post', nil) |
| 136 | + assert_equal('', client.request['Content-Type']) |
| 137 | + assert_equal(nil, client.request.body) |
| 138 | + end |
| 139 | + |
| 140 | + def test_build_request_post_multipart |
| 141 | + headers = { |
| 142 | + 'Content-Type' => 'multipart/form-data; boundary=xYzZY' |
| 143 | + } |
| 144 | + client = MockRequest.new( |
| 145 | + host: 'https://localhost', |
| 146 | + request_headers: headers, |
| 147 | + ) |
| 148 | + name = 'post' |
| 149 | + args = [{'request_body' => 'hogebody'}] |
| 150 | + client.build_request(name, args) |
| 151 | + assert_equal('multipart/form-data; boundary=xYzZY', client.request['Content-Type']) |
| 152 | + assert_equal('hogebody', client.request.body) |
| 153 | + end |
| 154 | + |
98 | 155 | def add_ssl |
99 | 156 | uri = URI.parse('https://localhost:4010') |
100 | 157 | http = Net::HTTP.new(uri.host, uri.port) |
|
0 commit comments