From d07f41ed24b2f7526e19a9ae93fd87f4c0ca8f4f Mon Sep 17 00:00:00 2001 From: timpeat Date: Wed, 11 Dec 2024 14:56:34 +0000 Subject: [PATCH] Simplify the Funding Decision data model --- Gemfile | 2 +- Gemfile.lock | 6 +- .../commands/create_draft_from_maat.rb | 2 +- .../deciding/commands/set_funding_decision.rb | 2 +- .../commands/update_from_maat_decision.rb | 6 +- app/aggregates/deciding/decision.rb | 7 +- app/components/decision_result_component.rb | 7 +- .../casework/maat_decisions_controller.rb | 1 - app/lib/maat/decision.rb | 65 +++----- app/lib/maat/get_decision.rb | 2 +- app/models/decisions/draft.rb | 7 +- app/models/decisions/overall_result_form.rb | 2 +- app/services/maat/base_translator.rb | 24 +++ .../create_draft_decision_from_reference.rb | 6 +- .../maat/crown_court_decision_translator.rb | 20 +++ app/services/maat/decision_translator.rb | 54 +++++++ .../maat/funding_decision_translator.rb | 20 +++ .../maat/interests_of_justice_translator.rb | 45 ++++++ app/services/maat/maat_id_service_object.rb | 6 +- app/services/maat/means_result_translator.rb | 22 +++ app/services/maat/means_translator.rb | 60 ++++++++ .../casework/crime_applications/show.html.erb | 2 + config/locales/en/casework.yml | 8 +- config/locales/en/helpers.yml | 4 +- spec/aggregates/reviewing/complete_spec.rb | 4 +- spec/components/decision_component_spec.rb | 2 +- .../decision_result_component_spec.rb | 38 +---- spec/lib/maat/decision_spec.rb | 85 ++++++++--- spec/lib/maat/get_decision_spec.rb | 12 +- .../decisions/overall_result_form_spec.rb | 2 +- .../crown_court_decision_translator_spec.rb | 12 ++ .../services/maat/decision_translator_spec.rb | 140 ++++++++++++++++++ .../maat/funding_decision_translator_spec.rb | 16 ++ .../interests_of_justice_translator_spec.rb | 52 +++++++ .../maat/means_result_translator_spec.rb | 12 ++ spec/services/maat/means_translator_spec.rb | 93 ++++++++++++ .../when_adding_a_decision_by_maat_id.rb | 32 ++++ .../a_maat_value_translator.rb | 7 + .../deciding/adding_a_cifc_decision_spec.rb | 33 +---- .../adding_a_maat_decision_by_maat_id_spec.rb | 55 +++---- ...dding_a_maat_decision_by_reference_spec.rb | 22 ++- .../adding_another_maat_decision_spec.rb | 49 ++---- .../deciding/removing_a_maat_decision_spec.rb | 31 +--- .../submitting_a_non_means_decision_spec.rb | 2 +- .../updating_a_decision_from_maat_spec.rb | 41 ++--- 45 files changed, 806 insertions(+), 314 deletions(-) create mode 100644 app/services/maat/base_translator.rb create mode 100644 app/services/maat/crown_court_decision_translator.rb create mode 100644 app/services/maat/decision_translator.rb create mode 100644 app/services/maat/funding_decision_translator.rb create mode 100644 app/services/maat/interests_of_justice_translator.rb create mode 100644 app/services/maat/means_result_translator.rb create mode 100644 app/services/maat/means_translator.rb create mode 100644 spec/services/maat/crown_court_decision_translator_spec.rb create mode 100644 spec/services/maat/decision_translator_spec.rb create mode 100644 spec/services/maat/funding_decision_translator_spec.rb create mode 100644 spec/services/maat/interests_of_justice_translator_spec.rb create mode 100644 spec/services/maat/means_result_translator_spec.rb create mode 100644 spec/services/maat/means_translator_spec.rb create mode 100644 spec/shared_contexts/when_adding_a_decision_by_maat_id.rb create mode 100644 spec/shared_examples/a_maat_value_translator.rb diff --git a/Gemfile b/Gemfile index 37897182b..efe459f13 100644 --- a/Gemfile +++ b/Gemfile @@ -25,7 +25,7 @@ gem 'laa-criminal-applications-datastore-api-client', gem 'laa-criminal-legal-aid-schemas', github: 'ministryofjustice/laa-criminal-legal-aid-schemas', - tag: 'v1.4.3' + tag: 'v1.5.0' # The original asset pipeline for Rails [https://github.com/rails/sprockets-rails] gem 'sprockets-rails' diff --git a/Gemfile.lock b/Gemfile.lock index 8f13c4a2d..2953bc663 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -9,10 +9,10 @@ GIT GIT remote: https://github.com/ministryofjustice/laa-criminal-legal-aid-schemas.git - revision: 861869efc25d2804f2b66d62df50d1330f28243f - tag: v1.4.3 + revision: dfe3d23ab4cc93ea3659db5d20950e14ce37a6a1 + tag: v1.5.0 specs: - laa-criminal-legal-aid-schemas (1.4.3) + laa-criminal-legal-aid-schemas (1.5.0) dry-schema (~> 1.13) dry-struct (~> 1.6.0) json-schema (~> 4.0.0) diff --git a/app/aggregates/deciding/commands/create_draft_from_maat.rb b/app/aggregates/deciding/commands/create_draft_from_maat.rb index c2d837bd9..6c0a0bc5b 100644 --- a/app/aggregates/deciding/commands/create_draft_from_maat.rb +++ b/app/aggregates/deciding/commands/create_draft_from_maat.rb @@ -2,7 +2,7 @@ module Deciding class CreateDraftFromMaat < Command attribute :application_id, Types::Uuid attribute :application_type, Types::ApplicationType - attribute :maat_decision, Maat::Decision + attribute :maat_decision, Decisions::Draft attribute :user_id, Types::Uuid def call diff --git a/app/aggregates/deciding/commands/set_funding_decision.rb b/app/aggregates/deciding/commands/set_funding_decision.rb index f8ea6ec5f..161f327ce 100644 --- a/app/aggregates/deciding/commands/set_funding_decision.rb +++ b/app/aggregates/deciding/commands/set_funding_decision.rb @@ -1,7 +1,7 @@ module Deciding class SetFundingDecision < Command attribute :user_id, Types::Uuid - attribute :funding_decision, Types::FundingDecisionResult + attribute :funding_decision, Types::FundingDecision def call with_decision do |decision| diff --git a/app/aggregates/deciding/commands/update_from_maat_decision.rb b/app/aggregates/deciding/commands/update_from_maat_decision.rb index c0ccd9ab4..3a1e128a8 100644 --- a/app/aggregates/deciding/commands/update_from_maat_decision.rb +++ b/app/aggregates/deciding/commands/update_from_maat_decision.rb @@ -1,11 +1,13 @@ module Deciding class UpdateFromMaatDecision < Command - attribute :maat_decision, Maat::Decision + attribute :maat_decision, Decisions::Draft attribute :user_id, Types::Uuid def call with_decision do |decision| - decision.sync_with_maat(maat_decision:, user_id:) + raise MaatRecordNotChanged unless maat_decision.checksum != decision.checksum + + decision.sync_with_maat(maat_decision: maat_decision.to_h, user_id: user_id) end end end diff --git a/app/aggregates/deciding/decision.rb b/app/aggregates/deciding/decision.rb index 10d0a314a..116094b4b 100644 --- a/app/aggregates/deciding/decision.rb +++ b/app/aggregates/deciding/decision.rb @@ -22,6 +22,7 @@ def create_draft(application_id:, user_id:, reference:) def create_draft_from_maat(application_id:, maat_decision:, user_id:, application_type:) raise AlreadyCreated unless @state.nil? + maat_decision = maat_decision.to_h apply DraftCreatedFromMaat.new( data: { decision_id:, application_id:, maat_decision:, user_id:, application_type: } ) @@ -42,9 +43,7 @@ def link_to_cifc(application_id:, user_id:) end def sync_with_maat(maat_decision:, user_id:) - raise MaatRecordNotChanged unless maat_decision&.checksum != checksum - - apply SynchedWithMaat.build(self, maat_decision:, user_id:) + apply SynchedWithMaat.build(self, maat_decision: maat_decision.to_h, user_id: user_id) end def set_interests_of_justice(user_id:, interests_of_justice:) @@ -128,7 +127,7 @@ def send_to_provider(user_id:, application_id:) end def update_from_maat(maat_attributes) - decision = Maat::Decision.new(maat_attributes) + decision = Decisions::Draft.new(maat_attributes) @maat_id = decision.maat_id @reference = decision.reference diff --git a/app/components/decision_result_component.rb b/app/components/decision_result_component.rb index 36eb2ca06..78c22b571 100644 --- a/app/components/decision_result_component.rb +++ b/app/components/decision_result_component.rb @@ -21,11 +21,6 @@ def call attr_reader :result def colour - case result - when /fail|inel/ - 'red' - else - 'green' - end + { 'grant' => 'green', 'refuse' => 'red' }.fetch(result, nil) end end diff --git a/app/controllers/casework/maat_decisions_controller.rb b/app/controllers/casework/maat_decisions_controller.rb index 9eee0427c..2c05aae8a 100644 --- a/app/controllers/casework/maat_decisions_controller.rb +++ b/app/controllers/casework/maat_decisions_controller.rb @@ -13,7 +13,6 @@ def new # import failed due to a technical issue). def create @form_object = ::Decisions::MaatIdForm.new(application: @crime_application) - @form_object.create_with_user!(permitted_params, current_user_id) set_flash(:maat_decision_linked, maat_id: @form_object.maat_id) diff --git a/app/lib/maat/decision.rb b/app/lib/maat/decision.rb index 83cf6a25e..4dbdc84a7 100644 --- a/app/lib/maat/decision.rb +++ b/app/lib/maat/decision.rb @@ -1,55 +1,28 @@ module Maat - class Decision < LaaCrimeSchemas::Structs::Decision - attribute :maat_id, Types::Integer - attribute? :case_id, Types::String.optional - attribute :funding_decision, Types::FundingDecisionResult.optional + class Decision < Dry::Struct + transform_keys(&:to_sym) - def checksum - Digest::MD5.hexdigest(to_json) - end + attribute? :maat_ref, Types::MaatId + attribute? :usn, Types::ApplicationReference.optional + attribute? :case_id, Types::String + attribute? :case_type, Types::String + attribute? :app_created_date, Types::DateTime.optional - alias decision_id maat_id + attribute? :ioj_result, Types::String.optional + attribute? :ioj_reason, Types::String.optional + attribute? :ioj_assessor_name, Types::String.optional - class << self - def build(response) - new( - reference: response['usn'], - maat_id: response['maat_ref'], - case_id: response['case_id'], - funding_decision: funding_decision(response['funding_decision']), - interests_of_justice: interests_of_justice(response), - means: means(response) - ) - end + attribute? :ioj_appeal_result, Types::String.optional - def funding_decision(maat_value) - return nil if maat_value.blank? + attribute? :means_result, Types::String.optional + attribute? :means_assessor_name, Types::String.optional + attribute? :date_means_created, Types::DateTime.optional - maat_value.downcase - end + attribute? :passport_result, Types::String.optional + attribute? :passport_assessor_name, Types::String.optional + attribute? :date_passport_created, Types::DateTime.optional - def interests_of_justice(response) - return nil if response['ioj_result'].blank? - - { - result: response['ioj_result'].downcase, - details: response['ioj_reason'], - assessed_by: response['ioj_assessor_name'], - assessed_on: response['app_created_date'] - } - end - - def result(maat_result); end - - def means(response) - return nil if response['means_result'].blank? - - { - result: response['means_result'].downcase, - assessed_by: response['means_assessor_name'], - assessed_on: response['date_means_created'] - } - end - end + attribute? :funding_decision, Types::String.optional + attribute? :cc_rep_decision, Types::String.optional end end diff --git a/app/lib/maat/get_decision.rb b/app/lib/maat/get_decision.rb index 34c2bd80a..cc91a6d4c 100644 --- a/app/lib/maat/get_decision.rb +++ b/app/lib/maat/get_decision.rb @@ -48,7 +48,7 @@ def get(path) # the response body includes a MAAT ID (maat_ref). return nil unless response.body.present? && response.body['maat_ref'].present? - Decision.build(response.body) + Decision.new(response.body) end attr_reader :http_client diff --git a/app/models/decisions/draft.rb b/app/models/decisions/draft.rb index 7ec040420..de58bcb7c 100644 --- a/app/models/decisions/draft.rb +++ b/app/models/decisions/draft.rb @@ -1,12 +1,11 @@ module Decisions class Draft < LaaCrimeSchemas::Structs::Decision - attribute? :funding_decision, Types::Nil | Types::FundingDecisionResult + attribute? :funding_decision, Types::Nil | Types::FundingDecision attribute? :reference, Types::Nil | Types::Integer attribute? :decision_id, Types::Nil | Types::Integer | Types::Uuid attribute? :application_id, Types::Uuid attribute? :maat_id, Types::Integer.optional attribute? :case_id, Types::String.optional - attribute? :checksum, Types::String.optional def to_param { crime_application_id: application_id, decision_id: decision_id } @@ -16,8 +15,8 @@ def complete? funding_decision.present? end - def as_json - LaaCrimeSchemas::Structs::Decision.new(self) + def checksum + Digest::MD5.hexdigest(to_json) end class << self diff --git a/app/models/decisions/overall_result_form.rb b/app/models/decisions/overall_result_form.rb index 2920e6a2b..355817602 100644 --- a/app/models/decisions/overall_result_form.rb +++ b/app/models/decisions/overall_result_form.rb @@ -6,7 +6,7 @@ class OverallResultForm validates :funding_decision, inclusion: { in: :possible_decisions } def possible_decisions - [Types::FundingDecisionResult['granted_on_ioj'], Types::FundingDecisionResult['fail_on_ioj']] + [Types::FundingDecision['grant'], Types::FundingDecision['refuse']] end class << self diff --git a/app/services/maat/base_translator.rb b/app/services/maat/base_translator.rb new file mode 100644 index 000000000..9333a9f06 --- /dev/null +++ b/app/services/maat/base_translator.rb @@ -0,0 +1,24 @@ +module Maat + class BaseTranslator + def initialize(original:) + @original = original + end + + class << self + def translate(original) + new(original:).translate + end + end + + # :nocov: + def translate + raise 'implement in subclasses' + end + # :nocov: + # + + private + + attr_reader :original + end +end diff --git a/app/services/maat/create_draft_decision_from_reference.rb b/app/services/maat/create_draft_decision_from_reference.rb index 498fe2bb8..ec44964c6 100644 --- a/app/services/maat/create_draft_decision_from_reference.rb +++ b/app/services/maat/create_draft_decision_from_reference.rb @@ -37,7 +37,11 @@ def application_id delegate :decision_id, to: :maat_decision def maat_decision - @maat_decision ||= Maat::GetDecision.new.by_usn!(reference) + return @maat_decision if @maat_decision + + maat_decision = Maat::GetDecision.new.by_usn!(reference) + + Maat::DecisionTranslator.translate(maat_decision) if maat_decision.present? end end end diff --git a/app/services/maat/crown_court_decision_translator.rb b/app/services/maat/crown_court_decision_translator.rb new file mode 100644 index 000000000..bf9803e74 --- /dev/null +++ b/app/services/maat/crown_court_decision_translator.rb @@ -0,0 +1,20 @@ +module Maat + class CrownCourtDecisionTranslator < BaseTranslator + def translate + return nil if funding_decision.blank? + + Types::FundingDecision[funding_decision] + end + + private + + def funding_decision + case original + when /Granted/ + 'grant' + when /Refused|Failed/ + 'refuse' + end + end + end +end diff --git a/app/services/maat/decision_translator.rb b/app/services/maat/decision_translator.rb new file mode 100644 index 000000000..4f756fd89 --- /dev/null +++ b/app/services/maat/decision_translator.rb @@ -0,0 +1,54 @@ +module Maat + class DecisionTranslator + def initialize(maat_decision:) + @maat_decision = maat_decision + end + + class << self + def translate(maat_decision) + new(maat_decision:).translate + end + end + + def translate + Decisions::Draft.new( + maat_id:, case_id:, reference:, interests_of_justice:, + means:, funding_decision:, decision_id: + ) + end + + private + + def maat_id + maat_decision.maat_ref + end + alias decision_id maat_id + + def reference + maat_decision.usn + end + + def interests_of_justice + InterestsOfJusticeTranslator.translate(maat_decision) + end + + def means + MeansTranslator.translate(maat_decision) + end + + def funding_decision + return crown_court_decision if crown_court_decision + return nil unless maat_decision.funding_decision + + FundingDecisionTranslator.translate(maat_decision.funding_decision) + end + + delegate :case_id, to: :maat_decision + + def crown_court_decision + CrownCourtDecisionTranslator.translate(maat_decision.cc_rep_decision) + end + + attr_reader :maat_decision + end +end diff --git a/app/services/maat/funding_decision_translator.rb b/app/services/maat/funding_decision_translator.rb new file mode 100644 index 000000000..9903b57ee --- /dev/null +++ b/app/services/maat/funding_decision_translator.rb @@ -0,0 +1,20 @@ +module Maat + class FundingDecisionTranslator < BaseTranslator + def translate + return nil if funding_decision.blank? + + Types::FundingDecision[funding_decision] + end + + private + + def funding_decision + case original + when /PASS|GRANTED|FULL/ + 'grant' + when /INEL|FAIL/ + 'refuse' + end + end + end +end diff --git a/app/services/maat/interests_of_justice_translator.rb b/app/services/maat/interests_of_justice_translator.rb new file mode 100644 index 000000000..9a1e9d083 --- /dev/null +++ b/app/services/maat/interests_of_justice_translator.rb @@ -0,0 +1,45 @@ +module Maat + class InterestsOfJusticeTranslator + def initialize(maat_decision:) + @maat_decision = maat_decision + end + + class << self + def translate(maat_decision) + new(maat_decision:).translate + end + end + + def translate + return nil unless result + + LaaCrimeSchemas::Structs::TestResult.new( + result:, assessed_by:, assessed_on:, details: + ) + end + + private + + def assessed_on + maat_decision.app_created_date + end + + def assessed_by + maat_decision.ioj_assessor_name + end + + def details + maat_decision.ioj_reason + end + + def result + if maat_decision.ioj_appeal_result.present? + maat_decision.ioj_appeal_result.downcase + else + maat_decision.ioj_result&.downcase + end + end + + attr_reader :maat_decision + end +end diff --git a/app/services/maat/maat_id_service_object.rb b/app/services/maat/maat_id_service_object.rb index 3e2f93937..c8029a08f 100644 --- a/app/services/maat/maat_id_service_object.rb +++ b/app/services/maat/maat_id_service_object.rb @@ -26,7 +26,11 @@ def application_id end def maat_decision - @maat_decision ||= Maat::GetDecision.new.by_maat_id!(maat_id) + return @maat_decision if @maat_decision + + maat_decision = Maat::GetDecision.new.by_maat_id!(maat_id) + + Maat::DecisionTranslator.translate(maat_decision) if maat_decision.present? end end end diff --git a/app/services/maat/means_result_translator.rb b/app/services/maat/means_result_translator.rb new file mode 100644 index 000000000..6675bcecb --- /dev/null +++ b/app/services/maat/means_result_translator.rb @@ -0,0 +1,22 @@ +module Maat + class MeansResultTranslator < BaseTranslator + def translate + return nil if original.blank? + + Types::TestResult[means_result] + end + + private + + def means_result + case original + when /PASS/ + 'pass' + when /FULL/ + 'contribution' + when /FAIL|INEL/ + 'fail' + end + end + end +end diff --git a/app/services/maat/means_translator.rb b/app/services/maat/means_translator.rb new file mode 100644 index 000000000..bf2a2a84d --- /dev/null +++ b/app/services/maat/means_translator.rb @@ -0,0 +1,60 @@ +module Maat + class MeansTranslator + def initialize(maat_decision:) + @maat_decision = maat_decision + end + + def translate + return nil unless result + + LaaCrimeSchemas::Structs::TestResult.new( + result:, assessed_by:, assessed_on: + ) + end + + class << self + def translate(maat_decision) + new(maat_decision:).translate + end + end + + private + + attr_reader :maat_decision + + def assessed_on + if passport_result_most_recent? + maat_decision.date_passport_created + else + maat_decision.date_means_created + end + end + + def assessed_by + if passport_result_most_recent? + maat_decision.passport_assessor_name + else + maat_decision.means_assessor_name + end + end + + def result + Maat::MeansResultTranslator.translate(maat_result) + end + + def maat_result + if passport_result_most_recent? + maat_decision.passport_result + else + maat_decision.means_result + end + end + + def passport_result_most_recent? + return false if maat_decision.date_passport_created.blank? + return true if maat_decision.date_means_created.blank? + + maat_decision.date_passport_created > maat_decision.date_means_created + end + end +end diff --git a/app/views/casework/crime_applications/show.html.erb b/app/views/casework/crime_applications/show.html.erb index 86e6a9279..35d1bd55f 100644 --- a/app/views/casework/crime_applications/show.html.erb +++ b/app/views/casework/crime_applications/show.html.erb @@ -1,8 +1,10 @@ <% title t('.page_title') %> + <% if FeatureFlags.adding_decisions.enabled? && @crime_application.decisions_pending? && @crime_application.reviewable_by?(current_user_id) %> <% message = t(:finish_adding_decisions, scope: 'flash.important', continue_adding_decision_link: govuk_link_to(t(:continue_adding_decision, scope: 'flash.important'), crime_application_send_decisions_path(@crime_application))) %> <%= render FlashNotice.new(:important, message) %> <% end %> + <%= render partial: 'review_overview', locals: { crime_application: @crime_application } %>
diff --git a/config/locales/en/casework.yml b/config/locales/en/casework.yml index d5d043d48..51847f97c 100644 --- a/config/locales/en/casework.yml +++ b/config/locales/en/casework.yml @@ -467,13 +467,18 @@ en: deleted_user_name: '[deleted]' decision_ioj_test_result: pass: Passed - fail: Refused + fail: Failed decision_means_test_result: pass: Passed fail: Failed +# deprecate > full: Contribution inel: Ineligible +# < deprecate decision_overall_result: + grant: Granted + refuse: Refused +# deprecate > granted: Granted granted_on_ioj: Granted fail_on_ioj: Failed IoJ @@ -482,6 +487,7 @@ en: failioj: Failed IoJ inel: Ineligible full: Granted - with a contribution +# < deprecate either_way: Either way esa: Income-related Employment and Support Allowance (ESA) diff --git a/config/locales/en/helpers.yml b/config/locales/en/helpers.yml index ea395f0bb..7892a991d 100644 --- a/config/locales/en/helpers.yml +++ b/config/locales/en/helpers.yml @@ -33,8 +33,8 @@ en: assessed_by: What is the name of the caseworker who assessed this? decisions_overall_result_form: funding_decision_options: - granted_on_ioj: Granted - fail_on_ioj: Failed interests of justice test + grant: Granted + fail: Failed interests of justice test decisions_comment_form: comment: Comments for provider (optional) decisions_maat_id_form: diff --git a/spec/aggregates/reviewing/complete_spec.rb b/spec/aggregates/reviewing/complete_spec.rb index 494b3ddcd..d56ecb010 100644 --- a/spec/aggregates/reviewing/complete_spec.rb +++ b/spec/aggregates/reviewing/complete_spec.rb @@ -44,7 +44,7 @@ [ Decisions::Draft.new( reference: reference, maat_id: nil, case_id: nil, interests_of_justice: nil, means: nil, - funding_decision: 'granted', comment: nil, decision_id: decision_id, application_id: application_id + funding_decision: 'grant', comment: nil, decision_id: decision_id, application_id: application_id ).as_json ] end @@ -58,7 +58,7 @@ Reviewing::AddDecision.call(**args) Deciding::CreateDraft.call(**args) - Deciding::SetFundingDecision.call(**args, funding_decision: 'granted') + Deciding::SetFundingDecision.call(**args, funding_decision: 'grant') end it 'changes the state from :received to :completed' do diff --git a/spec/components/decision_component_spec.rb b/spec/components/decision_component_spec.rb index 566c355da..561f86c6c 100644 --- a/spec/components/decision_component_spec.rb +++ b/spec/components/decision_component_spec.rb @@ -7,7 +7,7 @@ allow(decision).to receive_messages( interests_of_justice: {}, means: {}, - funding_decision: 'failioj', + funding_decision: 'grant', comment: nil, maat_id: nil ) diff --git a/spec/components/decision_result_component_spec.rb b/spec/components/decision_result_component_spec.rb index a6ee89dd9..3d23b9c72 100644 --- a/spec/components/decision_result_component_spec.rb +++ b/spec/components/decision_result_component_spec.rb @@ -8,45 +8,17 @@ render_inline(described_class.new(result:)) end - context 'when result is "granted"' do - let(:result) { 'granted' } + context 'when decision is "grant"' do + let(:result) { 'grant' } it { is_expected.to have_text('Granted') } it { is_expected.to have_css('.govuk-tag--green') } end - context 'when result is "granted_on_ioj"' do - let(:result) { 'granted_on_ioj' } + context 'when decision is "refuse"' do + let(:result) { 'refuse' } - it { is_expected.to have_text('Granted') } - it { is_expected.to have_css('.govuk-tag--green') } - end - - context 'when result is "failed_on_ioj"' do - let(:result) { 'fail_on_ioj' } - - it { is_expected.to have_text('Failed IoJ') } - it { is_expected.to have_css('.govuk-tag--red') } - end - - context 'when result is "failioj"' do - let(:result) { 'failioj' } - - it { is_expected.to have_text('Failed IoJ') } - it { is_expected.to have_css('.govuk-tag--red') } - end - - context 'when result is "inel"' do - let(:result) { 'inel' } - - it { is_expected.to have_text('Ineligible') } - it { is_expected.to have_css('.govuk-tag--red') } - end - - context 'when result is "failmeans"' do - let(:result) { 'failmeans' } - - it { is_expected.to have_text('Failed means') } + it { is_expected.to have_text('Refused') } it { is_expected.to have_css('.govuk-tag--red') } end end diff --git a/spec/lib/maat/decision_spec.rb b/spec/lib/maat/decision_spec.rb index eab8fa0e3..9c8cde4d8 100644 --- a/spec/lib/maat/decision_spec.rb +++ b/spec/lib/maat/decision_spec.rb @@ -1,8 +1,8 @@ require 'rails_helper' RSpec.describe Maat::Decision do - describe '.build()' do - subject(:build) { described_class.build(response) } + describe '.new' do + subject(:new) { described_class.new(response) } let(:response) do { @@ -21,29 +21,76 @@ } end - it 'returns an instance of a Maat::Decision' do - expect(build).to be_a described_class + describe '#usn' do + subject(:usn) { new.usn } + + it { is_expected.to be 10 } + end + + describe '#maat_ref' do + subject(:maat_ref) { new.maat_ref } + + it { is_expected.to be 600 } + end + + describe '#case_id' do + subject(:case_id) { new.case_id } + + it { is_expected.to eq '123123123' } + end + + describe '#case_type' do + subject(:case_type) { new.case_type } + + it { is_expected.to eq 'SUMMARY ONLY' } + end + + describe '#ioj_result' do + subject(:ioj_result) { new.ioj_result } + + it { is_expected.to eq 'PASS' } + end + + describe '#ioj_assessor_name' do + subject(:ioj_assessor_name) { new.ioj_assessor_name } + + it { is_expected.to eq 'System Test IoJ' } + end + + describe '#ioj_reason' do + subject(:ioj_reason) { new.ioj_reason } + + it { is_expected.to eq 'Details of IoJ' } + end + + describe '#app_created_date' do + subject(:app_created_date) { new.app_created_date } + + it { is_expected.to eq '2024-09-23T00:00:00' } end - it 'sets the interests of justice' do - expect(build.interests_of_justice.attributes).to eq( - assessed_by: 'System Test IoJ', - assessed_on: Date.new(2024, 9, 23), - details: 'Details of IoJ', - result: 'pass' - ) + describe '#means_result' do + subject(:means_result) { new.means_result } + + it { is_expected.to eq 'PASS' } end - it 'sets the means' do - expect(build.means.attributes).to eq( - assessed_by: 'System Test Means', - assessed_on: Date.new(2024, 9, 23), - result: 'pass' - ) + describe '#means_assessor_name' do + subject(:means_assessor_name) { new.means_assessor_name } + + it { is_expected.to eq 'System Test Means' } end - it 'sets the funding decision' do - expect(build.funding_decision).to eq('granted') + describe '#date_means_created' do + subject(:date_means_created) { new.date_means_created } + + it { is_expected.to eq '2024-09-23T17:18:56' } + end + + describe '#funding_decision' do + subject(:funding_decision) { new.funding_decision } + + it { is_expected.to eq 'GRANTED' } end end end diff --git a/spec/lib/maat/get_decision_spec.rb b/spec/lib/maat/get_decision_spec.rb index b75077c9a..80cc727c2 100644 --- a/spec/lib/maat/get_decision_spec.rb +++ b/spec/lib/maat/get_decision_spec.rb @@ -13,7 +13,7 @@ before do allow(connection).to receive(:get) { response } - allow(Maat::Decision).to receive(:build).with(body) { instance_double(Maat::Decision) } + allow(Maat::Decision).to receive(:new).with(body) { instance_double(Maat::Decision) } end describe '#by_usn' do @@ -23,14 +23,14 @@ expect(connection).to have_received(:get) .with('/api/external/v1/crime-application/result/usn/123456') - expect(Maat::Decision).to have_received(:build).with(body) + expect(Maat::Decision).to have_received(:new).with(body) end context 'when decision is empty found' do let(:body) { {} } it 'returns nil' do - expect(Maat::Decision).not_to have_received(:build) + expect(Maat::Decision).not_to have_received(:new) end end @@ -38,7 +38,7 @@ let(:body) { { 'maat_ref' => nil } } it 'returns nil' do - expect(Maat::Decision).not_to have_received(:build) + expect(Maat::Decision).not_to have_received(:new) end end end @@ -49,7 +49,7 @@ it 'makes a GET request to the MAAT API USN path' do get_by_usn! - expect(Maat::Decision).to have_received(:build).with(body) + expect(Maat::Decision).to have_received(:new).with(body) end context 'when decision is empty found' do @@ -76,7 +76,7 @@ expect(connection).to have_received(:get) .with('/api/external/v1/crime-application/result/rep-order-id/60123') - expect(Maat::Decision).to have_received(:build).with(body) + expect(Maat::Decision).to have_received(:new).with(body) end end end diff --git a/spec/models/decisions/overall_result_form_spec.rb b/spec/models/decisions/overall_result_form_spec.rb index 8b5b32c74..ec072e7b7 100644 --- a/spec/models/decisions/overall_result_form_spec.rb +++ b/spec/models/decisions/overall_result_form_spec.rb @@ -6,7 +6,7 @@ describe '#possible_decisions' do subject(:possible_decisions) { form_object.possible_decisions } - it { is_expected.to eq %w[granted_on_ioj fail_on_ioj] } + it { is_expected.to eq %w[grant refuse] } end describe '#command_class' do diff --git a/spec/services/maat/crown_court_decision_translator_spec.rb b/spec/services/maat/crown_court_decision_translator_spec.rb new file mode 100644 index 000000000..542f7fee2 --- /dev/null +++ b/spec/services/maat/crown_court_decision_translator_spec.rb @@ -0,0 +1,12 @@ +require 'rails_helper' + +RSpec.describe Maat::CrownCourtDecisionTranslator do + expected_translations = [ + 'Granted - Passed Means Test', 'grant', + 'Granted - Failed Means Test', 'grant', + 'Refused - Ineligible', 'refuse', + 'Failed - CfS Failed Means Test', 'refuse' + ].freeze + + it_behaves_like 'a MAAT value translator', expected_translations +end diff --git a/spec/services/maat/decision_translator_spec.rb b/spec/services/maat/decision_translator_spec.rb new file mode 100644 index 000000000..848bd921d --- /dev/null +++ b/spec/services/maat/decision_translator_spec.rb @@ -0,0 +1,140 @@ +require 'rails_helper' + +RSpec.describe Maat::DecisionTranslator do + let(:maat_decision) { Maat::Decision.new(funding_decision: nil) } + + describe '.translate' do + subject(:translate) { described_class.translate(maat_decision) } + + let(:maat_decision) { Maat::Decision.new } + + it { is_expected.to be_a Decisions::Draft } + + describe '#funding_decision' do + subject(:funding_decision) { translate.funding_decision } + + context 'when not decided' do + it { is_expected.to be_nil } + end + + context 'when funding decision exists' do + let(:maat_decision) { Maat::Decision.new(funding_decision: 'FAILIOJ') } + + it { is_expected.to eq 'refuse' } + end + + context 'when a crown court decision exists' do + let(:maat_decision) { Maat::Decision.new(cc_rep_decision: 'Granted - Passported') } + + it { is_expected.to eq 'grant' } + end + + context 'when both a crown court and funding decision exists' do + let(:maat_decision) do + Maat::Decision.new( + funding_decision: 'FAILMEIOJ', + cc_rep_decision: 'Granted - Passported' + ) + end + + it 'returns the crown court decision' do + expect(funding_decision).to eq 'grant' + end + end + end + + describe '#case_id' do + subject(:case_id) { translate.case_id } + + context 'when case_id nil' do + it { is_expected.to be_nil } + end + + context 'when case_id is set' do + let(:maat_decision) { Maat::Decision.new(case_id: 'AbD123') } + + it { is_expected.to eq 'AbD123' } + end + end + + describe '#maat_id' do + subject(:maat_id) { translate.maat_id } + + context 'when maat_ref nil' do + it { is_expected.to be_nil } + end + + context 'when maat_ref is set' do + let(:maat_decision) { Maat::Decision.new(maat_ref: 6_090_910) } + + it { is_expected.to be 6_090_910 } + end + end + + describe '#decision_id' do + subject(:decision_id) { translate.decision_id } + + context 'when maat_ref nil' do + it { is_expected.to be_nil } + end + + context 'when maat_ref is set' do + let(:maat_decision) { Maat::Decision.new(maat_ref: 6_090_910) } + + it { is_expected.to be 6_090_910 } + end + end + + describe '#reference' do + subject(:reference) { translate.reference } + + context 'when usn nil' do + it { is_expected.to be_nil } + end + + context 'when usn is set' do + let(:maat_decision) { Maat::Decision.new(usn: 6_090_910) } + + it { is_expected.to be 6_090_910 } + end + end + + describe '#means' do + subject(:means) { translate.means } + + let(:translated_means) do + LaaCrimeSchemas::Structs::TestResult.new( + result: 'pass', + assessed_by: 'Ken', + assessed_on: '2024-12-12' + ) + end + + before do + allow(Maat::MeansTranslator).to receive(:translate) + .with(maat_decision) { translated_means } + end + + it { is_expected.to be translated_means } + end + + describe '#interests_of_justice' do + subject(:interests_of_justice) { translate.interests_of_justice } + + let(:translated_interests_of_justice) do + LaaCrimeSchemas::Structs::TestResult.new( + result: 'fail', + assessed_by: 'Jo', + assessed_on: '2024-12-11' + ) + end + + before do + allow(Maat::InterestsOfJusticeTranslator).to receive(:translate) + .with(maat_decision) { translated_interests_of_justice } + end + + it { is_expected.to be translated_interests_of_justice } + end + end +end diff --git a/spec/services/maat/funding_decision_translator_spec.rb b/spec/services/maat/funding_decision_translator_spec.rb new file mode 100644 index 000000000..abbf2039c --- /dev/null +++ b/spec/services/maat/funding_decision_translator_spec.rb @@ -0,0 +1,16 @@ +require 'rails_helper' + +RSpec.describe Maat::FundingDecisionTranslator do + expected_translations = %w[ + PASS grant + FAIL refuse + INEL refuse + FULL grant + GRANTED grant + FAILMEANS refuse + FAILIOJ refuse + FAILMEIOJ refuse + ] + + it_behaves_like 'a MAAT value translator', expected_translations +end diff --git a/spec/services/maat/interests_of_justice_translator_spec.rb b/spec/services/maat/interests_of_justice_translator_spec.rb new file mode 100644 index 000000000..d72220ccf --- /dev/null +++ b/spec/services/maat/interests_of_justice_translator_spec.rb @@ -0,0 +1,52 @@ +require 'rails_helper' + +RSpec.describe Maat::InterestsOfJusticeTranslator do + let(:maat_decision) do + Maat::Decision.new( + maat_ref: 6_000_001, + ioj_reason: 'because', + ioj_assessor_name: 'Ken', + ioj_result: ioj_result, + app_created_date: DateTime.new(2024, 12, 12, 12), + ioj_appeal_result: ioj_appeal_result + ) + end + + let(:ioj_appeal_result) { nil } + + describe '.translate' do + subject(:translate) { described_class.translate(maat_decision) } + + context 'when IoJ result is nil' do + let(:ioj_result) { nil } + + it { is_expected.to be_nil } + end + + context 'when IoJ result set' do + let(:ioj_result) { 'FAIL' } + + it 'returns the translated result as a hash' do + expect(translate).to eq LaaCrimeSchemas::Structs::TestResult.new( + assessed_by: 'Ken', + assessed_on: DateTime.new(2024, 12, 12, 12), + details: 'because', + result: 'fail' + ) + end + + context 'when IoJ appeal result present' do + let(:ioj_appeal_result) { 'PASS' } + + it 'uses the appeal result' do + expect(translate).to eq LaaCrimeSchemas::Structs::TestResult.new( + assessed_by: 'Ken', + assessed_on: DateTime.new(2024, 12, 12, 12), + details: 'because', + result: 'pass' + ) + end + end + end + end +end diff --git a/spec/services/maat/means_result_translator_spec.rb b/spec/services/maat/means_result_translator_spec.rb new file mode 100644 index 000000000..1af6abc20 --- /dev/null +++ b/spec/services/maat/means_result_translator_spec.rb @@ -0,0 +1,12 @@ +require 'rails_helper' + +RSpec.describe Maat::MeansResultTranslator do + expected_translations = %w[ + PASS pass + INEL fail + FULL contribution + FAIL fail + ] + + it_behaves_like 'a MAAT value translator', expected_translations +end diff --git a/spec/services/maat/means_translator_spec.rb b/spec/services/maat/means_translator_spec.rb new file mode 100644 index 000000000..f908e84ce --- /dev/null +++ b/spec/services/maat/means_translator_spec.rb @@ -0,0 +1,93 @@ +require 'rails_helper' + +RSpec.describe Maat::MeansTranslator do + let(:maat_decision) { Maat::Decision.new } + + describe '.translate' do + subject(:translate) { described_class.translate(maat_decision) } + + context 'when the means result and passport result are both nil' do + let(:maat_decision) { Maat::Decision.new(maat_ref: 6_000_001) } + + it { is_expected.to be_nil } + end + + context 'when only the passport result is present' do + let(:maat_decision) do + Maat::Decision.new( + passport_assessor_name: 'Pam', + passport_result: 'PASS', + date_passport_created: DateTime.new(2024, 12, 12, 13) + ) + end + + it 'returns the passporting result details' do + expect(translate).to eq LaaCrimeSchemas::Structs::TestResult.new( + assessed_by: 'Pam', + assessed_on: DateTime.new(2024, 12, 12, 13), + result: 'pass' + ) + end + end + + context 'when only the means result is present' do + let(:maat_decision) do + Maat::Decision.new( + means_assessor_name: 'Kit', + means_result: 'FAIL', + date_means_created: DateTime.new(2024, 12, 12, 12) + ) + end + + it 'returns the means result details' do + expect(translate).to eq LaaCrimeSchemas::Structs::TestResult.new( + assessed_by: 'Kit', + assessed_on: DateTime.new(2024, 12, 12, 12), + result: 'fail' + ) + end + end + + context 'when both means and passport results are present' do + let(:maat_decision) do + Maat::Decision.new( + passport_assessor_name: 'Pam', + passport_result: 'PASS', + date_passport_created: DateTime.new(2024, 12, 12, 13), + means_assessor_name: 'Kit', + means_result: 'FAIL', + date_means_created: DateTime.new(2024, 12, 12, 12) + ) + end + + it 'uses the most recent' do + expect(translate).to eq LaaCrimeSchemas::Structs::TestResult.new( + assessed_by: 'Pam', + assessed_on: DateTime.new(2024, 12, 12, 13), + result: 'pass' + ) + end + end + + context 'when means and passport results have the same timestamp' do + let(:maat_decision) do + Maat::Decision.new( + passport_assessor_name: 'Pam', + passport_result: 'PASS', + date_passport_created: DateTime.new(2024, 12, 12, 12), + means_assessor_name: 'Kit', + means_result: 'FAIL', + date_means_created: DateTime.new(2024, 12, 12, 12) + ) + end + + it 'returns the means result details' do + expect(translate).to eq LaaCrimeSchemas::Structs::TestResult.new( + assessed_by: 'Kit', + assessed_on: DateTime.new(2024, 12, 12, 12), + result: 'fail' + ) + end + end + end +end diff --git a/spec/shared_contexts/when_adding_a_decision_by_maat_id.rb b/spec/shared_contexts/when_adding_a_decision_by_maat_id.rb new file mode 100644 index 000000000..38558f6b3 --- /dev/null +++ b/spec/shared_contexts/when_adding_a_decision_by_maat_id.rb @@ -0,0 +1,32 @@ +RSpec.shared_context 'when adding a decision by MAAT ID' do + let(:maat_decision) do + Maat::Decision.new( + maat_ref: maat_decision_maat_id, + usn: maat_decision_reference, + ioj_result: 'PASS', + ioj_assessor_name: 'Jo Bloggs', + app_created_date: 1.day.ago.to_s, + means_result: 'PASS', + means_assessor_name: 'Jo Bloggs', + date_means_created: 1.day.ago.to_s, + funding_decision: maat_decision_funding_decision + ) + end + + let(:maat_decision_funding_decision) { 'GRANTED' } + let(:maat_decision_reference) { 6_000_001 } + let(:maat_decision_maat_id) { 999_333 } + let(:mock_get_decision) { instance_double(Maat::GetDecision) } + + before do + allow(DatastoreApi::Requests::UpdateApplication).to receive(:new) + .and_return(instance_double(DatastoreApi::Requests::UpdateApplication, call: {})) + + allow(FeatureFlags).to receive(:adding_decisions) { + instance_double(FeatureFlags::EnabledFeature, enabled?: true) + } + + allow(mock_get_decision).to receive(:by_maat_id!).with(maat_decision_maat_id).and_return(maat_decision) + allow(Maat::GetDecision).to receive(:new).and_return(mock_get_decision) + end +end diff --git a/spec/shared_examples/a_maat_value_translator.rb b/spec/shared_examples/a_maat_value_translator.rb new file mode 100644 index 000000000..219a9f23b --- /dev/null +++ b/spec/shared_examples/a_maat_value_translator.rb @@ -0,0 +1,7 @@ +RSpec.shared_examples 'a MAAT value translator' do |expected_translations| + expected_translations.each_slice(2).each do |original, expected| + it "#{original} is translated to #{expected}" do + expect(described_class.translate(original)).to eq(expected) + end + end +end diff --git a/spec/system/casework/deciding/adding_a_cifc_decision_spec.rb b/spec/system/casework/deciding/adding_a_cifc_decision_spec.rb index ba730bbde..efcefa62c 100644 --- a/spec/system/casework/deciding/adding_a_cifc_decision_spec.rb +++ b/spec/system/casework/deciding/adding_a_cifc_decision_spec.rb @@ -2,11 +2,11 @@ RSpec.describe 'Adding a decision by MAAT ID' do include_context 'with stubbed application' + include_context 'when adding a decision by MAAT ID' + let(:application_id) { '98ab235c-f125-4dcb-9604-19e81782e53b' } let(:application_data) { JSON.parse(LaaCrimeSchemas.fixture(1.0, name: 'change_in_financial_circumstances').read) } - let(:mock_get_decision) { instance_double(Maat::GetDecision) } - let(:origional_application) do instance_double( CrimeApplication, @@ -18,16 +18,6 @@ end before do - allow(DatastoreApi::Requests::UpdateApplication).to receive(:new) - .and_return(instance_double(DatastoreApi::Requests::UpdateApplication, call: {})) - - allow(FeatureFlags).to receive(:adding_decisions) { - instance_double(FeatureFlags::EnabledFeature, enabled?: true) - } - - allow(mock_get_decision).to receive(:by_maat_id!).with(maat_id).and_return(maat_decision) - allow(Maat::GetDecision).to receive(:new).and_return(mock_get_decision) - visit crime_application_path(application_id) click_button 'Assign to your list' click_button 'Mark as ready for MAAT' @@ -39,23 +29,8 @@ context 'when the original maat record is found' do let(:maat_id) { 987_654_321 } - let(:maat_decision) do - Maat::Decision.new( - maat_id: maat_id, - reference: origional_application.reference, - interests_of_justice: { - result: 'pass', - assessed_by: 'Jo Bloggs', - assessed_on: 1.day.ago.to_s - }, - means: { - result: 'pass', - assessed_by: 'Jo Bloggs', - assessed_on: 1.day.ago.to_s - }, - funding_decision: 'granted' - ) - end + let(:maat_decision_maat_id) { maat_id } + let(:maat_decision_reference) { origional_application.reference } it 'creates the decision and shows the success message' do save_and_continue diff --git a/spec/system/casework/deciding/adding_a_maat_decision_by_maat_id_spec.rb b/spec/system/casework/deciding/adding_a_maat_decision_by_maat_id_spec.rb index c77662b58..dd404ba0f 100644 --- a/spec/system/casework/deciding/adding_a_maat_decision_by_maat_id_spec.rb +++ b/spec/system/casework/deciding/adding_a_maat_decision_by_maat_id_spec.rb @@ -4,21 +4,11 @@ include DecisionFormHelpers include_context 'with stubbed application' + include_context 'when adding a decision by MAAT ID' - let(:mock_get_decision) { instance_double(Maat::GetDecision) } - let(:maat_decision) { nil } + let(:maat_decision_maat_id) { maat_id } before do - allow(DatastoreApi::Requests::UpdateApplication).to receive(:new) - .and_return(instance_double(DatastoreApi::Requests::UpdateApplication, call: {})) - - allow(FeatureFlags).to receive(:adding_decisions) { - instance_double(FeatureFlags::EnabledFeature, enabled?: true) - } - - allow(mock_get_decision).to receive(:by_maat_id!).with(maat_id).and_return(maat_decision) - allow(Maat::GetDecision).to receive(:new).and_return(mock_get_decision) - visit crime_application_path(application_id) click_button 'Assign to your list' click_button 'Mark as ready for MAAT' @@ -31,6 +21,7 @@ context 'when MAAT ID not entered' do let(:maat_id) { nil } + let(:maat_decision) { nil } it 'shows an error' do expect(page).to have_error( @@ -54,19 +45,15 @@ let(:maat_decision) do Maat::Decision.new( - maat_id: maat_id, - reference: 6_000_001, - interests_of_justice: { - result: 'fail', - assessed_by: 'Jo Blogs', - assessed_on: Date.new(2024, 2, 1) - }, - means: { - result: 'fail', - assessed_by: 'Jan Blogs', - assessed_on: Date.new(2024, 2, 2) - }, - funding_decision: 'failmeioj' + maat_ref: maat_id, + usn: 6_000_001, + ioj_result: 'FAIL', + ioj_assessor_name: 'Jo Blogs', + app_created_date: Date.new(2024, 2, 1), + means_result: 'FAIL', + means_assessor_name: 'Jan Blogs', + date_means_created: Date.new(2024, 2, 2), + funding_decision: 'FAILMEIOJ' ) end @@ -76,14 +63,14 @@ ) expect(summary_card('Case')).to have_rows( - 'Interests of justice (IoJ) test result', 'Refused', + 'Interests of justice (IoJ) test result', 'Failed', 'IoJ comments', '', 'IoJ caseworker', 'Jo Blogs', 'IoJ test date', '01/02/2024', 'Means test result', 'Failed', 'Means test caseworker', 'Jan Blogs', 'Means test date', '02/02/2024', - 'Overall result', 'Failed means and IoJ' + 'Overall result', 'Refused' ) expect(current_path).to eq( @@ -97,11 +84,8 @@ let(:maat_decision) do Maat::Decision.new( - maat_id: maat_id, - reference: 6_000_002, - interests_of_justice: nil, - means: nil, - funding_decision: nil + maat_ref: maat_id, + usn: 6_000_002 ) end @@ -117,11 +101,8 @@ let(:maat_decision) do Maat::Decision.new( - maat_id: maat_id, - reference: 6_000_001, - interests_of_justice: nil, - means: nil, - funding_decision: nil + maat_ref: maat_id, + usn: 6_000_001 ) end diff --git a/spec/system/casework/deciding/adding_a_maat_decision_by_reference_spec.rb b/spec/system/casework/deciding/adding_a_maat_decision_by_reference_spec.rb index 3fbb62bca..4e051cf0c 100644 --- a/spec/system/casework/deciding/adding_a_maat_decision_by_reference_spec.rb +++ b/spec/system/casework/deciding/adding_a_maat_decision_by_reference_spec.rb @@ -52,19 +52,15 @@ context 'when an application for the reference is found on MAAT' do let(:maat_decision) do Maat::Decision.new( - maat_id: 999_333, - reference: 6_000_001, - interests_of_justice: { - result: 'pass', - assessed_by: 'Jo Bloggs', - assessed_on: 1.day.ago.to_s - }, - means: { - result: 'pass', - assessed_by: 'Jo Bloggs', - assessed_on: 1.day.ago.to_s - }, - funding_decision: 'granted' + maat_ref: 999_333, + usn: 6_000_001, + ioj_result: 'PASS', + ioj_assessor_name: 'Jo Bloggs', + app_created_date: 1.day.ago.to_s, + means_result: 'PASS', + means_assessor_name: 'Jo Bloggs', + date_means_created: 1.day.ago.to_s, + funding_decision: 'GRANTED' ) end diff --git a/spec/system/casework/deciding/adding_another_maat_decision_spec.rb b/spec/system/casework/deciding/adding_another_maat_decision_spec.rb index 334e79851..31739a9de 100644 --- a/spec/system/casework/deciding/adding_another_maat_decision_spec.rb +++ b/spec/system/casework/deciding/adding_another_maat_decision_spec.rb @@ -4,44 +4,23 @@ include DecisionFormHelpers include_context 'with stubbed application' + include_context 'when adding a decision by MAAT ID' - let(:mock_get_decision) { instance_double(Maat::GetDecision) } let(:maat_id) { 12_312_345 } let(:maat_id2) { 12_312_347 } - - let(:maat_decision) do - Maat::Decision.new( - maat_id: maat_id, - reference: 6_000_001, - interests_of_justice: { - result: 'pass', - assessed_by: 'Jo Bloggs', - assessed_on: 1.day.ago.to_s - }, - means: { - result: 'pass', - assessed_by: 'Jo Bloggs', - assessed_on: 1.day.ago.to_s - }, - funding_decision: 'granted' - ) - end + let(:maat_decision_maat_id) { maat_id } let(:maat_decision2) do Maat::Decision.new( - maat_id: maat_id2, - reference: nil, - interests_of_justice: { - result: 'pass', - assessed_by: 'Jo Bloggs', - assessed_on: 1.hour.ago.to_s - }, - means: { - result: 'fail', - assessed_by: 'Jo Bloggs', - assessed_on: 1.hour.ago.to_s - }, - funding_decision: 'failmeans' + maat_ref: maat_id2, + usn: nil, + ioj_result: 'PASS', + ioj_assessor_name: 'Jo Bloggs', + app_created_date: 1.day.ago.to_s, + means_result: 'FAIL', + means_assessor_name: 'Jo Bloggs', + date_means_created: 1.day.ago.to_s, + funding_decision: 'FAILMEANS' ) end @@ -49,13 +28,7 @@ allow(DatastoreApi::Requests::UpdateApplication).to receive(:new) .and_return(instance_double(DatastoreApi::Requests::UpdateApplication, call: {})) - allow(FeatureFlags).to receive(:adding_decisions) { - instance_double(FeatureFlags::EnabledFeature, enabled?: true) - } - - allow(mock_get_decision).to receive(:by_maat_id!).with(maat_id).and_return(maat_decision) allow(mock_get_decision).to receive(:by_maat_id!).with(maat_id2).and_return(maat_decision2) - allow(Maat::GetDecision).to receive(:new).and_return(mock_get_decision) visit crime_application_path(application_id) click_button 'Assign to your list' diff --git a/spec/system/casework/deciding/removing_a_maat_decision_spec.rb b/spec/system/casework/deciding/removing_a_maat_decision_spec.rb index ecf2387d5..e88ddc5dc 100644 --- a/spec/system/casework/deciding/removing_a_maat_decision_spec.rb +++ b/spec/system/casework/deciding/removing_a_maat_decision_spec.rb @@ -4,39 +4,12 @@ include DecisionFormHelpers include_context 'with stubbed application' - - let(:mock_get_decision) { instance_double(Maat::GetDecision) } - let(:maat_decision) do - Maat::Decision.new( - maat_id: maat_id, - reference: 6_000_001, - interests_of_justice: { - result: 'pass', - assessed_by: 'Jo Bloggs', - assessed_on: 1.day.ago.to_s - }, - means: { - result: 'pass', - assessed_by: 'Jo Bloggs', - assessed_on: 1.day.ago.to_s - }, - funding_decision: 'granted' - ) - end + include_context 'when adding a decision by MAAT ID' let(:maat_id) { 123 } + let(:maat_decision_maat_id) { maat_id } before do - allow(DatastoreApi::Requests::UpdateApplication).to receive(:new) - .and_return(instance_double(DatastoreApi::Requests::UpdateApplication, call: {})) - - allow(FeatureFlags).to receive(:adding_decisions) { - instance_double(FeatureFlags::EnabledFeature, enabled?: true) - } - - allow(mock_get_decision).to receive(:by_maat_id!).with(maat_id).and_return(maat_decision) - allow(Maat::GetDecision).to receive(:new).and_return(mock_get_decision) - visit crime_application_path(application_id) click_button 'Assign to your list' click_button 'Mark as ready for MAAT' diff --git a/spec/system/casework/deciding/submitting_a_non_means_decision_spec.rb b/spec/system/casework/deciding/submitting_a_non_means_decision_spec.rb index ec349d795..27d40ad79 100644 --- a/spec/system/casework/deciding/submitting_a_non_means_decision_spec.rb +++ b/spec/system/casework/deciding/submitting_a_non_means_decision_spec.rb @@ -24,7 +24,7 @@ 'assessed_on' => '2024-10-01 00:00:00' }, 'means' => nil, - 'funding_decision' => 'granted', + 'funding_decision' => 'grant', 'comment' => 'Test comment' } ] diff --git a/spec/system/casework/deciding/updating_a_decision_from_maat_spec.rb b/spec/system/casework/deciding/updating_a_decision_from_maat_spec.rb index 8ed4d1ce7..0bf85899b 100644 --- a/spec/system/casework/deciding/updating_a_decision_from_maat_spec.rb +++ b/spec/system/casework/deciding/updating_a_decision_from_maat_spec.rb @@ -9,21 +9,18 @@ let(:missing_prompt) { 'Information missing' } let(:maat_decision) do Maat::Decision.new( - maat_id: 999_333, - reference: 6_000_001, - interests_of_justice: { - result: 'pass', - assessed_by: 'Jo Bloggs', - assessed_on: 1.day.ago.to_s - }, - means: { - result: 'pass', - assessed_by: 'Jo Bloggs', - assessed_on: 1.day.ago.to_s - }, + maat_ref: 999_333, + usn: 6_000_001, + ioj_result: 'PASS', + ioj_assessor_name: 'Jo Bloggs', + app_created_date: 1.day.ago.to_s, + means_result: 'PASS', + means_assessor_name: 'Jo Bloggs', + date_means_created: 1.day.ago.to_s, funding_decision: nil ) end + let(:reference) { 6_000_001 } before do @@ -36,7 +33,7 @@ allow(mock_get_decision).to receive(:by_usn!).with(reference).and_return(maat_decision) - allow(mock_get_decision).to receive(:by_maat_id!).with(maat_decision.maat_id).and_return(v2) + allow(mock_get_decision).to receive(:by_maat_id!).with(maat_decision.maat_ref).and_return(v2) allow(Maat::GetDecision).to receive(:new).and_return(mock_get_decision) @@ -51,7 +48,7 @@ end context 'when nothing has changed on MAAT details are missing' do - let(:v2) { maat_decision } + let(:v2) { Maat::Decision.new(**maat_decision.attributes) } it 'instructs the caseworker to make changes on MAAT' do expect(page).to have_notification_banner( @@ -68,21 +65,7 @@ context 'when changed on MAAT with missing details provided' do let(:v2) do - Maat::Decision.new( - maat_id: 999_333, - reference: 6_000_001, - interests_of_justice: { - result: 'pass', - assessed_by: 'Jo Bloggs', - assessed_on: 1.day.ago.to_s - }, - means: { - result: 'pass', - assessed_by: 'Jo Bloggs', - assessed_on: 1.day.ago.to_s - }, - funding_decision: 'granted' - ) + Maat::Decision.new(**maat_decision.attributes, funding_decision: 'GRANTED') end it 'instructs the caseworker to check the decision' do