api_test.rb
1.72 KB
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
require File.dirname(__FILE__) + '/../../../../test/unit/api/test_helper'
require File.dirname(__FILE__) + '/../helpers/plugin_test_helper'
class GovUserApiTest < ActiveSupport::TestCase
include PluginTestHelper
def setup
login_api
environment = Environment.default
environment.enable_plugin(GovUserPlugin)
@gov_power = GovernmentalPower.create(:name=>"Some Gov Power")
@gov_sphere = GovernmentalSphere.create(:name=>"Some Gov Sphere")
@juridical_nature = JuridicalNature.create(:name => "Autarquia")
@institution = create_public_institution(
"Ministerio Publico da Uniao",
"MPU",
"BR",
"DF",
"Gama",
@juridical_nature,
@gov_power,
@gov_sphere,
"11.222.333/4444-55")
end
should 'list all institutions' do
@institution1 = create_public_institution(
"Instituicao bacana",
"IB",
"BR",
"DF",
"Gama",
@juridical_nature,
@gov_power,
@gov_sphere,
"11.222.333/4444-56"
)
get "/api/v1/gov_user/institutions?#{params.to_query}"
json = JSON.parse(last_response.body)
assert_equivalent [@institution.id, @institution1.id], json['institutions'].map {|c| c['id']}
end
should 'get institution by id' do
get "/api/v1/gov_user/institutions/#{@institution.id}?#{params.to_query}"
json = JSON.parse(last_response.body)
assert_equal @institution.id, json["institution"]["id"]
end
end