Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Claim checklist #5831

Draft
wants to merge 5 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 15 additions & 12 deletions .rubocop_todo.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# This configuration was generated by
# `rubocop --auto-gen-config --auto-gen-only-exclude --exclude-limit 1000`
# on 2023-05-24 18:09:00 UTC using RuboCop version 1.51.0.
# on 2023-07-04 15:40:54 UTC using RuboCop version 1.53.1.
# The point is for the user to remove these configuration records
# one by one as the offenses are removed from the code base.
# Note that changes in the inspected code, or installation of new
Expand Down Expand Up @@ -78,6 +78,7 @@ Lint/FloatComparison:
- 'lib/extensions/string_extension.rb'

# Offense count: 9
# Configuration parameters: AllowedParentClasses.
Lint/MissingSuper:
Exclude:
- 'app/services/cclf/mapping_bill_adapter.rb'
Expand Down Expand Up @@ -140,7 +141,7 @@ Metrics/AbcSize:
- 'spec/support/seed_helpers.rb'
- 'spec/support/validation_helpers.rb'

# Offense count: 22
# Offense count: 21
# Configuration parameters: CountComments, Max, CountAsOne.
Metrics/ClassLength:
Exclude:
Expand Down Expand Up @@ -184,7 +185,7 @@ Metrics/CyclomaticComplexity:
- 'spec/api/v2/claim_spec.rb'
- 'spec/factories/claim/base_claims.rb'

# Offense count: 82
# Offense count: 79
# Configuration parameters: CountComments, Max, CountAsOne, AllowedMethods, AllowedPatterns.
Metrics/MethodLength:
Exclude:
Expand Down Expand Up @@ -292,7 +293,7 @@ Naming/AccessorMethodName:
- 'app/models/claims/state_machine.rb'
- 'app/services/claims/claim_actions_service.rb'

# Offense count: 4
# Offense count: 3
# This cop supports unsafe autocorrection (--autocorrect-all).
# Configuration parameters: EnforcedStyleForLeadingUnderscores.
# SupportedStylesForLeadingUnderscores: disallowed, required, optional
Expand Down Expand Up @@ -349,7 +350,7 @@ Naming/PredicateName:
- 'app/validators/fee_sub_model_validator.rb'
- 'app/validators/supplier_number_sub_model_validator.rb'

# Offense count: 270
# Offense count: 277
# Configuration parameters: EnforcedStyle, CheckMethodNames, CheckSymbols, AllowedIdentifiers, AllowedPatterns.
# SupportedStyles: snake_case, normalcase, non_integer
# AllowedIdentifiers: capture3, iso8601, rfc1123_date, rfc822, rfc2822, rfc3339, x86_64
Expand Down Expand Up @@ -393,6 +394,7 @@ Naming/VariableNumber:
- 'spec/presenters/claim/advocate_claim_presenter_spec.rb'
- 'spec/presenters/claim/advocate_hardship_claim_presenter_spec.rb'
- 'spec/presenters/fee/basic_fee_presenter_spec.rb'
- 'spec/requests/external_users/fees/add_unclaimed_spec.rb'
- 'spec/services/ccr/daily_attendance_adapter_spec.rb'
- 'spec/services/claim_reporter_spec.rb'
- 'spec/services/claims/context_mapper_spec.rb'
Expand Down Expand Up @@ -1389,7 +1391,7 @@ RSpec/MultipleExpectations:
- 'spec/views/case_workers/claims/show_spec.rb'
- 'spec/views/external_users/claims/show_spec.rb'

# Offense count: 1314
# Offense count: 1339
# Configuration parameters: AllowSubject, Max.
RSpec/MultipleMemoizedHelpers:
Exclude:
Expand Down Expand Up @@ -1528,7 +1530,7 @@ RSpec/NamedSubject:
- 'spec/services/injection_response_service_spec.rb'
- 'spec/validators/expense_validator_spec.rb'

# Offense count: 769
# Offense count: 771
# Configuration parameters: Max, AllowedGroups.
RSpec/NestedGroups:
Exclude:
Expand Down Expand Up @@ -1847,7 +1849,8 @@ Rails/Blank:
Exclude:
- 'spec/factories/claim/base_claims.rb'

# Offense count: 62
# Offense count: 61
# This cop supports unsafe autocorrection (--autocorrect-all).
# Configuration parameters: EnforcedStyle, AllowToTime.
# SupportedStyles: strict, flexible
Rails/Date:
Expand Down Expand Up @@ -2260,7 +2263,7 @@ Style/BlockDelimiters:
- 'spec/validators/claim/base_claim_validator_spec.rb'
- 'spec/validators/fee/interim_fee_validator_spec.rb'

