diff --git a/app/models/family/eligibility_determination/alive_status/subject.rb b/app/models/family/eligibility_determination/alive_status/subject.rb index 723e7fa3..e3f7b402 100644 --- a/app/models/family/eligibility_determination/alive_status/subject.rb +++ b/app/models/family/eligibility_determination/alive_status/subject.rb @@ -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 }) diff --git a/app/operations/fdsh/pvc/dmf/request/store_request.rb b/app/operations/fdsh/pvc/dmf/request/store_request.rb index 5d5de318..c82bb3ba 100644 --- a/app/operations/fdsh/pvc/dmf/request/store_request.rb +++ b/app/operations/fdsh/pvc/dmf/request/store_request.rb @@ -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? diff --git a/app/operations/fdsh/pvc/dmf/response/store_response.rb b/app/operations/fdsh/pvc/dmf/response/store_response.rb index 6f56233f..961e593a 100644 --- a/app/operations/fdsh/pvc/dmf/response/store_response.rb +++ b/app/operations/fdsh/pvc/dmf/response/store_response.rb @@ -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? diff --git a/spec/operations/fdsh/pvc/dmf/request/store_request_spec.rb b/spec/operations/fdsh/pvc/dmf/request/store_request_spec.rb index bb56bdcd..af43c533 100644 --- a/spec/operations/fdsh/pvc/dmf/request/store_request_spec.rb +++ b/spec/operations/fdsh/pvc/dmf/request/store_request_spec.rb @@ -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 diff --git a/spec/operations/fdsh/pvc/dmf/response/store_response_spec.rb b/spec/operations/fdsh/pvc/dmf/response/store_response_spec.rb index 890973a9..9f47eab6 100644 --- a/spec/operations/fdsh/pvc/dmf/response/store_response_spec.rb +++ b/spec/operations/fdsh/pvc/dmf/response/store_response_spec.rb @@ -35,6 +35,7 @@ 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 } @@ -42,27 +43,59 @@ 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