diff --git a/app/services/state_file/ty23_archiver_service.rb b/app/services/state_file/ty23_archiver_service.rb index fec3fcc7418..bc467d0b551 100644 --- a/app/services/state_file/ty23_archiver_service.rb +++ b/app/services/state_file/ty23_archiver_service.rb @@ -30,14 +30,17 @@ def archive_batch archived_intake = StateFileArchivedIntake.new(intake.attributes.slice(*archive_attributes)) # TODO: pull mailing address details off the intake; populate relevant fields on the archived intake record if intake.submission_pdf.attached? + pdf = intake.submission_pdf archived_intake.submission_pdf.attach( - io: StringIO.new(intake.submission_pdf.download), - filename: intake.submission_pdf.filename.to_s, - content_type: intake.submission_pdf.content_type, + io: StringIO.new(pdf.download), + filename: pdf.filename.to_s, + content_type: pdf.content_type, ) else Rails.logger.error("No submission pdf attached for record #{record}. Continuing with batch.") end + archived_intake.state_code = @state_code + archived_intake.tax_year = @tax_year archived_intake.save! archived_ids << intake.id rescue StandardError => e diff --git a/spec/services/state_file/ty23_archiver_service_spec.rb b/spec/services/state_file/ty23_archiver_service_spec.rb index d73b085195e..c23edb6f7c8 100644 --- a/spec/services/state_file/ty23_archiver_service_spec.rb +++ b/spec/services/state_file/ty23_archiver_service_spec.rb @@ -50,7 +50,15 @@ %w[az ny].each do |state_code| context 'when there is a current batch to archive' do let(:archiver) { described_class.new(state_code: state_code) } - let!(:intake) { create("state_file_#{state_code}_intake".to_sym, created_at: Date.parse("1/5/23"), hashed_ssn: "fake hashed ssn") } + let(:email_address) { "fake@email.com"} + let!(:intake) { + create( + "state_file_#{state_code}_intake".to_sym, + created_at: Date.parse("1/5/23"), + hashed_ssn: "fake hashed ssn", + email_address: email_address, + ) + } let!(:submission) { create(:efile_submission, :for_state, :accepted, data_source: intake, created_at: Date.parse("1/5/23")) } let!(:mock_batch) { [submission] } let(:test_pdf) { Rails.root.join("spec", "fixtures", "files", "document_bundle.pdf") } @@ -68,7 +76,12 @@ archived_ids = archiver.archive_batch expect(archived_ids.count).to eq 1 archived_ids.each do |id| - expect(StateFileArchivedIntake.find(id).submission_pdf.attached?).to be true + archived_intake = StateFileArchivedIntake.find(id) + expect(archived_intake.hashed_ssn).to eq(intake.hashed_ssn) + expect(archived_intake.email_address).to eq(intake.email_address) + expect(archived_intake.tax_year).to eq(2023) + expect(archived_intake.state_code).to eq(state_code) + expect(archived_intake.submission_pdf.attached?).to be true end end end