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

Create model definitions and user associations for #20426

Merged
Merged
Show file tree
Hide file tree
Changes from 32 commits
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
7b12db4
Removes Sidekiq Enterprise and Pro dependencies
anjolovic Jan 21, 2025
0aaffe6
Adds user action tracking models and specs
anjolovic Jan 23, 2025
b393e7a
Restore original Gemfile.lock
anjolovic Jan 23, 2025
94d9f03
Update CODEOWNERS: Add user_action.rb and remove Gemfile.lock
anjolovic Jan 23, 2025
552b0bc
Update CODEOWNERS: Add user_action files with octo-identity ownership
anjolovic Jan 23, 2025
cd6726d
Fix CODEOWNERS: Add user_action entries in correct alphabetical order
anjolovic Jan 23, 2025
e58d829
Fix CODEOWNERS: Update user_action entries to only use octo-identity …
anjolovic Jan 23, 2025
730a5f3
Update CODEOWNERS: Add spec files and ensure alphabetical order
anjolovic Jan 23, 2025
5e2fe0c
Removes trailing whitespace from model and spec files
anjolovic Jan 23, 2025
cbb595a
Update CODEOWNERS: Add factory files
anjolovic Jan 23, 2025
983d55e
Fix CODEOWNERS: Move factory entries to correct alphabetical order
anjolovic Jan 23, 2025
f808fd9
Fix CODEOWNERS: Add parent directory entries and maintain alphabetica…
anjolovic Jan 23, 2025
253c49a
Fix CODEOWNERS: Move user_action entries to correct alphabetical order
anjolovic Jan 24, 2025
a61d5b7
Refactor UserAction and UserActionEvent specs
anjolovic Jan 24, 2025
c14762b
Remove presence validations for IP and User Agent
anjolovic Jan 24, 2025
ae87744
Use Faker gem in factories
anjolovic Jan 24, 2025
67b1152
Update UserAction model to match new schema
anjolovic Jan 24, 2025
4c07eca
Add system_initiated trait for UserAction
anjolovic Jan 24, 2025
bf0d1cd
Remove system_initiated trait and its tests as requested
anjolovic Jan 27, 2025
5bad0b4
Refactor UserAction specs to use let statements and contexts
anjolovic Jan 27, 2025
4018b79
Removes trailing whitespace from spec files
anjolovic Jan 27, 2025
e5a1c81
Refactor UserAction specs to use let statements and contexts
anjolovic Jan 27, 2025
84966c5
Removes trailing whitespace in user action spec
anjolovic Jan 27, 2025
18d9edd
Update CODEOWNERS: Add user_action entries in alphabetical order
anjolovic Jan 27, 2025
4079baa
Adds code owners for user action files
anjolovic Jan 28, 2025
b52b1fa
Adds CODEOWNERS for UserActionEvent files
anjolovic Jan 28, 2025
a77928a
Updates CODEOWNERS for user action files
anjolovic Jan 28, 2025
735815c
Assigns OCTO Identity team ownership for user actions
anjolovic Jan 28, 2025
4132401
Removes duplicate CODEOWNERS entries for user specs
anjolovic Jan 28, 2025
5c2ea8b
Simplifies enum status validation in UserAction
anjolovic Jan 28, 2025
ae72e4e
Adds newline at end of files
anjolovic Jan 28, 2025
8b16433
Cleans up CODEOWNERS file redundancy and naming
anjolovic Jan 28, 2025
a5a3649
Simplifies user action specs with focused test cases
anjolovic Jan 28, 2025
d2a83ab
Renames spec factory files to match plural convention:
anjolovic Jan 28, 2025
4467434
Simplifies user action model specs
anjolovic Jan 28, 2025
1422228
Fix linting
anjolovic Jan 28, 2025
4bfa55f
Merge branch 'master' into VI-863-create-model-definitions-and-user-a…
anjolovic Jan 29, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .github/CODEOWNERS
Original file line number Diff line number Diff line change
Expand Up @@ -330,6 +330,8 @@ app/models/triage_team.rb @department-of-veterans-affairs/vfs-mhv-secure-messagi
app/models/all_triage_teams.rb @department-of-veterans-affairs/vfs-mhv-secure-messaging @department-of-veterans-affairs/va-api-engineers @department-of-veterans-affairs/backend-review-group
app/models/user_acceptable_verified_credential.rb @department-of-veterans-affairs/octo-identity
app/models/user_account.rb @department-of-veterans-affairs/octo-identity
app/models/user_action_event.rb @department-of-veterans-affairs/octo-identity
app/models/user_action.rb @department-of-veterans-affairs/octo-identity
anjolovic marked this conversation as resolved.
Show resolved Hide resolved
app/models/user_credential_email.rb @department-of-veterans-affairs/octo-identity
app/models/user_identity.rb @department-of-veterans-affairs/octo-identity
app/models/user_profile_attributes.rb @department-of-veterans-affairs/vfs-authenticated-experience-backend @department-of-veterans-affairs/va-api-engineers @department-of-veterans-affairs/backend-review-group @department-of-veterans-affairs/octo-identity
Expand Down Expand Up @@ -1268,6 +1270,8 @@ spec/factories/supporting_evidence_attachment.rb @department-of-veterans-affairs
spec/factories/triage_teams.rb @department-of-veterans-affairs/vfs-mhv-secure-messaging @department-of-veterans-affairs/va-api-engineers @department-of-veterans-affairs/backend-review-group
spec/factories/user_acceptable_verified_credentials.rb @department-of-veterans-affairs/octo-identity
spec/factories/user_accounts.rb @department-of-veterans-affairs/octo-identity
spec/factories/user_action_event.rb @department-of-veterans-affairs/octo-identity
Copy link
Contributor

Choose a reason for hiding this comment

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

