summaryrefslogtreecommitdiff
path: root/test/unit/request_handlers/leap_email_handler_test.rb
blob: fadb9149400c9bf49e063f96f1f8b79f156648c7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
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