Skip to content

Commit

Permalink
EPBR-6817 removes other country table
Browse files Browse the repository at this point in the history
updated the service performance page to no longer include the table used to display data for 'other' countries. Also updated the tests for the downloading of csv data to be more accurate.
  • Loading branch information
barryhalper committed Sep 26, 2024
1 parent a0d7915 commit f66c28c
Show file tree
Hide file tree
Showing 6 changed files with 53 additions and 71 deletions.
2 changes: 1 addition & 1 deletion lib/domain/statistics_results.rb
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ def to_csv_hash(country:)
if %w[SAP RdSAP CEPC].include?(type) && !stats_item.nil?
hash["Average #{type} Energy Rating"] = stats_item.key?(:ratingAverage) && !stats_item[:ratingAverage].nil? ? stats_item[:ratingAverage].round(2) : nil
end
if %w[SAP RdSAP].include?(type) && !stats_item.nil?
if %w[SAP RdSAP].include?(type) && !stats_item.nil? && country != "other"
hash["Average #{type} CO2/sqm emissions"] = stats_item.key?(:avgCo2Emission) && !stats_item[:avgCo2Emission].nil? ? stats_item[:avgCo2Emission].round(2) : nil
end
end
Expand Down
14 changes: 1 addition & 13 deletions lib/views/partial__stats_accordion.erb
Original file line number Diff line number Diff line change
Expand Up @@ -55,19 +55,7 @@
show_average_co2: show_average_co2,
})
}},
{ heading: {
text: t('service_performance.contents.epcs_upload.tables.titles.other'),
prefix: t("service_performance.contents.epcs_upload.tables.hidden.certificates_uploaded_country.#{assessment_type.downcase}"),
},
content: {
html: erb(:partial__stats_table, locals: {
assessment_type: assessment_type,
country_key: "other",
values: values["Other"],
show_average_rating: show_average_rating,
show_average_co2: show_average_co2,
})
}}

] %>


Expand Down
68 changes: 14 additions & 54 deletions spec/acceptance/service_performance_csv_spec.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
require "csv"

shared_context "when request service performance csv" do
def stats_web_mock(body)
WebMock
Expand Down Expand Up @@ -26,20 +28,20 @@ def response_csv_header(body)
include RSpecFrontendServiceMixin
include_context "when request service performance csv"

before do
stats_web_mock(ServicePerformance::MonthsStatsDataStub.get_data)
ServicePerformance::AverageCo2EmissionsStub.statistics
end

let(:parsed_data) do
CSV.parse(response.body, headers: true)
end

describe "get . find-energy-certificate/service-performance/download-csv" do
let(:response) do
get "http://find-energy-certificate.epb-frontend/service-performance/download-csv"
end

let(:parsed_data) do
CSV.parse(response.body, headers: true)
end

before do
stats_web_mock(ServicePerformance::MonthsStatsDataStub.get_data)
ServicePerformance::AverageCo2EmissionsStub.statistics
end

it "return a response 200 response" do
expect(response.status).to eq(200)
end
Expand All @@ -52,16 +54,8 @@ def response_csv_header(body)
expect(file_name_from_header).to eq("service-performance-all-regions.csv")
end

it "has a csv with the correct headers" do
expect(response_csv_header(response.body)).to eq expected_header
end

it "has a csv with the correct body" do
expect(response.body).to match(/Oct-2021,21163,78.41,,122394,61.71,,8208,67.36,2189,470,1251/)
end

it "produces a data set with correct number of rows" do
expect(parsed_data.length).to eq(2)
expect(CSV.parse(response.body)).to eq CSV.parse(ServicePerformance::CsvStub.all_regions.strip!)
end

context "when calling the page with data in a different order" do
Expand Down Expand Up @@ -103,15 +97,6 @@ def response_csv_header(body)
get "http://find-energy-certificate.epb-frontend/service-performance/download-csv?country=england"
end

let(:parsed_data) do
CSV.parse(response.body, headers: true)
end

before do
stats_web_mock(ServicePerformance::MonthsStatsDataStub.get_data)
ServicePerformance::AverageCo2EmissionsStub.statistics
end

it "return a response 200 response" do
expect(response.status).to eq(200)
end
Expand All @@ -124,16 +109,8 @@ def response_csv_header(body)
expect(file_name_from_header).to eq("service-performance-england.csv")
end

it "has a csv with the correct headers" do
expect(response_csv_header(response.body)).to eq expected_header
end

it "has a csv with the correct body" do
expect(response.body).to match(/Sep-2021,23834,77.82,15,119033,61.74,10,7572,68.18,3298,402,861/)
end

