Skip to content

Commit

Permalink
Show Claim Activities as a timeline
Browse files Browse the repository at this point in the history
  • Loading branch information
Nitemaeric committed Dec 24, 2024
1 parent f412a27 commit 27ec46b
Show file tree
Hide file tree
Showing 21 changed files with 256 additions and 14 deletions.
Original file line number Diff line number Diff line change
@@ -1,3 +1,17 @@
class Claims::Support::Claims::ClaimActivitiesController < Claims::Support::ApplicationController
before_action :skip_authorization
def index
@pagy, @claim_activities = pagy(Claims::ClaimActivity.order(created_at: :desc))

authorize [:claims, @claim_activities]
end

def show
@claim_activity = Claims::ClaimActivity.find(params[:id])

if @claim_activity.sampling_uploaded?
@pagy, @provider_samplings = pagy(@claim_activity.record.provider_samplings.order_by_provider_name)
end

authorize [:claims, @claim_activity]
end
end
12 changes: 9 additions & 3 deletions app/models/claims/claim_activity.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,17 @@
# fk_rails_... (user_id => users.id)
#
class Claims::ClaimActivity < ApplicationRecord
belongs_to :user
belongs_to :user, class_name: "Claims::SupportUser"
belongs_to :record, polymorphic: true

enum :action, {
payment_delivered: "payment_delivered",
sampling_in_progress: "sampling_in_progress",
payment_request_delivered: "payment_request_delivered",
payment_response_uploaded: "payment_response_uploaded",
sampling_uploaded: "sampling_uploaded",
sampling_response_uploaded: "sampling_response_uploaded",
clawback_request_delivered: "clawback_request_delivered",
clawback_response_uploaded: "clawback_response_uploaded",
}

delegate :full_name, to: :user, prefix: true, allow_nil: true
end
2 changes: 2 additions & 0 deletions app/models/claims/provider_sampling.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,5 +27,7 @@ class Claims::ProviderSampling < ApplicationRecord

has_one_attached :csv_file

scope :order_by_provider_name, -> { joins(:provider).order(providers: { name: :asc }) }

delegate :email_address, :name, to: :provider, prefix: true
end
2 changes: 2 additions & 0 deletions app/policies/claims/support/claims/claim_activity_policy.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
class Claims::Support::Claims::ClaimActivityPolicy < Claims::ApplicationPolicy
end
2 changes: 1 addition & 1 deletion app/services/claims/payment/create_and_deliver.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ def call
claim.update!(status: :payment_in_progress, payment_in_progress_at: Time.current)
end

Claims::ClaimActivity.create!(action: :payment_delivered, user: current_user, record: payment)
Claims::ClaimActivity.create!(action: :payment_request_delivered, user: current_user, record: payment)

transaction.after_commit do
Claims::PaymentMailer.payment_created_notification(payment).deliver_later
Expand Down
2 changes: 1 addition & 1 deletion app/services/claims/sampling/create_and_deliver.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ def call
end
end

Claims::ClaimActivity.create!(action: :sampling_in_progress, user: current_user, record: sampling)
Claims::ClaimActivity.create!(action: :sampling_uploaded, user: current_user, record: sampling)
end

private
Expand Down
59 changes: 57 additions & 2 deletions app/views/claims/support/claims/claim_activities/index.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,62 @@

<%= render "claims/support/claims/secondary_navigation", current: :activity_log %>

<h2 class="govuk-heading-m"><%= t(".sub_heading") %></h2>
<div class="govuk-grid-row">
<div class="govuk-grid-column-two-thirds">
<h2 class="govuk-heading-m"><%= t(".sub_heading") %></h2>

<p class="govuk-body"><%= t(".no_activity") %></p>
<% if @claim_activities.any? %>
<div class="app-timeline">
<% @claim_activities.each do |claim_activity| %>
<div class="app-timeline__item">
<div class="app-timeline__header">
<h3 class="app-timeline__title">
<%= Claims::ClaimActivity.human_attribute_name("action.#{claim_activity.action}") %>
</h3>

<p class="app-timeline__byline">
<%= t(".byline", user: claim_activity.user_full_name, time: l(claim_activity.created_at, format: :date_at_time)) %>
</p>
</div>

<div class="app-timeline__description">
<% case claim_activity.action %>
<% when "payment_request_delivered", "clawback_request_delivered" %>
<ul class="app-timeline__documents">
<li class="app-timeline__document-item">
<%= govuk_link_to claim_activity.record.csv_file, class: "app-timeline__document-link" do %>
<%= image_tag "icon-document.svg", class: "app-timeline__document-link__icon" %> Claims sent to ESFA
<% end %>
</li>
</ul>
<% when "sampling_uploaded" %>
<% provider_samplings = claim_activity.record.provider_samplings %>

<ul class="app-timeline__documents">
<% provider_samplings.limit(5).each do |provider_sampling| %>
<li class="app-timeline__document-item">
<%= govuk_link_to provider_sampling.csv_file, class: "app-timeline__document-link" do %>
<%= image_tag "icon-document.svg", class: "app-timeline__document-link__icon" %> <%= provider_sampling.provider.name %>
<% end %>
</li>
<% end %>
</ul>

