Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

vi-1055 Create UserActionEventsController and query route #20690

Open
wants to merge 28 commits into
base: master
Choose a base branch
from

Conversation

emilykim13
Copy link
Contributor

@emilykim13 emilykim13 commented Feb 7, 2025

Note: Delete the description statements, complete each step. None are optional, but can be justified as to why they cannot be completed as written. Provide known gaps to testing that may raise the risk of merging to production.

Summary

  • No feature toggle
  • This adds 2 new files, UserActionEventsController.rb and it's respective spec file. Changes include a new route to the #index action in this controller.
  • Identity Platform Team

Related issue(s)

Testing done

  • New code is covered by unit tests
  • Confirmed routes have been created
bin/rails routes | grep user_action_events
                               v0_user_action_events GET                       /v0/user_action_events(.:format)                                                                  v0/user_action_events#index {:format=>"json"}
                  v0_user_action_events GET    /v0/user_action_events(.:format)                                             mobile/v0/user_action_events#index
  • Test #index action
user_verification = UserVerification.find_by(idme_uuid:<idme_uuid>)
UserActionEvent.new(details: 'test user action event').save!
user_action_event = UserActionEvent.last
user_action_one = UserAction.new(user_action_event_id: user_action_event.id, status: 'success', subject_user_verification_id: user_verification.id, acting_user_verification_id: user_verification.id, acting_ip_address: '::1', acting_user_agent: 'test')
user_action_two = UserAction.new(user_action_event_id: user_action_event.id, status: 'success', subject_user_verification_id: user_verification.id, acting_user_verification_id: user_verification.id, acting_ip_address: '::1', acting_user_agent: 'test', created_at: 2.years.ago)
user_action_three = UserAction.new(user_action_event_id: user_action_event.id, status: 'success', subject_user_verification_id: user_verification.id, acting_user_verification_id: user_verification.id, acting_ip_address: '::1', acting_user_agent: 'test', created_at: 3.years.ago)
user_action_one.save!
user_action_two.save!
user_action_three.save!
controller = V0::UserActionEventsController.new
params = { start_date: nil, end_date: nil, page: nil, per_page: nil }
controller.params = params

Go to http://localhost:3000/v0/user_action_events and we should see something like this as a result of default params when params are not provided:

{"data":{"data":[],"included":[]},"meta":{"current_page":1,"total_pages":1,"per_page":10,"total_count":0}}

And then we can change the start_date, end_date, page, per_page param in our params object to test the responses for different params

What areas of the site does it impact?

  • This a part of the Audit DB project

Acceptance criteria

  • I fixed|updated|added unit tests and integration tests for each feature (if applicable).
  • No error nor warning in the console.
  • Events are being sent to the appropriate logging solution
  • Documentation has been updated (link to documentation)
  • No sensitive information (i.e. PII/credentials/internal URLs/etc.) is captured in logging, hardcoded, or specs
  • Feature/bug has a monitor built into Datadog (if applicable)
  • If app impacted requires authentication, did you login to a local build and verify all authenticated routes work as expected
  • I added a screenshot of the developed feature

@emilykim13 emilykim13 requested a review from a team February 7, 2025 20:59
@emilykim13 emilykim13 self-assigned this Feb 7, 2025
Copy link

github-actions bot commented Feb 7, 2025

Error: A file (or its parent directories) does not have a CODEOWNERS entry. Please update the .github/CODEOWNERS file and add the entry for the Offending file: app/controllers/v0/user_action_events_controller.rb

Copy link

github-actions bot commented Feb 7, 2025

Error: A file (or its parent directories) does not have a CODEOWNERS entry. Please update the .github/CODEOWNERS file and add the entry for the Offending file: app/controllers/v0/user_action_events_controller.rb

Copy link

Error: A file (or its parent directories) does not have a CODEOWNERS entry. Please update the .github/CODEOWNERS file and add the entry for the Offending file: app/controllers/v0/user_action_events_controller.rb

Copy link

Error: A file (or its parent directories) does not have a CODEOWNERS entry. Please update the .github/CODEOWNERS file and add the entry for the Offending file: app/controllers/v0/user_action_events_controller.rb

Copy link

Error: A file (or its parent directories) does not have a CODEOWNERS entry. Please update the .github/CODEOWNERS file and add the entry for the Offending file: app/controllers/v0/user_action_events_controller.rb

Copy link

Error: A file (or its parent directories) does not have a CODEOWNERS entry. Please update the .github/CODEOWNERS file and add the entry for the Offending file: app/controllers/v0/user_action_events_controller.rb

Copy link

Error: A file (or its parent directories) does not have a CODEOWNERS entry. Please update the .github/CODEOWNERS file and add the entry for the Offending file: app/controllers/v0/user_action_events_controller.rb

@emilykim13 emilykim13 requested review from bosawt and bramleyjl March 4, 2025 20:54
@va-vfs-bot va-vfs-bot temporarily deployed to vi-1055/main/main March 5, 2025 01:05 Inactive
Copy link
Contributor

@bramleyjl bramleyjl left a comment

Choose a reason for hiding this comment

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

When you declare subject { get(:index, params: index_params) } at the top of the #index method test that subject invocation of the method is available in all of your nested contexts.

So everywhere that you're explicitly calling get :index, params: ... you should be able to remove that and instead set the params ahead of time (since they'll show up in the index_params arguments object) & then call the subject to make the call happen. You'll only need to call it once per it block so you should set it to a variable (like response = subject) if you're planning on running lots of tests in an example.

# original way
context 'with some context' do
  let(:start_date) { 3.months.ago.to_date }
  let(:end_date) { 2.weeks.ago.to_date }
   it 'does something' do
     get :index, params: { start_date:, end_date: }

    json_response = JSON.parse(response.body)['data']['data']

# with subject
context 'with some context' do
  let(:start_date) { 3.months.ago.to_date }
  let(:end_date) { 2.weeks.ago.to_date }
   it 'does something' do

    json_response = JSON.parse(subject.body)['data']['data']

@emilykim13 emilykim13 requested a review from bramleyjl March 5, 2025 20:05
let(:end_date) { 2.weeks.ago.to_date }

it 'returns the results in descending order by created_at' do
subject
Copy link
Contributor

Choose a reason for hiding this comment

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

You only need to call subject once, so this test (and all of the other ones that have a line like this) can just begin with json_response = JSON.parse(subject.body) and then you can set your expectations against that json_response variable.

If you call the subject like that and set it to a variable then you won't need subject or get :index declared at the top of any of your tests.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants