Skip to content

State level action fixes & improvements#941

Merged
hartsick merged 7 commits into2024-upgrades-mainfrom
stateleg-spec
Apr 23, 2025
Merged

State level action fixes & improvements#941
hartsick merged 7 commits into2024-upgrades-mainfrom
stateleg-spec

Conversation

@esoterik
Copy link
Member

Fixes and refactors state level actions.

Still need to get styles matching other action types + do a clean up review of files (this involved a not insignificant amount of file renames and relocations and I haven't checked to clean up duplicates or anything yet)

# This option may cause significant delays in view rendering with a large
# number of complex assets.
config.assets.debug = false
config.assets.debug = true
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

would like to leave this, got stuck on some JS issues for a while because i expected it to be true, though we don't have to leave it

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm good with leaving it in development! can modify locally if needed

Rails.application.config.google_civic_api_url = "http://civic.example.com"
Rails.application.config.google_civic_api_url = "https://civic.example.com"
Rails.application.secrets.google_civic_api_key = "test-key-for-civic-api"
end
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

might be worth making a support file for stubbing this api

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

would be worth it if it was easier to construct matching params strings, leaving for now

@esoterik esoterik marked this pull request as ready for review April 17, 2025 04:00
@esoterik esoterik changed the title [WIP] State level action fixes & improvements State level action fixes & improvements Apr 17, 2025
@esoterik
Copy link
Member Author

Ready for review! commit 3b05f0f36b3dcb69435d35308fba156bc10bf91a should be removed before merging but will be helpful for review.

Copy link
Member

@hartsick hartsick left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good! I left a few notes including where I made some small changes.

I'd love to talk about how state-level actions work and additional things we should track for future and make sure we have issues for those (expanding to target multiple roles, and handling multiple representative emails stood out to me—maybe there are more?).

before do
Rails.application.config.google_civic_api_url = "http://civic.example.com"
Rails.application.config.google_civic_api_url = "https://civic.example.com"
Rails.application.secrets.google_civic_api_key = "test-key-for-civic-api"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Two notes here:

  • in another PR I'm going to change this so that we stub the test environment rather than setting in test, since I'm not sure this gets reset after each test so we might have pollution. It will look like this: allow(Rails.application.secrets).to receive(:google_civic_api_url) { "https://civic.example.com" }. Though we also have this directly set in the test env for secrets.yml, so can decide if it's necessary (might be for test clarity)
  • I think we want to update Rails.application.config to be Rails.application.secrets


raise ArgumentError, "Invalid role for Civic API #{roles}" unless VALID_ROLES.include?(roles)
unless [address, roles].all?
raise ArgumentError, "required argument is nil "\
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm going to change this to just show what required arguments are nil, since we want to avoid sending the address to Sentry

Also, this line allows roles and address to be empty strings or arrays. I was confused about it before understanding we only allow one role to be selected for now (so it comes in as a nil rather than empty array), so am going to submit a change since I've already written it as part of above.

let!(:headers) { { "CONTENT_TYPE" => "application/javascript" } }

before do
Rails.application.config.google_civic_api_url = "https://civic.example.com"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I went and set these in the test block for secrets.yml and deleted them from here - want to try to avoid potential test pollution by setting them here if we don't unset them.

I noticed config.google_civic_api_url is set from secrets.google_civic_api_url. It makes sense conceptually, but I think adds indirection that can be confusing. Might want to do a find + replace for Rails.application.config.google_civic_api_url and Rails.application.config.congress_forms_url, which is set similarly, to just point them to secrets

end

describe "POST tools/state_reps" do
it "returns json containing rep data for a given address" do
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we have a test that covers CivicApi.state_rep_search at a unit level? If not think it'd be helpful to cover at least the validation behaviors - think the happy path is covered by the system spec below.

@hartsick
Copy link
Member

Merging! Failing test is the flaky one I've been working to fix in a separate branch.

@hartsick hartsick merged commit 555094e into 2024-upgrades-main Apr 23, 2025
1 of 2 checks passed
@hartsick hartsick deleted the stateleg-spec branch April 23, 2025 00:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants