Skip to content

Commit 18652f4

Browse files
committed
chore/Update the billing section
The billing information is mandatory for energy suppliers to provide, but there could be a chance where we don't get any/all of the data required. Therefore we are going to adjust the section to render "N/A" if the data is missing; as confirmed by Emily
1 parent 3abf10d commit 18652f4

3 files changed

Lines changed: 32 additions & 9 deletions

File tree

app/components/csr_table/billing_and_metering_scores_component.rb

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,22 +25,26 @@ def descriptions
2525
def bills_accuracy_smart
2626
{
2727
term: content_tag(:p, "Bills accuracy (smart meters) "),
28-
description: content_tag(:p, "#{supplier.bills_accuracy_smart}%")
28+
description: content_tag(:p, description_content(supplier.bills_accuracy_smart))
2929
}
3030
end
3131

3232
def bills_accuracy_traditional
3333
{
3434
term: content_tag(:p, "Bills accuracy (traditional meters)"),
35-
description: content_tag(:p, "#{supplier.bills_accuracy_traditional}%")
35+
description: content_tag(:p, description_content(supplier.bills_accuracy_traditional))
3636
}
3737
end
3838

3939
def smart_operating
4040
{
4141
term: content_tag(:p, "Smart meters working correctly"),
42-
description: content_tag(:p, "#{supplier.smart_operating}%")
42+
description: content_tag(:p, description_content(supplier.smart_operating))
4343
}
4444
end
45+
46+
def description_content(supplier_field)
47+
supplier_field.present? ? "#{supplier_field}%" : "N/A"
48+
end
4549
end
4650
end

spec/components/csr_table/billing_and_metering_scores_component_spec.rb

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,20 @@
1414
it { is_expected.to have_text "Billing and metering" }
1515

1616
it { is_expected.to have_text "Bills accuracy (smart meters)" }
17-
it { is_expected.to have_text "98.3%" }
1817
it { is_expected.to have_text "Bills accuracy (traditional meters)" }
19-
it { is_expected.to have_text "82.9%" }
2018
it { is_expected.to have_text "Smart meters working correctly" }
21-
it { is_expected.to have_text "91.7%" }
19+
20+
context "when there is billing data" do
21+
it { is_expected.to have_text "98.3%" }
22+
it { is_expected.to have_text "82.9%" }
23+
it { is_expected.to have_text "91.7%" }
24+
end
25+
26+
context "when there is no billing data" do
27+
let(:supplier) { build(:supplier, :no_billing_data) }
28+
29+
it { is_expected.to have_text "N/A", count: 3 }
30+
end
2231

2332
context "when there is no supplier" do
2433
let(:supplier) { nil }

spec/factories/supplier.rb

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,6 @@
1212
guarantee_rating { 3 }
1313
overall_rating { 4.8 }
1414
bill_accuracy_and_metering_rating { 4.8 }
15-
bills_accuracy_smart { 98.3 }
16-
bills_accuracy_traditional { 82.9 }
17-
smart_operating { 91.7 }
1815
contact_info { { json: JSON.parse(File.read("spec/fixtures/contact_info.json")) } }
1916
billing_info { { json: JSON.parse(File.read("spec/fixtures/billing_info.json")) } }
2017
opening_hours { { json: JSON.parse(File.read("spec/fixtures/opening_hours.json")) } }
@@ -30,6 +27,15 @@
3027
contact_email { 89 }
3128
contact_social_media { "01:15:00" }
3229
guarantee_list { { json: JSON.parse(File.read("spec/fixtures/guarantee_list.json")) } }
30+
bills_accuracy_smart { 98.3 }
31+
bills_accuracy_traditional { 82.9 }
32+
smart_operating { 91.7 }
33+
end
34+
35+
trait :no_billing_data do
36+
bills_accuracy_smart { nil }
37+
bills_accuracy_traditional { nil }
38+
smart_operating { nil }
3339
end
3440

3541
trait :both_guarantee_schemes do
@@ -99,6 +105,10 @@
99105
data factory: %i[supplier_data ranked]
100106
end
101107

108+
trait(:no_billing_data) do
109+
data factory: %i[supplier_data no_billing_data]
110+
end
111+
102112
trait(:no_guarantee_schemes) do
103113
data factory: %i[supplier_data no_guarantee_schemes]
104114
end

0 commit comments

Comments
 (0)