Skip to content

Commit

Permalink
Add last overall update to Dashboard
Browse files Browse the repository at this point in the history
  • Loading branch information
odlp committed Oct 5, 2020
1 parent e7a8671 commit 908b0fe
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 0 deletions.
4 changes: 4 additions & 0 deletions lib/dashboard_stats.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@ def total_organisations
api_catalogue.organisations_apis.count
end

def last_updated
by_organisation.max_by(&:last_updated)&.last_updated
end

def by_organisation
@_by_organsation ||= calculate_stats_by_organisation
end
Expand Down
2 changes: 2 additions & 0 deletions source/dashboard.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,15 @@ hide_in_navigation: true
<tr>
<th>Total APIs:</th>
<th>Departments Represented:</th>
<th>Last Update:</th>
</tr>
</thead>

<tbody>
<tr>
<td><%= dashboard_stats.total_apis %></td>
<td><%= dashboard_stats.total_organisations %></td>
<td><%= dashboard_stats.last_updated %></td>
</tr>
</tbody>
</table>
Expand Down
17 changes: 17 additions & 0 deletions spec/lib/dashboard_stats_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,23 @@
end
end

describe "#last_updated" do
let(:apis) do
[
instance_double(Api, organisation: "A", name: "A1", date_updated: Date.new(2020, 1, 1), date_added: Date.new(2016, 1, 1), provider: nil),
instance_double(Api, organisation: "A", name: "A2", date_updated: Date.new(2019, 1, 1), date_added: Date.new(2016, 1, 1), provider: nil),
instance_double(Api, organisation: "B", name: "B1", date_updated: Date.new(2018, 1, 1), date_added: Date.new(2016, 1, 1), provider: nil),
instance_double(Api, organisation: "C", name: "C1", date_updated: Date.new(2017, 1, 1), date_added: Date.new(2016, 1, 1), provider: nil),
]
end

let(:api_catalogue) { ApiCatalogue.new(apis) }

it "matches the most recently updated API" do
expect(subject.last_updated).to eq Date.new(2020, 1, 1)
end
end

describe "#by_organisation" do
it "provides stats per organisation" do
nhs_stats = subject.by_organisation.detect do |stats|
Expand Down

0 comments on commit 908b0fe

Please sign in to comment.