# Offense count: 108
# Offense count: 85
# This cop supports unsafe autocorrection (--autocorrect-all).
# Configuration parameters: EnforcedStyle.
# SupportedStyles: nested, compact
Expand Down Expand Up @@ -2363,7 +2366,7 @@ Style/CombinableLoops:
Exclude:
- 'spec/models/ability_spec.rb'

# Offense count: 3
# Offense count: 2
# This cop supports safe autocorrection (--autocorrect).
# Configuration parameters: Keywords, RequireColon.
# Keywords: TODO, FIXME, OPTIMIZE, HACK, REVIEW, NOTE
Expand Down Expand Up @@ -2679,7 +2682,7 @@ Style/StringLiterals:
Exclude:
- 'spec/services/message_queue/aws_client_spec.rb'

# Offense count: 96
# Offense count: 94
# This cop supports safe autocorrection (--autocorrect).
# Configuration parameters: EnforcedStyle, MinSize.
# SupportedStyles: percent, brackets
Expand Down Expand Up @@ -2741,7 +2744,7 @@ Style/WordArray:
- 'spec/services/cclf/fee/misc_fee_adapter_spec.rb'
- 'spec/services/claims/context_mapper_spec.rb'

# Offense count: 762
# Offense count: 759
# This cop supports safe autocorrection (--autocorrect).
# Configuration parameters: Max, AllowHeredoc, AllowURI, URISchemes, IgnoreCopDirectives, AllowedPatterns.
# URISchemes: http, https
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
module ExternalUsers
module Fees
class AddUnclaimedsController < ExternalUsers::ApplicationController
skip_load_and_authorize_resource
before_action :set_claim, only: :create
before_action :set_fees, only: :create

def create
return head :bad_request if @fees.empty?

Claims::UpdateClaim.call(@claim, params: { misc_fees_attributes: @fees.map { |f| fee_attributes_for(f) } })

head :created
end

private

def set_claim
@claim = Claim::BaseClaim.active.find(add_unclaimed_params[:claim_id])
end

def set_fees
# @fees = (Fee::BaseFeeType.where(id: add_unclaimed_params[:fees]) & @claim.eligible_misc_fee_types) - claimed_fees
@fees = (add_unclaimed_params[:fees].map(&:to_i) & @claim.eligible_misc_fee_types.map(&:id)) - claimed_fees
end

def claimed_fees
@claim.fees.map(&:fee_type).pluck(:id)
end

def add_unclaimed_params
params.permit(
:claim_id,
fees: []
)
end

def fee_attributes_for(fee)
calculator = Claims::FeeCalculator::UnitPrice.new(@claim, fee_type_id: fee, fees: {})
{
fee_type_id: fee,
quantity: 1,
rate: calculator.call&.data&.amount
}
end
end
end
end
4 changes: 4 additions & 0 deletions app/helpers/claims_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -74,4 +74,8 @@ def display_elected_not_proceeded_signpost?(claim)
# This applies to both AGFS fee scheme 13 and LGFS fee scheme 10 but the dates are the same
claim.final? && Time.zone.today >= Settings.agfs_scheme_13_clair_release_date.beginning_of_day
end

def unclaimed_fees(claim)
(claim.eligible_misc_fee_types & Fee::MiscFeeType.where(unique_code: %w[MIUMU MIAPF])) - claim.fees.map(&:fee_type)
end
end
2 changes: 2 additions & 0 deletions app/models/certification.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ class Certification < ApplicationRecord
belongs_to :claim, class_name: 'Claim::BaseClaim'
belongs_to :certification_type

attr_accessor :additional_fees

validates_with CertificationValidator

def perform_validation?
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
- if fees_to_offer.present?
= form_with url: external_users_claim_fees_add_unclaimed_path(@claim.id), builder: GdsAdpFormBuilder do |f|
.js-callout-banner#mod-unclaimed-fees
= f.govuk_collection_check_boxes :additional_fees,
fees_to_offer,
:id,
:description,
legend: { text: 'You may be eligible for these additional fees' },
hint: { text: "Based on the details of your case there are some fees to which you would usually eligible. If you have not already included them in another claim for the same case then you may like to add them here. n future these can be added during the submission process as 'Miscellaneous Fees'" }
= govuk_button 'Add', id: 'add-unclaimed-fees', class: 'add-unclaimed-fees'
2 changes: 2 additions & 0 deletions app/views/external_users/certifications/new.html.haml
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
= render partial: 'offer_unclaimed_fees', locals: { fees_to_offer: unclaimed_fees(@claim) }

