-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add Forms funnel and Ineligible forms funnel
These widget have the ability to change the date_range of the formsfunnelquery but defaults to the last 24 hours. The date range filter feature is soft launched at the moment and is only usable via the url `/system-admin/dashboard?date_range[unit]=hours&date_range[range_start]=48&date_range[range_end]=24`
- Loading branch information
1 parent
648072b
commit a76257c
Showing
4 changed files
with
146 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,20 @@ | ||
module SystemAdmin | ||
class DashboardController < AdminController | ||
def show | ||
@kpis = Kpis.new | ||
@kpis = Kpis.new(**kpi_params) | ||
rescue ArgumentError => e | ||
flash[:alert] = e.message | ||
redirect_to(dashboard_path) | ||
end | ||
|
||
private | ||
|
||
def kpi_params | ||
params | ||
.fetch(:date_range, {}) | ||
.permit(:unit, :range_start, :range_end) | ||
.to_hash | ||
.symbolize_keys | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,35 +1,77 @@ | ||
require "rails_helper" | ||
|
||
RSpec.describe Kpis do | ||
describe "#total_applications" do | ||
it "returns the total number of applications" do | ||
create_list(:application, 5) | ||
subject(:kpis) { described_class.new(unit:, range_start:, range_end:) } | ||
|
||
let(:unit) { "hours" } | ||
let(:range_start) { "12" } | ||
let(:range_end) { "0" } | ||
|
||
kpis = described_class.new | ||
let(:application) { create(:application) } | ||
|
||
expect(kpis.total_applications).to eq(5) | ||
describe "argument error on initialize" do | ||
context "when unknown unit" do | ||
let(:unit) { "bad" } | ||
|
||
it { expect { kpis }.to raise_error(ArgumentError) } | ||
end | ||
end | ||
|
||
describe "#total_rejections" do | ||
it "returns the total number of applications rejected" do | ||
application = create(:application) | ||
create_list(:application_progress, 5, :rejection_completed, application:) | ||
context "when bad range_start and range_end" do | ||
let(:range_start) { "bad" } | ||
let(:range_end) { "bad" } | ||
|
||
it { expect { kpis }.to raise_error(ArgumentError) } | ||
end | ||
|
||
context "when range_start negative" do | ||
let(:range_start) { "-15" } | ||
|
||
it { expect { kpis }.to raise_error(ArgumentError) } | ||
end | ||
|
||
context "when range_end negative" do | ||
let(:range_end) { "-15" } | ||
|
||
it { expect { kpis }.to raise_error(ArgumentError) } | ||
end | ||
|
||
stats = described_class.new | ||
context "when range_end value greater than range_start" do | ||
let(:range_start) { "15" } | ||
let(:range_end) { "24" } | ||
|
||
expect(stats.total_rejections).to eq(5) | ||
it { expect { kpis }.to raise_error(ArgumentError) } | ||
end | ||
end | ||
|
||
describe "#total_applications" do | ||
before { create_list(:application, 5) } | ||
|
||
it { expect(kpis.total_applications).to eq(5) } | ||
end | ||
|
||
describe "#total_rejections" do | ||
before { create_list(:application_progress, 5, :rejection_completed, application:) } | ||
|
||
it { expect(kpis.total_rejections).to eq(5) } | ||
end | ||
|
||
describe "#total_paid" do | ||
it "returns the total number of applications paid" do | ||
application = create(:application) | ||
create_list(:application_progress, 5, :banking_approval_completed, application:) | ||
before { create_list(:application_progress, 5, :banking_approval_completed, application:) } | ||
|
||
it { expect(kpis.total_paid).to eq(5) } | ||
end | ||
|
||
describe "funnel_date_range_title" do | ||
context "when range_end is set to 0" do | ||
let(:range_end) { 0 } | ||
|
||
it { expect(kpis.funnel_date_range_title).to eq("last 12 hours") } | ||
end | ||
|
||
stats = described_class.new | ||
context "when range_end is not 0" do | ||
let(:range_end) { 6 } | ||
|
||
expect(stats.total_paid).to eq(5) | ||
it { expect(kpis.funnel_date_range_title).to eq("between 12 and 6 hours ago") } | ||
end | ||
end | ||
end |