Skip to content
This repository is currently being migrated. It's locked while the migration is in progress.
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,11 @@ def create_poa_request
end

request.save!

pathway = @registration_number.present? ? 'rep-first' : 'org-first'
Copy link

Copilot AI Apr 6, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The pathway metric name uses hyphenated segments (rep-first / org-first). This module’s existing StatsD/Datadog metric names appear to use only dots/underscores (e.g., ar.poa.request.decision.accept, ar.unique_session.count). To avoid introducing an inconsistent naming pattern (and potential metric-name restrictions), consider switching to underscore-separated names or emitting a single ar.poa.request.pathway metric with a pathway:rep_first|org_first tag.

Suggested change
pathway = @registration_number.present? ? 'rep-first' : 'org-first'
pathway = @registration_number.present? ? 'rep_first' : 'org_first'

Copilot uses AI. Check for mistakes.

Monitoring.new.track_count('ar.poa.request.count')
Monitoring.new.track_count("ar.poa.request.pathway.#{pathway}")
end
Copy link

Copilot AI Apr 6, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

track_count is executed inside the DB transaction (after save! but before the transaction commits). If the transaction fails at commit time, these metrics will still be emitted even though the record wasn’t persisted. Consider moving the metric emission outside the ActiveRecord::Base.transaction block (or using an after_commit hook) so counts only reflect committed requests.

Copilot uses AI. Check for mistakes.

request
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,17 @@
let(:poa_code) { organization.poa }
let(:representative) { create(:representative, representative_id: '86753') }
let(:registration_number) { representative.representative_id }
let(:monitoring) do
instance_double(
AccreditedRepresentativePortal::Monitoring,
track_count: true
)
end

before do
allow(monitoring).to receive(:trace).and_yield(nil)
allow(AccreditedRepresentativePortal::Monitoring).to receive(:new).and_return(monitoring)
end

it 'creates a new AccreditedRepresentativePortal::PowerOfAttorneyRequest' do
expect { subject.call }.to change(AccreditedRepresentativePortal::PowerOfAttorneyRequest, :count).by(1)
Expand Down Expand Up @@ -98,6 +109,18 @@
expect(result[:request].power_of_attorney_holder_type).to eq('veteran_service_organization')
end

it 'tracks the overall request count' do
subject.call

expect(monitoring).to have_received(:track_count).with('ar.poa.request.count')
end

it 'tracks the rep-first pathway count when registration_number is present' do
subject.call

expect(monitoring).to have_received(:track_count).with('ar.poa.request.pathway.rep-first')
end

context 'unresolved PowerOfAttorneyRequests' do
context 'when there are unresolved requests' do
let!(:poa_request1) { create(:power_of_attorney_request, claimant:) }
Expand Down Expand Up @@ -156,6 +179,12 @@

expect(result[:request].accredited_individual).to be_nil
end

it 'tracks the org-first pathway count' do
subject.call

expect(monitoring).to have_received(:track_count).with('ar.poa.request.pathway.org-first')
end
end

context 'when there are errors' do
Expand Down
Loading