<% if provider_samplings.offset(5).any? %>
<p class="govuk-body"><%= t(".showing", count: provider_samplings.limit(5).length, total_count: provider_samplings.count) %></p>

<%= govuk_link_to t(".view_all_files"), claims_support_claims_claim_activity_path(claim_activity) %>
<% end %>
<% end %>
</div>
</div>
<% end %>
</div>

<%= render PaginationComponent.new(pagy: @pagy) %>
<% else %>
<p class="govuk-body"><%= t(".no_activity") %></p>
<% end %>
</div>
</div>
</div>
28 changes: 28 additions & 0 deletions app/views/claims/support/claims/claim_activities/show.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<%= content_for :page_title, Claims::ClaimActivity.human_attribute_name("action.#{@claim_activity.action}") %>
<%= render "claims/support/primary_navigation", current: :claims %>

<% content_for(:before_content) do %>
<%= govuk_back_link href: claims_support_claims_claim_activities_path %>
<% end %>

<div class="govuk-width-container">
<p class="govuk-caption-l"><%= t(".page_caption") %></p>
<h1 class="govuk-heading-l"><%= Claims::ClaimActivity.human_attribute_name("action.#{@claim_activity.action}") %></h1>

<p class="govuk-body"><%= t(".byline", user: @claim_activity.user_full_name, time: l(@claim_activity.created_at, format: :date_at_time)) %></p>

<h2 class="govuk-heading-m"><%= t(".files") %></h2>

<%= govuk_list type: :bullet do %>
<% case @claim_activity.action %>
<% when "payment_request_delivered", "clawback_request_delivered" %>
<li><%= govuk_link_to "Claims sent to ESFA", @claim_activity.record.csv_file %></li>
<% when "sampling_uploaded" %>
<% @provider_samplings.each do |provider_sampling| %>
<li><%= govuk_link_to provider_sampling.provider.name, provider_sampling.csv_file %></li>
<% end %>
<% end %>
<% end %>

<%= render PaginationComponent.new(pagy: @pagy) if @pagy %>
</div>
1 change: 1 addition & 0 deletions config/locales/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,3 +31,4 @@ en:
long_with_seconds: "%-d %B %Y %H:%M:%S"
time: "%H:%M"
time_on_date: "%l:%M%P on %A %-d %B %Y"
date_at_time: "%-d %B %Y at %l:%M%P"
7 changes: 7 additions & 0 deletions config/locales/en/activerecord.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,13 @@ en:
clawback_requested: Clawback requested
clawback_in_progress: Clawback in progress
clawback_complete: Clawback complete
claims/claim_activity/action:
payment_request_delivered: Claims sent to ESFA for payment
payment_response_uploaded: ESFA payment response uploaded
sampling_uploaded: Sampling data uploaded
sampling_response_uploaded: Provider sampling response uploaded
clawback_request_delivered: Claims sent to ESFA for clawback
clawback_response_uploaded: ESFA clawback response uploaded
claims/claim_window:
academic_year: Academic year
window: Claim window
Expand Down
7 changes: 7 additions & 0 deletions config/locales/en/claims/support/claims/claim_activities.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,10 @@ en:
heading: Claims
sub_heading: Activity log
no_activity: There is no activity.
byline: "%{user} on %{time}"
showing: "Showing %{count} of %{total_count} files"
view_all_files: View all files
show:
page_caption: Activity log
byline: "%{user} on %{time}"
files: Files
2 changes: 1 addition & 1 deletion config/routes/claims.rb
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@
end
end

resources :claim_activities, path: "activity", only: %i[index]
resources :claim_activities, path: "activity", only: %i[index show]
end

resources :claims, only: %i[index show] do
Expand Down
12 changes: 9 additions & 3 deletions spec/factories/claims/claim_activities.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,16 @@
factory :claim_activity, class: "Claims::ClaimActivity" do
association :user, factory: :claims_support_user

trait :payment_delivered do
action { "payment_delivered" }
trait :payment_request_delivered do
action { "payment_request_delivered" }

association :record, factory: :claims_payment
record { build(:claims_payment, sent_by: user) }
end

trait :sampling_uploaded do
action { "sampling_uploaded" }

record { build(:claims_sampling) }
end
end
end
1 change: 1 addition & 0 deletions spec/factories/claims/payments.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,6 @@
association :sent_by, factory: :claims_support_user

claims { build_list(:claim, 3, :submitted) }
csv_file { file_fixture("example.csv") }
end
end
4 changes: 3 additions & 1 deletion spec/factories/claims/provider_samplings.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@
#
FactoryBot.define do
factory :provider_sampling, class: "Claims::ProviderSampling" do
association :sampling, factory: :samplings
association :sampling, factory: :claims_sampling
association :provider, factory: :claims_provider

