diff --git a/app/models/kpis.rb b/app/models/kpis.rb index 8176369c..227a536b 100644 --- a/app/models/kpis.rb +++ b/app/models/kpis.rb @@ -62,4 +62,8 @@ def time_to_banking_approval def time_to_payment_confirmation TimeToPaymentConfirmationQuery.new.call end + + def status_breakdown + StatusBreakdownQuery.call + end end diff --git a/app/queries/status_breakdown_query.rb b/app/queries/status_breakdown_query.rb new file mode 100644 index 00000000..2b08f888 --- /dev/null +++ b/app/queries/status_breakdown_query.rb @@ -0,0 +1,22 @@ +class StatusBreakdownQuery + def self.call + new.execute + end + + def execute + ordered_with_defaults(status_breakdown) + end + +private + + def status_breakdown + ApplicationProgress.group(:status).count + end + + def ordered_with_defaults(breakdown) + ApplicationProgress.statuses.each_with_object({}) do |(key, _), hsh| + hsh[key] = breakdown.fetch(key, 0) + hsh + end + end +end diff --git a/app/views/system_admin/dashboard/show.html.erb b/app/views/system_admin/dashboard/show.html.erb index 4b160375..f2f37d87 100644 --- a/app/views/system_admin/dashboard/show.html.erb +++ b/app/views/system_admin/dashboard/show.html.erb @@ -141,4 +141,17 @@ +
+ + diff --git a/spec/queries/status_breakdown_query_spec.rb b/spec/queries/status_breakdown_query_spec.rb new file mode 100644 index 00000000..43603ded --- /dev/null +++ b/spec/queries/status_breakdown_query_spec.rb @@ -0,0 +1,45 @@ +require "rails_helper" + +RSpec.describe StatusBreakdownQuery, type: :service do + subject(:breakdown) { described_class.call } + + describe ".call" do + let(:expected_breakdown) do + { + "initial_checks" => 0, + "home_office_checks" => 0, + "school_checks" => 0, + "bank_approval" => 0, + "payment_confirmation" => 0, + "paid" => 0, + "rejected" => 0, + } + end + + it "returns the ordered application status breakdown" do + expect(breakdown).to include(expected_breakdown) + end + + context "with data" do + before do + create(:application, :with_initial_checks_completed) + end + + let(:expected_breakdown) do + { + "initial_checks" => 0, + "home_office_checks" => 1, + "school_checks" => 0, + "bank_approval" => 0, + "payment_confirmation" => 0, + "paid" => 0, + "rejected" => 0, + } + end + + it "returns the ordered application status breakdown" do + expect(breakdown).to include(expected_breakdown) + end + end + end +end