Skip to content

Commit

Permalink
add job_id to family subjects
Browse files Browse the repository at this point in the history
  • Loading branch information
vkghub committed Jul 17, 2024
1 parent ca638de commit 4a4c282
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@ class Subject

field :encrypted_ssn, type: String

# @!attribute [rw] job_id
# @return [String] the job id
field :job_id, type: String

# indexes
index({ person_hbx_id: 1 })

Expand Down
3 changes: 2 additions & 1 deletion app/operations/fdsh/pvc/dmf/request/store_request.rb
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,8 @@ def create_eligible_members(family)
next unless member_eligible?(family_member)
next unless valid_ssn?(family_member)
family.eligibility_determination_subjects.new(person_hbx_id: family_member.hbx_id,
encrypted_ssn: family_member&.person&.person_demographics&.encrypted_ssn)
encrypted_ssn: family_member&.person&.person_demographics&.encrypted_ssn,
job_id: @job.job_id)
end

result = unless family.eligibility_determination_subjects.empty?
Expand Down
2 changes: 1 addition & 1 deletion app/operations/fdsh/pvc/dmf/response/store_response.rb
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ def domain_to_mapper(sanitize_xml_string)
def find_subject(nokogiri_document)
ssn_identification = nokogiri_document.person.person_ssn_identification.ssn_identification
encrypted_ssn = AcaEntities::Operations::Encryption::Encrypt.new.call(value: ssn_identification).value!
subject = Family::EligibilityDetermination::AliveStatus::Subject.where(encrypted_ssn: encrypted_ssn).first
subject = Family::EligibilityDetermination::AliveStatus::Subject.where(encrypted_ssn: encrypted_ssn, job_id: @job.job_id).first

return Failure("Subject not found") unless subject.present?

Expand Down
1 change: 1 addition & 0 deletions spec/operations/fdsh/pvc/dmf/request/store_request_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@
families = AliveStatus::Family.all
expect(families.count).to eq 1
expect(families.first.job_id).to eq @job.job_id
expect(families.first.eligibility_determination_subjects.first.job_id).to eq @job.job_id
end

it 'should have individual xml_payload attributes' do
Expand Down
49 changes: 41 additions & 8 deletions spec/operations/fdsh/pvc/dmf/response/store_response_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -35,34 +35,67 @@

let(:encrypted_xml_string) { AcaEntities::Operations::Encryption::Encrypt.new.call(value: xml_string).value!}
let(:job) { FactoryBot.create(:transmittable_job, key: :dmf_request, job_id: '123456') }
let(:job2) { FactoryBot.create(:transmittable_job, key: :dmf_request, job_id: '223456') }
let(:family_json_hash) { family_hash.to_json }
let(:request_family_hash) { family_json_hash }

let!(:family) do
FactoryBot.create(
:alive_status_family,
:with_eligibility_determination_subject,
family_hbx_id: '100101000',
job_id: job.job_id,
request_family_cv: request_family_hash
)
end

let!(:family2) do
FactoryBot.create(
:alive_status_family,
:with_eligibility_determination_subject,
family_hbx_id: '100101000',
job_id: job2.job_id,
request_family_cv: request_family_hash
)
end

let!(:subject) do
s = family.eligibility_determination_subjects.first
s.job_id = job.job_id
s.encrypted_ssn = AcaEntities::Operations::Encryption::Encrypt.new.call(value: '100101000').value!
s.save!
s
end

let!(:subject2) do
s = family2.eligibility_determination_subjects.first
s.job_id = job2.job_id
s.encrypted_ssn = AcaEntities::Operations::Encryption::Encrypt.new.call(value: '100101000').value!
s.save!
s
end

context 'with valid parameters' do
let(:valid_params) { { "encrypted_xml_string" => encrypted_xml_string, "job_id" => job.job_id } }
let(:valid_params) { { "encrypted_xml_string" => encrypted_xml_string, "job_id" => job2.job_id } }

it 'decrypts the payload, parses the XML, and stores the response successfully' do
transaction = described_class.new.call(JSON.parse(valid_params.to_json, :symbolize_names => true)).success
before do
@transaction = described_class.new.call(JSON.parse(valid_params.to_json, :symbolize_names => true)).success
end

expect(transaction.process_status.latest_state).to eq :received
expect(transaction.transmission.present?).to be_truthy
expect(transaction.transmission.process_status.latest_state).to eq :received
expect(transaction.transmission.job.present?).to be_truthy
expect(transaction.xml_payload.present?).to be_truthy
it 'should store response to correct subject' do
expect(subject2.transactions.where(key: :dmf_response).first.id.to_s).to eq @transaction.id.to_s
end

it 'should not store response to incorrect subject' do
expect(subject.transactions.where(key: :dmf_response).first).to be_nil
end

it 'decrypts the payload, parses the XML, and stores the response successfully' do
expect(@transaction.process_status.latest_state).to eq :received
expect(@transaction.transmission.present?).to be_truthy
expect(@transaction.transmission.process_status.latest_state).to eq :received
expect(@transaction.transmission.job.present?).to be_truthy
expect(@transaction.xml_payload.present?).to be_truthy
end
end

Expand Down

0 comments on commit 4a4c282

Please sign in to comment.