@@ -16,6 +16,7 @@ def days_since_now(created_at)
16
16
17
17
before do
18
18
allow ( Settings . ivc_forms . sidekiq . missing_form_status_job ) . to receive ( :enabled ) . and_return ( true )
19
+ allow ( Flipper ) . to receive ( :enabled? ) . with ( :champva_vanotify_custom_callback , @current_user ) . and_return ( true )
19
20
allow ( StatsD ) . to receive ( :gauge )
20
21
allow ( StatsD ) . to receive ( :increment )
21
22
@@ -24,12 +25,14 @@ def days_since_now(created_at)
24
25
track_failed_send_zsf_notification_to_pega : nil ) )
25
26
# Save the original form creation times so we can restore them later
26
27
@original_creation_times = forms . map ( &:created_at )
28
+ @original_uuids = forms . map ( &:form_uuid )
27
29
end
28
30
29
31
after do
30
- # Restore original form creation times for time sensitive tests
32
+ # Restore original dummy form created_at/form_uuid props in case we've adjusted them
31
33
forms . each_with_index do |form , index |
32
34
form . update ( created_at : @original_creation_times [ index ] )
35
+ form . update ( form_uuid : @original_uuids [ index ] )
33
36
end
34
37
end
35
38
@@ -105,6 +108,30 @@ def days_since_now(created_at)
105
108
expect ( StatsD ) . to have_received ( :gauge ) . with ( 'ivc_champva.forms_missing_status.count' , forms . count - 1 )
106
109
end
107
110
111
+ it 'processes nil forms in batches that belong to the same submission' do
112
+ # Set shared `form_uuid` so these two now belong to the same batch:
113
+ forms [ 0 ] . update ( form_uuid : '78444a0b-3ac8-454d-a28d-8d63cddd0d3b' )
114
+ forms [ 1 ] . update ( form_uuid : '78444a0b-3ac8-454d-a28d-8d63cddd0d3b' )
115
+
116
+ # Perform the job that checks form statuses
117
+ job . perform
118
+
119
+ # Check that we processed batches rather than individual forms:
120
+ expect ( StatsD ) . to have_received ( :gauge ) . with ( 'ivc_champva.forms_missing_status.count' , forms . count - 1 )
121
+ end
122
+
123
+ it 'groups nil statuses into batches by uuid' do
124
+ # Set shared `form_uuid` so these two now belong to the same batch:
125
+ forms [ 0 ] . update ( form_uuid : '78444a0b-3ac8-454d-a28d-8d63cddd0d3b' )
126
+ forms [ 1 ] . update ( form_uuid : '78444a0b-3ac8-454d-a28d-8d63cddd0d3b' )
127
+
128
+ # Perform the job that checks form statuses
129
+ batches = job . get_nil_batches
130
+
131
+ expect ( batches . count == forms . count - 1 ) . to be true
132
+ expect ( batches [ '78444a0b-3ac8-454d-a28d-8d63cddd0d3b' ] . count == 2 ) . to be true
133
+ end
134
+
108
135
it 'sends the count of forms to DataDog' do
109
136
IvcChampva ::MissingFormStatusJob . new . perform
110
137
0 commit comments