This repository is currently being migrated. It's locked while the migration is in progress.
-
Notifications
You must be signed in to change notification settings - Fork 94
Expand file tree
/
Copy pathsubmission_statuses_controller_spec.rb
More file actions
264 lines (214 loc) · 9.98 KB
/
submission_statuses_controller_spec.rb
File metadata and controls
264 lines (214 loc) · 9.98 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
# frozen_string_literal: true
require 'rails_helper'
RSpec.describe V0::MyVA::SubmissionStatusesController, type: :controller do
let(:user) { build(:user, :loa3) }
let(:user_account) { user.user_account }
before do
sign_in_as(user)
allow(Flipper).to receive(:enabled?)
.with(:benefits_claims_ivc_champva_provider, user).and_return(false)
end
describe 'GET #show' do
context 'when both feature flags are disabled' do
let(:empty_report) do
double('Report', submission_statuses: [], errors: [])
end
before do
allow(Flipper).to receive(:enabled?)
.with(:my_va_display_all_lighthouse_benefits_intake_forms, user).and_return(false)
allow(Flipper).to receive(:enabled?)
.with(:my_va_display_decision_reviews_forms, user).and_return(false)
allow(Forms::SubmissionStatuses::Report).to receive(:new).and_return(empty_report)
allow(empty_report).to receive(:run).and_return(empty_report)
end
it 'returns empty array when no forms are allowed' do
get :show
expect(response).to have_http_status(:ok)
json_response = JSON.parse(response.body)
expect(json_response['data']).to eq([])
end
end
context 'when benefits intake flag is enabled but decision reviews is disabled' do
let(:benefits_report) do
double('Report', submission_statuses: [], errors: [])
end
before do
allow(Flipper).to receive(:enabled?).with(:my_va_display_all_lighthouse_benefits_intake_forms,
user).and_return(true)
allow(Flipper).to receive(:enabled?).with(:my_va_display_decision_reviews_forms, user).and_return(false)
end
it 'creates report with only benefits intake enabled' do
allow(Forms::SubmissionStatuses::Report).to receive(:new).and_return(benefits_report)
allow(benefits_report).to receive(:run).and_return(benefits_report)
get :show
expect(response).to have_http_status(:ok)
# Verify the report was created and run
expect(Forms::SubmissionStatuses::Report).to have_received(:new)
expect(benefits_report).to have_received(:run)
end
end
context 'when decision reviews flag is enabled but benefits intake is disabled' do
let(:decision_reviews_report) do
double('Report', submission_statuses: [], errors: [])
end
before do
allow(Flipper).to receive(:enabled?).with(:my_va_display_all_lighthouse_benefits_intake_forms,
user).and_return(false)
allow(Flipper).to receive(:enabled?).with(:my_va_display_decision_reviews_forms, user).and_return(true)
end
it 'creates report with only decision reviews enabled' do
allow(Forms::SubmissionStatuses::Report).to receive(:new).and_return(decision_reviews_report)
allow(decision_reviews_report).to receive(:run).and_return(decision_reviews_report)
get :show
expect(response).to have_http_status(:ok)
# Verify the report was created and run
expect(Forms::SubmissionStatuses::Report).to have_received(:new)
expect(decision_reviews_report).to have_received(:run)
end
end
context 'when both feature flags are enabled' do
let(:combined_report) do
double(
'Report',
submission_statuses: [
OpenStruct.new(
id: '123',
form_type: '21-4142',
status: 'received',
message: 'Form received',
detail: 'Processing started',
updated_at: 1.day.ago,
created_at: 2.days.ago,
pdf_support: true
)
],
errors: []
)
end
before do
allow(Flipper).to receive(:enabled?).with(:my_va_display_all_lighthouse_benefits_intake_forms,
user).and_return(true)
allow(Flipper).to receive(:enabled?).with(:my_va_display_decision_reviews_forms, user).and_return(true)
end
it 'creates report with both gateways enabled and all form types' do
allow(Forms::SubmissionStatuses::Report).to receive(:new).and_return(combined_report)
allow(combined_report).to receive(:run).and_return(combined_report)
get :show
expect(response).to have_http_status(:ok)
json_response = JSON.parse(response.body)
expect(json_response['data']).to be_an(Array)
expect(json_response['data'].length).to eq(1)
form_data = json_response['data'].first
expect(form_data['id']).to eq('123')
expect(form_data['attributes']['form_type']).to eq('21-4142')
expect(form_data['attributes']['status']).to eq('received')
expect(form_data['attributes']['pdf_support']).to be true
# Verify the report was created and run
expect(Forms::SubmissionStatuses::Report).to have_received(:new)
expect(combined_report).to have_received(:run)
end
end
context 'gateway options for CHAMPVA email' do
let(:email_options_report) do
double('Report', submission_statuses: [], errors: [])
end
before do
allow(Flipper).to receive(:enabled?).with(:my_va_display_all_lighthouse_benefits_intake_forms,
user).and_return(true)
allow(Flipper).to receive(:enabled?).with(:my_va_display_decision_reviews_forms, user).and_return(false)
allow(Forms::SubmissionStatuses::Report).to receive(:new).and_return(email_options_report)
allow(email_options_report).to receive(:run).and_return(email_options_report)
end
it 'omits user_email when CHAMPVA flag is disabled' do
allow(Flipper).to receive(:enabled?)
.with(:benefits_claims_ivc_champva_provider, anything).and_return(false)
get :show
expect(Forms::SubmissionStatuses::Report).to have_received(:new) do |args|
gateway_options = args[:gateway_options]
expect(gateway_options[:ivc_champva_enabled]).to be(false)
expect(gateway_options).not_to have_key(:user_email)
end
end
it 'includes user_email when CHAMPVA flag is enabled' do
allow(Flipper).to receive(:enabled?)
.with(:benefits_claims_ivc_champva_provider, anything).and_return(true)
get :show
expect(Forms::SubmissionStatuses::Report).to have_received(:new) do |args|
gateway_options = args[:gateway_options]
expect(gateway_options[:ivc_champva_enabled]).to be(true)
expect(gateway_options[:user_email]).to eq(user.email)
end
end
end
context 'when report execution fails' do
let(:failing_report) do
double('Report')
end
before do
allow(Flipper).to receive(:enabled?).with(:my_va_display_all_lighthouse_benefits_intake_forms,
user).and_return(true)
allow(Flipper).to receive(:enabled?).with(:my_va_display_decision_reviews_forms, user).and_return(false)
allow(Forms::SubmissionStatuses::Report).to receive(:new).and_return(failing_report)
allow(failing_report).to receive(:run).and_raise(StandardError, 'Service unavailable')
end
it 'handles errors gracefully' do
# Check if the controller catches and handles the error
get :show
# If it doesn't raise an error, it should return a 500 status
expect(response).to have_http_status(:internal_server_error)
end
end
context 'when feature flag is disabled (restricted list)' do
it 'includes multi-party form IDs in the restricted benefits intake forms' do
forms = controller.send(:restricted_benefits_intake_forms)
expect(forms).to include('21-2680', '21-0779', '21-4192', '21P-530a', '21-4138')
end
end
context 'serialization' do
let(:mock_submission_status) do
OpenStruct.new(
id: 'test-guid-123',
form_type: '21-4142',
status: 'processing',
message: 'Your form is being processed',
detail: 'Expected completion in 5-7 business days',
updated_at: Time.zone.parse('2024-01-15T10:30:00Z'),
created_at: Time.zone.parse('2024-01-10T09:00:00Z'),
pdf_support: true
)
end
let(:serialization_report) do
double(
'Report',
submission_statuses: [mock_submission_status],
errors: []
)
end
before do
allow(Flipper).to receive(:enabled?).with(:my_va_display_all_lighthouse_benefits_intake_forms,
user).and_return(true)
allow(Flipper).to receive(:enabled?).with(:my_va_display_decision_reviews_forms, user).and_return(false)
allow(Forms::SubmissionStatuses::Report).to receive(:new).and_return(serialization_report)
allow(serialization_report).to receive(:run).and_return(serialization_report)
end
it 'serializes submission status data correctly' do
get :show
expect(response).to have_http_status(:ok)
json_response = JSON.parse(response.body)
expect(json_response['data']).to be_an(Array)
expect(json_response['data'].length).to eq(1)
serialized_status = json_response['data'].first
expect(serialized_status['id']).to eq('test-guid-123')
expect(serialized_status['type']).to eq('submission_status')
attributes = serialized_status['attributes']
expect(attributes['form_type']).to eq('21-4142')
expect(attributes['status']).to eq('processing')
expect(attributes['message']).to eq('Your form is being processed')
expect(attributes['detail']).to eq('Expected completion in 5-7 business days')
expect(attributes['pdf_support']).to be true
expect(attributes['updated_at']).to eq('2024-01-15T10:30:00.000Z')
expect(attributes['created_at']).to eq('2024-01-10T09:00:00.000Z')
end
end
end
end