diff --git a/test/controllers/adopted_controller_test.rb b/test/controllers/adopted_controller_test.rb index f670225f..1b1151b4 100644 --- a/test/controllers/adopted_controller_test.rb +++ b/test/controllers/adopted_controller_test.rb @@ -4,7 +4,15 @@ class AdoptedControllerTest < ActionController::TestCase setup do request.env['devise.mapping'] = Devise.mappings[:user] @user = users(:erik) + @user2 = users(:dan) @admin = users(:admin) + @thing = things(:thing_1) + @thing2 = things(:thing_2) + + @thing.user_id = @user.id + @thing2.user_id = @user2.id + @thing.save + @thing2.save end test 'should get index' do @@ -17,28 +25,41 @@ class AdoptedControllerTest < ActionController::TestCase test 'should get json' do @request.env['HTTP_AUTHORIZATION'] = ActionController::HttpAuthentication::Basic.encode_credentials(@admin.email, 'correct') - get :index, format: :json + get :index assert_equal 'application/json', @response.content_type end - test 'should get xml' do - @request.env['HTTP_AUTHORIZATION'] = ActionController::HttpAuthentication::Basic.encode_credentials(@admin.email, 'correct') + test 'only admins get access' do + @request.env['HTTP_AUTHORIZATION'] = ActionController::HttpAuthentication::Basic.encode_credentials(@user.email, 'correct') - get :index, format: :xml - assert_equal 'application/xml', @response.content_type + get :index + assert_equal 'text/html', @response.content_type # If user were an admin, content_type would be JSON, since that is default end - test 'should get csv' do + + test 'drain data is correct' do @request.env['HTTP_AUTHORIZATION'] = ActionController::HttpAuthentication::Basic.encode_credentials(@admin.email, 'correct') - get :index, format: :csv - assert_equal 'text/csv', @response.content_type - end + get :index + random_drain = JSON.parse(@response.body)["drains"].first - test 'only admins get access' do - @request.env['HTTP_AUTHORIZATION'] = ActionController::HttpAuthentication::Basic.encode_credentials(@user.email, 'correct') + drain = Thing.find_by(city_id: random_drain["city_id"].gsub("N-","")) + assert_not_nil drain + assert_equal drain.lat.to_s, random_drain["latitude"] + assert_equal drain.lng.to_s, random_drain["longitude"] + + end + + test 'page counts' do + @request.env['HTTP_AUTHORIZATION'] = ActionController::HttpAuthentication::Basic.encode_credentials(@admin.email, 'correct') + get :index - assert_equal 'text/html', @response.content_type # If user were an admin, content_type would be JSON, since that is default + json = JSON.parse(@response.body) + puts(json) + + assert_equal json["next_page"], 2 + assert_equal json["prev_page"], -1 + assert_equal json["total_pages"], 1 end end