-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathendpoint_test.rb
60 lines (48 loc) · 1.58 KB
/
endpoint_test.rb
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
54
55
56
57
58
59
60
# encoding: utf-8
require 'test_helper'
class EndpointTest < Test::Unit::TestCase
def setup
ENV['ENIGMA_KEY'] = 'test_key'
@datapath = 'us.gov.whitehouse.visitor-list'
@ep = Enigma::Endpoint.new(@datapath)
end
def test_needs_datapath
assert_raises ArgumentError do
Enigma::Endpoint.new
end
end
def test_query_params
ep = Enigma::Endpoint.new(@datapath, limit: 100)
assert_equal({ limit: 100 }, ep.params)
end
def test_query_params_includes_page
ep = Enigma::Endpoint.new(@datapath, page: 2)
assert_equal({ page: 2 }, ep.params)
end
def test_has_descendants
assert Enigma::Endpoint.descendants.include? Enigma::Meta
end
def test_where_clause_from_hash
assert_equal 'firstName=Steve', @ep.serialize_where({ firstName: 'Steve' })
end
def test_where_clause_from_string
assert_equal 'firstName=Steve', @ep.serialize_where('firstName=Steve')
end
def test_search_clause_from_hash
search_hash = { nameFirst: 'andrew', nameLast: ['white', 'brown', 'black'] }
assert_equal('@nameFirst (andrew) @nameLast (white|brown|black)',
@ep.serialize_search(search_hash))
end
def test_search_clause_from_string
search = '@namefirst (andrew) @namelast (white|brown)'
assert_equal(search, @ep.serialize_search(search))
end
def test_select_clause_from_string
select = 'namefirst,namelast'
assert_equal(select, @ep.serialize_select(select))
end
def test_select_clause_from_array
select = ['namefirst', 'namelast']
assert_equal('namefirst,namelast', @ep.serialize_select(select))
end
end