= content_for :page_title, flush: true do
= t(".page_title.#{present(@claim).type_identifier}")

Expand Down
43 changes: 43 additions & 0 deletions app/webpack/javascripts/modules/Modules.UnclaimedFees.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
moj.Modules.UnclaimedFees = {
init: function () {
this.checkListWrapper = document.getElementById('mod-unclaimed-fees')
if (this.checkListWrapper) {
this.button = document.getElementById('add-unclaimed-fees')
const form = this.button.closest('form')
this.url = form.getAttribute('action')
this.token = Array.from(form.getElementsByTagName('input')).filter(i => i.getAttribute('name') === 'authenticity_token')[0].value
this.checkBoxes = Array.from(this.checkListWrapper.getElementsByClassName('govuk-checkboxes__input'))
this.checkBoxes.forEach(box => { box.onchange = () => this.setSubmitButton() })
this.setSubmitButton()
this.button.addEventListener('click', (event) => this.submit(event))
}
},

setSubmitButton: function () {
if (!this.checkListWrapper) { return }

this.button.disabled = !this.checkBoxes.reduce((selected, box) => selected || (box.checked && !box.disabled), false)
},

submit: async function (event) {
event.preventDefault()

const feesToAdd = this.checkBoxes.filter(box => box.checked)

await fetch(this.url, {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({
authenticity_token: this.token,
fees: feesToAdd.map(fee => fee.value)
})
}).then(response => {
if (response.ok) {
feesToAdd.forEach(box => { box.disabled = true })
this.setSubmitButton()
} else {
console.log('There was a problem')
}
})
}
}
1 change: 1 addition & 0 deletions app/webpack/packs/application.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ import '../javascripts/modules/Helpers.Autocomplete.js'
import '../javascripts/modules/Modules.TableRowClick.js'
import '../javascripts/modules/Modules.AllocationScheme.js'
import '../javascripts/modules/Modules.AddEditAdvocate.js'
import '../javascripts/modules/Modules.UnclaimedFees.js'

import '../javascripts/plugins/jquery.numbered.elements.js'

Expand Down
1 change: 1 addition & 0 deletions config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,7 @@

namespace :fees do
post 'calculate_price', to: 'prices#calculate'
resource :add_unclaimed, only: :create
end
end

Expand Down
65 changes: 65 additions & 0 deletions spec/requests/external_users/fees/add_unclaimed_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
require 'rails_helper'

RSpec.shared_examples 'attempting to add unclaimed fees while not logged in' do
before { sign_out persona.user }

it do
add_fees
expect(response).to redirect_to(new_user_session_url)
end
end

RSpec.describe 'Adding unclaimed fees to claim' do
subject(:add_fees) { post external_users_claim_fees_add_unclaimed_url(claim), params: }

let(:persona) { create(:external_user) }
let(:misc_fee) { create(:misc_fee_type, :miumu, :agfs_scheme_15) }
let(:params) { { fees: [misc_fee.to_param] } }

before do
allow(claim).to receive(:eligible_misc_fee_types).and_return([misc_fee])

sign_in persona.user
end

context 'when the claim is not eligible for the fee' do
let(:claim) { create(:advocate_claim, :agfs_scheme_10, :with_graduated_fee_case) }

it do
add_fees
expect(response).to have_http_status(:bad_request)
end

it { expect { add_fees }.not_to change(claim.fees, :count) }

it_behaves_like 'attempting to add unclaimed fees while not logged in'
end

context 'when the claim is eligible for the fee and it has been claimed' do
let(:claim) { create(:advocate_claim, :agfs_scheme_15, :with_graduated_fee_case) }

before { claim.fees << build(:misc_fee, fee_type: misc_fee) }

it do
add_fees
expect(response).to have_http_status(:bad_request)
end

it { expect { add_fees }.not_to change(claim.fees, :count) }

it_behaves_like 'attempting to add unclaimed fees while not logged in'
end

context 'when the claim is eligible for the fee and it has not been claimed' do
let(:claim) { create(:advocate_claim, :agfs_scheme_15, :with_graduated_fee_case) }

it do
add_fees
expect(response).to have_http_status(:created)
end

it { expect { add_fees }.to change(claim.fees, :count).by(1) }

it_behaves_like 'attempting to add unclaimed fees while not logged in'
end
end
Loading