Skip to content

Commit

Permalink
Increase InatController coverage
Browse files Browse the repository at this point in the history
Only 1 line uncovered. I will fix that when I refactor.
  • Loading branch information
JoeCohen committed Aug 17, 2024
1 parent 07d340a commit 874ca65
Showing 1 changed file with 48 additions and 24 deletions.
72 changes: 48 additions & 24 deletions test/controllers/observations/inat_imports_controller_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,54 @@ def test_new_inat_import
"Form needs checkbox requiring consent")
end

def test_create_missing_username
user = users(:rolf)
id = "123"
params = { inat_ids: id }

login(user.login)
post(:create, params: params)

assert_flash_text(:inat_missing_username.l)
assert_form_action(action: :create)
end

def test_create_no_observations_designated
params = { inat_username: "anything", inat_ids: "",
consent: 1 }
login
assert_no_difference("Observation.count",
"Imported observation(s) though none designated") do
post(:create, params: params)
end

assert_flash_text(:inat_no_imports_designated.l)
end

def test_create_illega_observation_id
params = { inat_username: "anything", inat_ids: "123*",
consent: 1 }
login
assert_no_difference("Observation.count",
"Imported observation(s) though none designated") do
post(:create, params: params)
end

assert_flash_text(:runtime_illegal_inat_id.l)
end

def test_create_no_consent
params = { inat_username: "anything", inat_ids: 123,
consent: 0 }
login
assert_no_difference("Observation.count",
"iNat obss imported without consent") do
post(:create, params: params)
end

assert_flash_text(:inat_consent_required.l)
end

def test_create_authorization_request
user = users(:rolf)
inat_username = "rolf"
Expand All @@ -64,30 +112,6 @@ def test_create_authorization_request
"Failed to save InatImport.inat_username")
end

def test_create_missing_username
user = users(:rolf)
id = "123"
params = { inat_ids: id }

login(user.login)
post(:create, params: params)

assert_flash_text(:inat_missing_username.l)
assert_form_action(action: :create)
end

def test_create_no_consent
params = { inat_username: "anything", inat_ids: 123,
consent: 0 }
login
assert_no_difference("Observation.count",
"iNat obss imported without consent") do
post(:create, params: params)
end

assert_flash_text(:inat_consent_required.l)
end

def test_import_authorization_denied
inat_authorization_callback_params =
{ error: "access_denied",
Expand Down

0 comments on commit 874ca65

Please sign in to comment.