summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
Diffstat (limited to 'test')
-rw-r--r--test/support/request_handler_test_helper.rb6
-rw-r--r--test/unit/adapters/celluloid_http_test.rb11
-rw-r--r--test/unit/email_address_test.rb1
-rw-r--r--test/unit/nicknym/source_test.rb33
-rw-r--r--test/unit/request_handlers/leap_email_handler_test.rb41
5 files changed, 88 insertions, 4 deletions
diff --git a/test/support/request_handler_test_helper.rb b/test/support/request_handler_test_helper.rb
index 3ca89ba..dd6940d 100644
--- a/test/support/request_handler_test_helper.rb
+++ b/test/support/request_handler_test_helper.rb
@@ -15,9 +15,9 @@ module RequestHandlerTestHelper
end
def source_expecting_query_for(*query_args)
- source = Minitest::Mock.new
- source.expect :query, 'response', query_args
- source
+ @source ||= Minitest::Mock.new
+ @source.expect :query, 'response', query_args
+ @source
end
def assert_responds_with_error(msg, opts)
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