Skip to content

Commit

Permalink
DRY InatControllerTest constants
Browse files Browse the repository at this point in the history
  • Loading branch information
JoeCohen committed Aug 19, 2024
1 parent 3ec2d89 commit 298f94c
Showing 1 changed file with 7 additions and 9 deletions.
16 changes: 7 additions & 9 deletions test/controllers/observations/inat_imports_controller_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,9 @@ def initialize(errors: [], results: [])
end

class InatImportsControllerTest < FunctionalTestCase
INAT_OBS_REQUEST_PREFIX = "https://api.inaturalist.org/v1/observations"
INAT_OBS_REQUEST_POSTFIX = "&order=asc&order_by=id&only_id=false"
# Where iNat will send the code once authorized
REDIRECT_URI =
"http://localhost:3000/observations/inat_imports/authenticate"
SITE = Observations::InatImportsController::SITE
REDIRECT_URI = Observations::InatImportsController::REDIRECT_URI
API_BASE = Observations::InatImportsController::API_BASE

def test_new_inat_import
login(users(:rolf).login)
Expand Down Expand Up @@ -62,7 +60,7 @@ def test_create_no_observations_designated
assert_flash_text(:inat_no_imports_designated.l)
end

def test_create_illega_observation_id
def test_create_illegal_observation_id
params = { inat_username: "anything", inat_ids: "123*",
consent: 1 }
login
Expand Down Expand Up @@ -511,7 +509,7 @@ def stub_token_requests
# stub exchanging iNat code for oauth token
# https://www.inaturalist.org/pages/api+reference#authorization_code_flow
def stub_oauth_token_request
stub_request(:post, "https://www.inaturalist.org/oauth/token").
stub_request(:post, "#{SITE}/oauth/token").
with(
body: { "client_id" => Rails.application.credentials.inat.id,
"client_secret" => Rails.application.credentials.inat.secret,
Expand All @@ -525,7 +523,7 @@ def stub_oauth_token_request
end

def stub_jwt_request
stub_request(:get, "https://www.inaturalist.org/users/api_token").
stub_request(:get, "#{SITE}/users/api_token").
with(
headers: {
"Accept" => "application/json",
Expand All @@ -552,7 +550,7 @@ def stub_inat_api_request(inat_obs_ids, mock_inat_response, id_above: 0,
&order=asc&order_by=id
&user_login=#{inat_user_login}
PARAMS
stub_request(:get, "#{INAT_OBS_REQUEST_PREFIX}#{params}").
stub_request(:get, "#{API_BASE}/observations#{params}").
with(headers:
{ "Accept" => "application/json",
"Accept-Encoding" => "gzip;q=1.0,deflate;q=0.6,identity;q=0.3",
Expand Down

0 comments on commit 298f94c

Please sign in to comment.