summaryrefslogtreecommitdiff
path: root/test/unit/hkp/client_test.rb
blob: 9784d0a44aa6fa0cef91302ec71ddd7a9942905e (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
42
43
44
45
46
47
48
49
50
51
52
53
require 'test_helper'
require 'nickserver/hkp/client'

module Nickserver::Hkp
  class ClientTest < Minitest::Test

    def test_get_key_infos_by_email
      adapter_expects_query op: "vindex",
        search: email,
        options: "mr",
        fingerprint: "on",
        exact: "on"
      client.get_key_infos_by_email(email)
      @adapter.verify
    end

    def test_key_by_fingerprint
      adapter_expects_query op: "get",
        search: "0x#{fingerprint}",
        options: "mr",
        exact: "on"
      client.get_key_by_fingerprint(fingerprint)
      @adapter.verify
    end

    def client
      @client ||= Client.new @adapter
    end

    def adapter_expects_query(query = {})
      adapter_expects Nickserver::Config.hkp_url, query: query
    end

    def adapter_expects(*args)
      @adapter = Minitest::Mock.new
      @adapter.expect :get, dummy_response,
        args
    end

    def email
      'dummy_email'
    end

    def fingerprint
      'dummy_fingerprint'
    end

    def dummy_response
      [200, 'dummy_response']
    end

  end
end