Skip to content

Commit ed85be6

Browse files
authored
RST-7753 Updating part_payment banner based on the part_payment outcome (#2311)
1 parent 76c37e9 commit ed85be6

File tree

3 files changed

+108
-1
lines changed

3 files changed

+108
-1
lines changed

app/models/views/application_result.rb

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,22 @@ def result
1212
['granted', 'full', 'part', 'paid', 'none', 'return'].include?(outcome) ? outcome : 'error'
1313
end
1414

15+
def banner_style
16+
if processed_part_payment?
17+
@application.decision
18+
else
19+
result
20+
end
21+
end
22+
23+
def pp_outcome
24+
if part_payment_successful
25+
'paid'
26+
else
27+
@application.part_payment&.outcome
28+
end
29+
end
30+
1531
def amount_to_pay
1632
# Because we are outside the ActiveRecord::Base scope I can't use is_a?
1733
if outcome_from.class.name.to_s == 'PartPayment'
@@ -55,6 +71,11 @@ def amount_to_refund
5571
@application.detail.fee - amount_to_pay_for_part_payment.to_f
5672
end
5773

74+
def processed_part_payment?
75+
return false if @application.part_payment.nil?
76+
@application.processed?
77+
end
78+
5879
delegate :state, to: :@application
5980

6081
def return_type
Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
1-
#result.callout class="callout-#{source.result}"
1+
#result.callout class="callout-#{source.try(:banner_style) || source&.result}"
22
- if source.try(:evidence)
33
h2.govuk-heading-l = t("remissions.#{source.result}_html", amount_to_pay: source.amount_to_pay, return_type: source.return_type)
44
- elsif source.try(:refund) && source.result != 'none'
55
h2.govuk-heading-l =t("remissions.part_refund_html", amount_to_pay: "£#{parse_amount_to_pay(source.amount_to_refund)}")
6+
- elsif source.try(:processed_part_payment?)
7+
h2.govuk-heading-l = t("remissions.#{source.pp_outcome}_html", amount_to_pay: source.amount_to_pay, return_type: source.return_type)
68
- else
79
h2.govuk-heading-l =t("remissions.#{source.result}_html", amount_to_pay: source.amount_to_pay, return_type: source.return_type)

spec/models/views/application_result_spec.rb

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -222,4 +222,88 @@
222222
it { is_expected.to eql('payment') }
223223
end
224224
end
225+
226+
describe '#processed_part_payment?' do
227+
subject { view.processed_part_payment? }
228+
229+
context 'when the application has a part payment and is processed' do
230+
let(:part_payment) { build_stubbed(:part_payment) }
231+
let(:application) { build_stubbed(:application, part_payment: part_payment, state: 3) }
232+
233+
it { is_expected.to be true }
234+
end
235+
236+
context 'when the application has no part payment' do
237+
let(:application) { build_stubbed(:application, part_payment: nil, state: 3) }
238+
239+
it { is_expected.to be false }
240+
end
241+
242+
context 'when the application is not processed' do
243+
let(:part_payment) { build_stubbed(:part_payment) }
244+
let(:application) { build_stubbed(:application, part_payment: part_payment, state: 2) }
245+
246+
it { is_expected.to be false }
247+
end
248+
end
249+
250+
describe '#banner_style' do
251+
subject { view.banner_style }
252+
253+
context 'when the application has a processed part payment' do
254+
let(:part_payment) { build_stubbed(:part_payment) }
255+
let(:application) { build_stubbed(:application, part_payment: part_payment, state: 3, decision: 'full', outcome: 'part') }
256+
257+
it 'returns the application decision' do
258+
is_expected.to eq 'full'
259+
end
260+
end
261+
262+
context 'when the application has no part payment' do
263+
let(:application) { build_stubbed(:application, part_payment: nil, outcome: 'granted') }
264+
265+
it 'returns the result' do
266+
is_expected.to eq 'granted'
267+
end
268+
end
269+
270+
context 'when the application is not processed' do
271+
let(:part_payment) { build_stubbed(:part_payment) }
272+
let(:application) { build_stubbed(:application, part_payment: part_payment, state: 2, decision: 'none', outcome: 'part') }
273+
274+
it 'returns the result' do
275+
is_expected.to eq 'part'
276+
end
277+
end
278+
end
279+
280+
describe '#pp_outcome' do
281+
subject { view.pp_outcome }
282+
283+
context 'when the part payment is successful' do
284+
let(:part_payment) { build_stubbed(:part_payment, correct: true, outcome: 'part') }
285+
let(:application) { build_stubbed(:application, part_payment: part_payment) }
286+
287+
it 'returns paid' do
288+
is_expected.to eq 'paid'
289+
end
290+
end
291+
292+
context 'when the part payment is not successful' do
293+
let(:part_payment) { build_stubbed(:part_payment, correct: false, outcome: 'none') }
294+
let(:application) { build_stubbed(:application, part_payment: part_payment) }
295+
296+
it 'returns the part payment outcome' do
297+
is_expected.to eq 'none'
298+
end
299+
end
300+
301+
context 'when there is no part payment' do
302+
let(:application) { build_stubbed(:application, part_payment: nil) }
303+
304+
it 'returns nil' do
305+
is_expected.to be_nil
306+
end
307+
end
308+
end
225309
end

0 commit comments

Comments
 (0)