diff options
author | Azul <azul@riseup.net> | 2016-08-30 12:38:43 +0200 |
---|---|---|
committer | Azul <azul@riseup.net> | 2016-08-31 12:14:52 +0200 |
commit | 625416ac16a1216240fc4c48aa19802ef8a967a1 (patch) | |
tree | f3a4a54627fcae49bf896f5f58e60b506f9a55d4 /test/unit | |
parent | b22e23eb9f5a1cb3e37ab2a26b1091183574f4e4 (diff) |
wip: key lookup by address via leaps nicknym
I added a RequestHandler that uses Nicknym::Source - but that has not
been implemented yet.
Diffstat (limited to 'test/unit')
-rw-r--r-- | test/unit/adapters/celluloid_http_test.rb | 11 | ||||
-rw-r--r-- | test/unit/email_address_test.rb | 1 | ||||
-rw-r--r-- | test/unit/nicknym/source_test.rb | 33 | ||||
-rw-r--r-- | test/unit/request_handlers/leap_email_handler_test.rb | 41 |
4 files changed, 85 insertions, 1 deletions
diff --git a/test/unit/adapters/celluloid_http_test.rb b/test/unit/adapters/celluloid_http_test.rb index 4381b8f..68b9606 100644 --- a/test/unit/adapters/celluloid_http_test.rb +++ b/test/unit/adapters/celluloid_http_test.rb @@ -13,7 +13,16 @@ class Nickserver::Adapters::CelluloidHttpTest < Minitest::Test super end - def test_successful_request + def test_request_without_query + url = 'http://url.to' + stub_http_request(:get, url) + .to_return status: 200, body: 'body' + status, body = adapter.get url + assert_equal 200, status + assert_equal 'body', body + end + + def test_successful_request_with_query url = 'http://url.to' stub_http_request(:get, url) .with(query: {key: :value}) diff --git a/test/unit/email_address_test.rb b/test/unit/email_address_test.rb index 6d57a8c..6aecef7 100644 --- a/test/unit/email_address_test.rb +++ b/test/unit/email_address_test.rb @@ -5,6 +5,7 @@ class EmailAddressTest < Minitest::Test def test_domain nick = Nickserver::EmailAddress.new 'nick@test.me' + assert_equal 'test.me', nick.domain assert nick.domain?('test.me') assert !nick.domain?('est.me') end diff --git a/test/unit/nicknym/source_test.rb b/test/unit/nicknym/source_test.rb new file mode 100644 index 0000000..586dc0e --- /dev/null +++ b/test/unit/nicknym/source_test.rb @@ -0,0 +1,33 @@ +require 'test_helper' +require 'nickserver/nicknym/source' + +class NicknymSourceTest < Minitest::Test + + def test_initialization + assert source + end + + def test_available_for_domain + adapter.expect :get, [200, 'dummy body'], + ['https://leap_powered.tld/provider.json'] + assert source.available_for?('leap_powered.tld') + adapter.verify + end + + def test_not_available_for_domain + adapter.expect :get, [404, nil], + ['https://remote.tld/provider.json'] + assert !source.available_for?('remote.tld') + adapter.verify + end + + protected + + def source + Nickserver::Nicknym::Source.new(adapter) + end + + def adapter + @adapter ||= Minitest::Mock.new + end +end diff --git a/test/unit/request_handlers/leap_email_handler_test.rb b/test/unit/request_handlers/leap_email_handler_test.rb new file mode 100644 index 0000000..fadb914 --- /dev/null +++ b/test/unit/request_handlers/leap_email_handler_test.rb @@ -0,0 +1,41 @@ +require 'test_helper' +require 'support/request_handler_test_helper' +require 'nickserver/request_handlers/leap_email_handler' + +class LeapEmailHandlerTest < MiniTest::Test + include RequestHandlerTestHelper + + def test_no_email + assert_refuses + end + + def test_local_email + assert_refuses email: 'me@local.tld', domain: 'local.tld' + end + + def test_remote_email + source ||= Minitest::Mock.new + source.expect :available_for?, false, ['remote.tld'] + source_class.stub :new, source do + assert_refuses email: 'me@remote.tld', domain: 'local.tld' + end + end + + def test_nicknym_email + @source ||= Minitest::Mock.new + @source.expect :available_for?, true, ['nicknym.tld'] + assert_queries_for Nickserver::EmailAddress do + assert_handles email: 'me@nicknym.tld', domain: 'local.tld' + end + end + + protected + + def handler + Nickserver::RequestHandlers::LeapEmailHandler + end + + def source_class + Nickserver::Nicknym::Source + end +end |