pluralize these:

  • user_action_events.rb
  • user_actions.rb

spec/factories/user_action.rb @department-of-veterans-affairs/octo-identity
spec/factories/user_credential_emails.rb @department-of-veterans-affairs/octo-identity
spec/factories/user_identities.rb @department-of-veterans-affairs/octo-identity
spec/factories/user_identity_attributes.rb @department-of-veterans-affairs/octo-identity
Expand Down Expand Up @@ -1664,6 +1668,8 @@ spec/models/terms_of_use_agreement_spec.rb @department-of-veterans-affairs/octo-
spec/models/triage_team_spec.rb @department-of-veterans-affairs/vfs-mhv-secure-messaging @department-of-veterans-affairs/va-api-engineers @department-of-veterans-affairs/backend-review-group
spec/models/user_acceptable_verified_credential_spec.rb @department-of-veterans-affairs/octo-identity
spec/models/user_account_spec.rb @department-of-veterans-affairs/octo-identity
spec/models/user_action_event_spec.rb @department-of-veterans-affairs/octo-identity
spec/models/user_action_spec.rb @department-of-veterans-affairs/octo-identity
bosawt marked this conversation as resolved.
Show resolved Hide resolved
spec/models/user_credential_email_spec.rb @department-of-veterans-affairs/octo-identity
spec/models/user_relationship_spec.rb @department-of-veterans-affairs/octo-identity
spec/models/user_session_form_spec.rb @department-of-veterans-affairs/octo-identity
Expand Down
9 changes: 9 additions & 0 deletions app/models/user_action.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# frozen_string_literal: true

class UserAction < ApplicationRecord
belongs_to :acting_user_verification, class_name: 'UserVerification', optional: true
belongs_to :subject_user_verification, class_name: 'UserVerification'
belongs_to :user_action_event

enum :status, { initial: 'initial', success: 'success', error: 'error' }, validate: true
end
7 changes: 7 additions & 0 deletions app/models/user_action_event.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# frozen_string_literal: true

class UserActionEvent < ApplicationRecord
has_many :user_actions, dependent: :restrict_with_exception

validates :details, presence: true
end
7 changes: 7 additions & 0 deletions spec/factories/user_action_events.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# frozen_string_literal: true

FactoryBot.define do
factory :user_action_event do
details { Faker::Lorem.sentence }
end
end
12 changes: 12 additions & 0 deletions spec/factories/user_actions.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# frozen_string_literal: true

FactoryBot.define do
factory :user_action do
association :subject_user_verification, factory: :user_verification
association :user_action_event
status { 'initial' }
acting_ip_address { Faker::Internet.ip_v4_address }
acting_user_agent { Faker::Internet.user_agent }
association :acting_user_verification, factory: :user_verification
end
end
23 changes: 23 additions & 0 deletions spec/models/user_action_event_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# frozen_string_literal: true

require 'rails_helper'

RSpec.describe UserActionEvent, type: :model do
describe 'validations' do
rileyanderson marked this conversation as resolved.
Show resolved Hide resolved
it { is_expected.to validate_presence_of(:details) }
end

describe 'associations' do
rileyanderson marked this conversation as resolved.
Show resolved Hide resolved
let(:user_action_event) { create(:user_action_event) }

it { is_expected.to have_many(:user_actions).dependent(:restrict_with_exception) }

context 'when user actions exist' do
let!(:user_action) { create(:user_action, user_action_event: user_action_event) }

it 'restricts destruction when user actions exist' do
expect { user_action_event.destroy }.to raise_error(ActiveRecord::DeleteRestrictionError)
end
end
end
end
81 changes: 81 additions & 0 deletions spec/models/user_action_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
# frozen_string_literal: true

require 'rails_helper'

RSpec.describe UserAction, type: :model do
describe 'validations' do
let(:acting_ip_address) { Faker::Internet.ip_v4_address }
let(:acting_user_agent) { Faker::Internet.user_agent }
let(:acting_user_verification) { build(:user_verification) }
let(:user_action) do
build(:user_action,
acting_ip_address:,
acting_user_agent:,
acting_user_verification:)
end

context 'when attributes are valid' do
it 'is valid' do
expect(user_action).to be_valid
end
end

context 'when acting_ip_address is nil' do
let(:acting_ip_address) { nil }

it 'is valid' do
expect(user_action).to be_valid
end
end

context 'when acting_user_agent is nil' do
let(:acting_user_agent) { nil }

it 'is valid' do
expect(user_action).to be_valid
end
end

context 'when acting_user_verification is nil' do
let(:acting_user_verification) { nil }

it 'is valid' do
expect(user_action).to be_valid
end
end
Copy link
Contributor

@rileyanderson rileyanderson Jan 28, 2025

Choose a reason for hiding this comment

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

I don’t think it’s necessary to test attribute validations unless they are explicitly defined in the model. These will be valid regardless of whether they are nil or not.

end

describe 'associations' do
it { is_expected.to belong_to(:acting_user_verification).class_name('UserVerification').optional }
it { is_expected.to belong_to(:subject_user_verification).class_name('UserVerification') }
it { is_expected.to belong_to(:user_action_event) }
end

describe 'enum status' do
let(:user_action) { create(:user_action) }

it 'defines status predicates' do
expect(user_action).to respond_to(:initial?)
expect(user_action).to respond_to(:success?)
expect(user_action).to respond_to(:error?)
end

it 'defines the expected status values' do
expect(described_class.statuses).to eq(
'initial' => 'initial',
'success' => 'success',
'error' => 'error'
)
end

%w[initial success error].each do |valid_status|
context "when status is #{valid_status}" do
let(:user_action) { build(:user_action, status: valid_status) }

it 'is valid' do
expect(user_action).to be_valid
end
end
end
end
end
Loading