diff options
| author | mo <mo@mokhan.ca> | 2018-05-07 14:29:04 -0600 |
|---|---|---|
| committer | mo <mo@mokhan.ca> | 2018-05-07 14:29:04 -0600 |
| commit | 2c5b1698b2d3cbed1df2bd17c67622f4e415286d (patch) | |
| tree | d39a0a60debabde5a13a8f982cfc162893e2a14a /test/net | |
| parent | 14ea3230db9f0cff4d976cceace10072fa185bd8 (diff) | |
add spec for post and put.
Diffstat (limited to 'test/net')
| -rw-r--r-- | test/net/client_test.rb | 42 |
1 files changed, 42 insertions, 0 deletions
diff --git a/test/net/client_test.rb b/test/net/client_test.rb index 406eab0..7a99ad9 100644 --- a/test/net/client_test.rb +++ b/test/net/client_test.rb @@ -29,4 +29,46 @@ class Net::Hippie::ClientTest < Minitest::Test assert_equal(283, JSON.parse(@response.body).count) end end + + def test_post + VCR.use_cassette("post_breaches") do + uri = URI.parse('https://haveibeenpwned.com/api/breaches') + response = subject.post(uri) + refute_nil response + assert_equal "Congratulations!", JSON.parse(response.body)["Message"] + end + end + + def test_post_with_block_syntax + VCR.use_cassette("post_breaches") do + uri = URI.parse('https://haveibeenpwned.com/api/breaches') + subject.post(uri) do |request, response| + @response = response + end + refute_nil @response + assert_equal "Congratulations!", JSON.parse(@response.body)["Message"] + end + end + + def test_put + VCR.use_cassette("put_breaches") do + uri = URI.parse('https://haveibeenpwned.com/api/breaches') + body = { command: 'echo hello' }.to_json + response = subject.put(uri, body: body) + refute_nil response + assert_equal "Congratulations!", JSON.parse(response.body)["Message"] + end + end + + def test_put_with_block_syntax + VCR.use_cassette("put_breaches") do + uri = URI.parse('https://haveibeenpwned.com/api/breaches') + body = { command: 'echo hello' }.to_json + subject.put(uri, body: body) do |request, response| + @response = response + end + refute_nil @response + assert_equal "Congratulations!", JSON.parse(@response.body)["Message"] + end + end end |
