Commit 2c5b169
Changed files (3)
test
fixtures
net
test/fixtures/post_breaches.yml
@@ -0,0 +1,24 @@
+---
+http_interactions:
+- request:
+ method: post
+ uri: https://haveibeenpwned.com/api/breaches
+ body:
+ encoding: UTF-8
+ string: "{}"
+ headers:
+ Accept:
+ - application/vnd.haveibeenpwned.v2+json
+ response:
+ status:
+ code: 201
+ message: Created
+ headers:
+ Content-Type:
+ - application/json; charset=utf-8
+ body:
+ encoding: UTF-8
+ string: '{"Message":"Congratulations!"}'
+ http_version:
+ recorded_at: Mon, 07 May 2018 20:21:13 GMT
+recorded_with: VCR 4.0.0
test/fixtures/put_breaches.yml
@@ -0,0 +1,24 @@
+---
+http_interactions:
+- request:
+ method: put
+ uri: https://haveibeenpwned.com/api/breaches
+ body:
+ encoding: UTF-8
+ string: "{\"command\":\"echo hello\"}"
+ headers:
+ Accept:
+ - application/vnd.haveibeenpwned.v2+json
+ response:
+ status:
+ code: 201
+ message: Created
+ headers:
+ Content-Type:
+ - application/json; charset=utf-8
+ body:
+ encoding: UTF-8
+ string: '{"Message":"Congratulations!"}'
+ http_version:
+ recorded_at: Mon, 07 May 2018 20:21:13 GMT
+recorded_with: VCR 4.0.0
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