diff --git a/modules/va_forms/app/workers/va_forms/form_builder.rb b/modules/va_forms/app/workers/va_forms/form_builder.rb index bac0297f67c..f6b269f87c2 100644 --- a/modules/va_forms/app/workers/va_forms/form_builder.rb +++ b/modules/va_forms/app/workers/va_forms/form_builder.rb @@ -99,7 +99,11 @@ def update_sha256(form) form_data = { form_name: form.form_name, form_url: form.url }.to_s Rails.logger.error("#{message}: #{form_data}", e) - VAForms::Slack::Messenger.new({ class: self.class.name, message:, exception: e, form_data: }).notify! + + # Only alert to slack when a formerly-valid PDF turns false + if form.valid_pdf? + VAForms::Slack::Messenger.new({ class: self.class.name, message:, exception: e, form_data: }).notify! + end form.valid_pdf = false form diff --git a/modules/va_forms/spec/workers/form_builder_spec.rb b/modules/va_forms/spec/workers/form_builder_spec.rb index ac5bd167067..47c404978a3 100644 --- a/modules/va_forms/spec/workers/form_builder_spec.rb +++ b/modules/va_forms/spec/workers/form_builder_spec.rb @@ -36,10 +36,21 @@ it 'fails to update the sha256 when forms are submitted' do VCR.use_cassette('va_forms/fails') do - form = VAForms::Form.new(url: 'http://www.vba.va.gov/pubs/forms/26-85992.pdf') + form = VAForms::Form.new(url: 'http://www.vba.va.gov/pubs/forms/26-85992.pdf', valid_pdf: true) form = form_builder.update_sha256(form) expect(form.valid_pdf).to eq(false) expect(form.sha256).to eq(nil) + expect(slack_messenger).to have_received(:notify!) + end + end + + it 'only sends slack notification when valid_pdf turns invalid' do + VCR.use_cassette('va_forms/fails') do + form = VAForms::Form.new(url: 'http://www.vba.va.gov/pubs/forms/26-85992.pdf', valid_pdf: false) + form = form_builder.update_sha256(form) + expect(form.valid_pdf).to eq(false) + expect(form.sha256).to eq(nil) + expect(slack_messenger).not_to have_received(:notify!) end end