csv_file { file_fixture("example.csv") }
end
end
3 changes: 2 additions & 1 deletion spec/factories/claims/samplings.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
# updated_at :datetime not null
#
FactoryBot.define do
factory :samplings, class: "Claims::Sampling" do
factory :claims_sampling, class: "Claims::Sampling" do
provider_samplings { build_list(:provider_sampling, 7, sampling: nil) }
end
end
2 changes: 2 additions & 0 deletions spec/factories/users.rb
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@

trait :support do
sequence(:email) { |n| "user#{n}@education.gov.uk" }

first_name { "Support User" }
end

trait :discarded do
Expand Down
2 changes: 2 additions & 0 deletions spec/fixtures/files/example.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
claim_reference,school_urn,school_name,claim_status
12345678,1234567,Example School,paid
4 changes: 4 additions & 0 deletions spec/support/factory_bot.rb
Original file line number Diff line number Diff line change
@@ -1 +1,5 @@
FactoryBot::SyntaxRunner.class_eval do
include RSpec::Rails::FileFixtureSupport
end

RSpec.configure { |config| config.include FactoryBot::Syntax::Methods }
58 changes: 58 additions & 0 deletions spec/system/claims/support/claims/view_a_claims_activity_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
require "rails_helper"

RSpec.describe "View a claims activity", service: :claims, type: :system do
let(:support_user) { create(:claims_support_user, first_name: "Colin", last_name: "Chapman") }
let(:created_at) { Time.zone.parse("20 December 2024 16:00") }

let(:payment_request_delivered) { create(:claim_activity, :payment_request_delivered, user: support_user, created_at:) }
let(:sampling_uploaded) { create(:claim_activity, :sampling_uploaded, user: support_user, created_at: created_at + 1.day) }

scenario "Support user visits a 'payment_request_delivered' activity" do
given_i_sign_in_as(support_user)
and_there_are_claim_activities(payment_request_delivered)
when_i_visit_the_claims_activity_by_url(payment_request_delivered)
then_i_can_see_the_claims_activity_payment_request_delivered_details
end

scenario "Support user views a 'sampling_uploaded' activity" do
given_i_sign_in_as(support_user)
and_there_are_claim_activities(sampling_uploaded)
when_i_visit_the_claims_activity_log
and_i_click_on_view_all_files_of_a_claim_activity
then_i_can_see_the_claims_activity_sampling_uploaded_details
end

private

def given_i_sign_in
visit sign_in_path
click_on "Sign in using DfE Sign In"
end

def and_there_are_claim_activities(*activities)
[*activities]
end

def when_i_visit_the_claims_activity_by_url(activity)
visit claims_support_claims_claim_activity_path(activity)
end

def when_i_visit_the_claims_activity_log
click_on "Claims"
click_on "Activity log"
end

def and_i_click_on_view_all_files_of_a_claim_activity
click_on "View all files"
end

def then_i_can_see_the_claims_activity_payment_request_delivered_details
expect(page).to have_css("h1.govuk-heading-l", text: "Claims sent to ESFA")
expect(page).to have_content("Colin Chapman on 20 December 2024 at 4:00pm")
end

def then_i_can_see_the_claims_activity_sampling_uploaded_details
expect(page).to have_css("h1.govuk-heading-l", text: "Sampling data uploaded")
expect(page).to have_content("Colin Chapman on 21 December 2024 at 4:00pm")
end
end
44 changes: 44 additions & 0 deletions spec/system/claims/support/claims/view_claims_activity_log_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
require "rails_helper"

RSpec.describe "View claims activity log", service: :claims, type: :system do
let(:support_user) { create(:claims_support_user, first_name: "Colin", last_name: "Chapman") }
let(:created_at) { Time.zone.parse("20 December 2024 16:00") }

let(:payment_request_delivered) { create(:claim_activity, :payment_request_delivered, user: support_user, created_at:) }
let(:sampling_uploaded) { create(:claim_activity, :sampling_uploaded, user: support_user, created_at: created_at + 1.day) }

scenario "Support user views the claims activity log" do
given_i_sign_in_as(support_user)
given_there_are_claim_activities
when_i_visit_the_claims_activity_log
then_i_can_see_the_claims_activities
end

private

def given_i_sign_in
visit sign_in_path
click_on "Sign in using DfE Sign In"
end

def given_there_are_claim_activities
[payment_request_delivered, sampling_uploaded]
end

def when_i_visit_the_claims_activity_log
click_on "Claims"
click_on "Activity log"
end

def then_i_can_see_the_claims_activities
within(".app-timeline__item:nth-child(1)") do
expect(page).to have_content("Sampling data uploaded")
expect(page).to have_content("Colin Chapman on 21 December 2024 at 4:00pm")
end

within(".app-timeline__item:nth-child(2)") do
expect(page).to have_content("Claims sent to ESFA for payment")
expect(page).to have_content("Colin Chapman on 20 December 2024 at 4:00pm")
end
end
end

0 comments on commit 27ec46b

Please sign in to comment.