Skip to content

Commit

Permalink
[ART] POA request representative refinement
Browse files Browse the repository at this point in the history
  • Loading branch information
nihil2501 committed Dec 23, 2024
1 parent 0af5f56 commit dc24a48
Show file tree
Hide file tree
Showing 10 changed files with 105 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,9 @@
module AccreditedRepresentativePortal
class PowerOfAttorneyForm < ApplicationRecord
belongs_to :power_of_attorney_request,
class_name: 'AccreditedRepresentativePortal::PowerOfAttorneyRequest',
class_name: 'PowerOfAttorneyRequest',
inverse_of: :power_of_attorney_form


has_kms_key

has_encrypted(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,21 @@
module AccreditedRepresentativePortal
class PowerOfAttorneyRequest < ApplicationRecord
module ClaimantTypes
DEPENDENT = 'dependent'
VETERAN = 'veteran'
ALL = [
DEPENDENT = 'dependent',
VETERAN = 'veteran'
].freeze
end

belongs_to :claimant, class_name: 'UserAccount'

has_one :power_of_attorney_form,
inverse_of: :power_of_attorney_request,
validate: true,
required: true

has_one :resolution,
class_name: 'AccreditedRepresentativePortal::PowerOfAttorneyRequestResolution',
class_name: 'PowerOfAttorneyRequestResolution',
inverse_of: :power_of_attorney_request

belongs_to :power_of_attorney_holder,
Expand All @@ -25,6 +28,8 @@ module ClaimantTypes

before_validation :set_claimant_type

validates :claimant_type, inclusion: { in: ClaimantTypes::ALL }

private

def set_claimant_type
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,19 @@

module AccreditedRepresentativePortal
class PowerOfAttorneyRequestDecision < ApplicationRecord
include PowerOfAttorneyRequestResolution::Resolving

self.inheritance_column = nil

module Types
ACCEPTANCE = 'AccreditedRepresentativePortal::PowerOfAttorneyRequestAcceptance'
DECLINATION = 'AccreditedRepresentativePortal::PowerOfAttorneyRequestDeclination'
ALL = [
ACCEPTANCE = 'PowerOfAttorneyRequestAcceptance',
DECLINATION = 'PowerOfAttorneyRequestDeclination'
].freeze
end

belongs_to :creator,
class_name: 'UserAccount'
belongs_to :creator, class_name: 'UserAccount'

validates :type, inclusion: { in: Types::ALL }
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,6 @@

module AccreditedRepresentativePortal
class PowerOfAttorneyRequestExpiration < ApplicationRecord
include PowerOfAttorneyRequestResolution::Resolving
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,31 @@
module AccreditedRepresentativePortal
class PowerOfAttorneyRequestResolution < ApplicationRecord
belongs_to :power_of_attorney_request,
class_name: 'AccreditedRepresentativePortal::PowerOfAttorneyRequest',
class_name: 'PowerOfAttorneyRequest',
inverse_of: :resolution

RESOLVING_TYPES = [

Check failure on line 9 in modules/accredited_representative_portal/app/models/accredited_representative_portal/power_of_attorney_request_resolution.rb

View workflow job for this annotation

GitHub Actions / Linting and Security

Style/WordArray: Use `%w` or `%W` for an array of words.
'AccreditedRepresentativePortal::PowerOfAttorneyRequestExpiration',
'AccreditedRepresentativePortal::PowerOfAttorneyRequestDecision'
'PowerOfAttorneyRequestExpiration',
'PowerOfAttorneyRequestDecision'
].freeze

delegated_type :resolving, types: RESOLVING_TYPES
delegated_type :resolving,
types: RESOLVING_TYPES,

Check failure on line 15 in modules/accredited_representative_portal/app/models/accredited_representative_portal/power_of_attorney_request_resolution.rb

View workflow job for this annotation

GitHub Actions / Linting and Security

Layout/ArgumentAlignment: Align the arguments of a method call if they span more than one line.
inverse_of: :resolution,
validate: true

module Resolving
extend ActiveSupport::Concern

included do
has_one :resolution,
as: :resolving,

Check failure on line 24 in modules/accredited_representative_portal/app/models/accredited_representative_portal/power_of_attorney_request_resolution.rb

View workflow job for this annotation

GitHub Actions / Linting and Security

Layout/ArgumentAlignment: Align the arguments of a method call if they span more than one line.
inverse_of: :resolving,
class_name: 'PowerOfAttorneyRequestResolution',
validate: true,
required: true
end
end

has_kms_key

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
association :claimant, factory: :user_account
association :power_of_attorney_form, strategy: :build

association :power_of_attorney_holder, factory: [:accredited_organization, :with_representatives]
association :power_of_attorney_holder, factory: [:accredited_organization, :with_representatives], strategy: :create

Check failure on line 8 in modules/accredited_representative_portal/spec/factories/power_of_attorney_request.rb

View workflow job for this annotation

GitHub Actions / Linting and Security

Style/SymbolArray: Use `%i` or `%I` for an array of symbols.
accredited_individual { power_of_attorney_holder.accredited_individuals.first }

trait :with_acceptance do
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
factory :power_of_attorney_request_decision,
class: 'AccreditedRepresentativePortal::PowerOfAttorneyRequestDecision' do
association :creator, factory: :user_account
association :resolution, factory: :power_of_attorney_request_resolution

trait :acceptance do
type { AccreditedRepresentativePortal::PowerOfAttorneyRequestDecision::Types::ACCEPTANCE }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,35 @@
power_of_attorney_request

trait :acceptance do
resolving { create(:power_of_attorney_request_decision, :acceptance) }
after(:build) do |resolution|
resolution.resolving =
build(
:power_of_attorney_request_decision, :acceptance,
resolution:
)
end
end

trait :declination do
resolving { create(:power_of_attorney_request_decision, :declination) }
after(:build) do |resolution|
resolution.resolving =
build(
:power_of_attorney_request_decision, :declination,
resolution:
)
end

reason { "Didn't authorize treatment record disclosure" }
end

trait :expiration do
resolving { create(:power_of_attorney_request_expiration) }
after(:build) do |resolution|
resolution.resolving =
build(
:power_of_attorney_request_expiration,
resolution:
)
end
end
end
end
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# frozen_string_literal: true

require 'rails_helper'

RSpec.describe AccreditedRepresentativePortal::PowerOfAttorneyRequestDecision, type: :model do
it 'validates inclusion of type in (acceptance, declination)' do
decision = build(:power_of_attorney_request_decision, type: 'invalid')
decision.valid?

expect(decision).not_to be_valid
expect(decision.errors.full_messages).to eq(
[
'Type is not included in the list',
'Resolution is invalid'
]
)
end
end
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# frozen_string_literal: true

require 'rails_helper'

RSpec.describe AccreditedRepresentativePortal::PowerOfAttorneyRequest, type: :model do
it 'validates its form and claimant type' do
poa_request =
build(
:power_of_attorney_request,
power_of_attorney_form: build(
:power_of_attorney_form,
data: {}.to_json
)
)

expect(poa_request).not_to be_valid
expect(poa_request.errors.full_messages).to eq(
[
'Power of attorney form is invalid',
'Claimant type is not included in the list'
]
)
end
end

0 comments on commit dc24a48

Please sign in to comment.