it "produces a data set with correct number of rows" do
expect(parsed_data.length).to eq(2)
expect(CSV.parse(response.body)).to eq CSV.parse(ServicePerformance::CsvStub.england.strip!)
end
end

Expand All @@ -142,15 +119,6 @@ def response_csv_header(body)
get "http://find-energy-certificate.epb-frontend/service-performance/download-csv?country=northern-ireland"
end

let(:parsed_data) do
CSV.parse(response.body, headers: true)
end

before do
stats_web_mock(ServicePerformance::MonthsStatsDataStub.get_data)
ServicePerformance::AverageCo2EmissionsStub.statistics
end

it "return a response 200 response" do
expect(response.status).to eq(200)
end
Expand All @@ -163,16 +131,8 @@ def response_csv_header(body)
expect(file_name_from_header).to eq("service-performance-northern-ireland.csv")
end

it "has a csv with the correct headers" do
expect(response_csv_header(response.body)).to eq expected_header
end

it "has a csv with the correct body" do
expect(response.body).to match(/Oct-2021,674,81.7,,2349,61.11,,134,90.5,38,8,45/)
end

it "produces a data set with correct number of rows" do
expect(parsed_data.length).to eq(2)
expect(CSV.parse(response.body)).to eq CSV.parse(ServicePerformance::CsvStub.northern_ireland.strip!)
end
end
end
1 change: 0 additions & 1 deletion spec/acceptance/view_service_performance_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,6 @@
expect(response.body).to have_link("Download a copy of the data for England", href: "service-performance/download-csv?country=england")
expect(response.body).to have_link("Download a copy of the data for Northern Ireland", href: "service-performance/download-csv?country=northern-ireland")
expect(response.body).to have_link("Download a copy of the data for Wales", href: "service-performance/download-csv?country=wales")
expect(response.body).to have_link("Download a copy of the data for Other", href: "service-performance/download-csv?country=other")
end

it "ensure all ids are unique" do
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,9 @@ def self.statistics
"country": "Wales",
"yearMonth": "2022-05",
"assessmentType": "SAP" }],
other: [{ "avgCo2Emission": 10,
other: [{ "avgCo2Emission": 20,
"country": "Other",
"yearMonth": "2022-01",
"yearMonth": "2020-01",
"assessmentType": "SAP" }] }
end
end
Expand Down
35 changes: 35 additions & 0 deletions spec/test_doubles/service_performance/csv_stub.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
module ServicePerformance
class CsvStub
def self.all_regions
<<~CSV
Month,SAPs Lodged,Average SAP Energy Rating,Average SAP CO2/sqm emissions,RdSAPs Lodged,Average RdSAP Energy Rating,Average RdSAP CO2/sqm emissions,CEPCs Lodged,Average CEPC Energy Rating,DECs Lodged,DEC-RRs Lodged,AC-CERTs Lodged
Oct-2021,21163,78.41,,122394,61.71,,8208,67.36,2189,470,1251
Sep-2021,24477,77.83,16,121499,61.71,10,7718,68.27,3500,428,918
CSV
end

def self.england
<<~CSV
Month,SAPs Lodged,Average SAP Energy Rating,Average SAP CO2/sqm emissions,RdSAPs Lodged,Average RdSAP Energy Rating,Average RdSAP CO2/sqm emissions,CEPCs Lodged,Average CEPC Energy Rating,DECs Lodged,DEC-RRs Lodged,AC-CERTs Lodged
Oct-2021,20489,78.4,,120045,61.73,,8074,67.33,2781,462,1206
Sep-2021,23834,77.82,15,119033,61.74,10,7572,68.18,3298,402,861
CSV
end

def self.northern_ireland
<<~CSV
Month,SAPs Lodged,Average SAP Energy Rating,Average SAP CO2/sqm emissions,RdSAPs Lodged,Average RdSAP Energy Rating,Average RdSAP CO2/sqm emissions,CEPCs Lodged,Average CEPC Energy Rating,DECs Lodged,DEC-RRs Lodged,AC-CERTs Lodged
Oct-2021,674,81.7,,2349,61.11,,134,90.5,38,8,45
Sep-2021,643,82.56,,2466,58.59,,146,79.33,202,26,57
CSV
end

def self.other
<<~CSV
Month,SAPs Lodged,Average SAP Energy Rating,RdSAPs Lodged,Average RdSAP Energy Rating,CEPCs Lodged,Average CEPC Energy Rating,DECs Lodged,DEC-RRs Lodged,AC-CERTs Lodged
Oct-2021,21163,78.41,122394,61.71,8208,67.36,2189,470,1251
Sep-2021,24477,77.83,121499,61.71,7718,68.27,3500,428,918
CSV
end
end
end

0 comments on commit f66c28c

Please sign in to comment.