Make tests conform with #924

This commit is contained in:
Maciej Szlosarczyk 2018-07-30 10:30:57 +03:00
parent 3adb85001a
commit ed1afb78f6
No known key found for this signature in database
GPG key ID: 41D62D42D3B0D765
2 changed files with 2 additions and 2 deletions

View file

@ -0,0 +1,58 @@
require 'test_helper'
class RegistrantApiAuthenticationTest < ActionDispatch::IntegrationTest
def setup
super
@user_hash = {ident: '37010100049', first_name: 'Adam', last_name: 'Baker'}
@existing_user = RegistrantUser.find_or_create_by_api_data(@user_hash)
end
def teardown
super
end
def test_request_creates_user_when_one_does_not_exist
params = {
ident: '30110100103',
first_name: 'John',
last_name: 'Smith',
}
post '/api/v1/registrant/auth/eid', params
assert(User.find_by(registrant_ident: 'EE-30110100103'))
json = JSON.parse(response.body, symbolize_names: true)
assert_equal([:access_token, :expires_at, :type], json.keys)
end
def test_request_returns_existing_user
assert_no_changes User.count do
post '/api/v1/registrant/auth/eid', @user_hash
end
end
def test_request_returns_401_from_a_not_whitelisted_ip
params = { foo: :bar, test: :test }
@original_whitelist_ip = ENV['registrant_api_auth_allowed_ips']
ENV['registrant_api_auth_allowed_ips'] = '1.2.3.4'
post '/api/v1/registrant/auth/eid', params
assert_equal(401, response.status)
json_body = JSON.parse(response.body, symbolize_names: true)
assert_equal({error: 'Not authorized'}, json_body)
ENV['registrant_api_auth_allowed_ips'] = @original_whitelist_ip
end
def test_request_documented_parameters_are_required
params = { foo: :bar, test: :test }
post '/api/v1/registrant/auth/eid', params
json = JSON.parse(response.body, symbolize_names: true)
assert_equal({errors: [{ident: ['parameter is required']}]}, json)
assert_equal(422, response.status)
end
end

View file

@ -0,0 +1,32 @@
require 'test_helper'
require 'auth_token/auth_token_creator'
class RegistrantApiDomainsTest < ActionDispatch::IntegrationTest
def setup
super
@user = users(:registrant)
@auth_headers = { 'HTTP_AUTHORIZATION' => auth_token }
end
def test_root_returns_domain_list
get '/api/v1/registrant/domains', {}, @auth_headers
assert_equal(200, response.status)
end
def test_root_returns_401_without_authorization
get '/api/v1/registrant/domains', {}, {}
assert_equal(401, response.status)
json_body = JSON.parse(response.body, symbolize_names: true)
assert_equal({error: 'Not authorized'}, json_body)
end
private
def auth_token
token_creator = AuthTokenCreator.create_with_defaults(@user)
hash = token_creator.token_in_hash
"Bearer #{hash[:access_token]}"
end
end