Skip to content

Commit

Permalink
Fix: complete page expects decisions (#719)
Browse files Browse the repository at this point in the history
  • Loading branch information
EdwinKruglov authored Oct 8, 2024
1 parent adc42f8 commit 81d695a
Show file tree
Hide file tree
Showing 8 changed files with 54 additions and 4 deletions.
4 changes: 4 additions & 0 deletions app/aggregates/deciding/decision.rb
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,10 @@ def interests_of_justice
Types::InterestsOfJusticeDecision[@interests_of_justice]
end

def complete?
@funding_decision.present?
end

def attributes
{
interests_of_justice:,
Expand Down
1 change: 1 addition & 0 deletions app/aggregates/reviewing.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ class CannotMarkAsReadyWhenCompleted < Error; end
class CannotMarkAsReadyWhenSentBack < Error; end
class CannotSendBackWhenCompleted < Error; end
class NotReceived < Error; end
class IncompleteDecisions < Error; end

class DecisionAdded < Event; end

Expand Down
5 changes: 4 additions & 1 deletion app/aggregates/reviewing/commands/complete.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,12 @@ def call # rubocop:disable Metrics/MethodLength
review.complete(user_id:)

decisions = review.decision_ids.map do |decision_id|
Deciding::LoadDecision.call(
decision = Deciding::LoadDecision.call(
application_id:, decision_id:
)
raise IncompleteDecisions unless decision.complete?

decision.attributes
end

DatastoreApi::Requests::UpdateApplication.new(
Expand Down
4 changes: 2 additions & 2 deletions app/controllers/casework/completes_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@ class CompletesController < Casework::BaseController

def show; end

def create # rubocop:disable Metrics/MethodLength
def create # rubocop:disable Metrics/MethodLength, Metrics/AbcSize
Reviewing::Complete.new(
application_id: @crime_application.id,
user_id: current_user_id
).call

if FeatureFlags.adding_decisions.enabled?
if FeatureFlags.adding_decisions.enabled? && @crime_application.draft_decisions.any?
redirect_to crime_application_complete_path(@crime_application)
else
set_flash :completed
Expand Down
1 change: 1 addition & 0 deletions config/locales/en/casework.yml
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ en:
not_allocated_to_appropriate_work_stream:
- You must be allocated to the %{work_queue} work queue to review this application
- Contact your supervisor to arrange this
incomplete_decisions: Please complete any pending funding decisions


primary_navigation:
Expand Down
2 changes: 1 addition & 1 deletion config/settings.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ feature_flags:
production: true
adding_decisions:
local: false
staging: true
staging: false
production: false
other_charges:
local: true
Expand Down
22 changes: 22 additions & 0 deletions spec/aggregates/deciding/decision_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,26 @@
expect(decision.attributes[:comment]).to eq(comment)
end
end

describe '#complete?' do
context 'when funding_decision is present' do
let(:funding_decision) { 'granted' }

before do
decision.set_funding_decision(user_id: SecureRandom.uuid, funding_decision: funding_decision)
end

it 'returns true' do
expect(decision.complete?).to be(true)
end
end

context 'when funding_decision is not present' do
let(:funding_decision) { nil }

it 'returns false' do
expect(decision.complete?).to be(false)
end
end
end
end
19 changes: 19 additions & 0 deletions spec/aggregates/reviewing/complete_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -37,4 +37,23 @@
expect { command.call }.to change { review.state }
.from(:open).to(:completed)
end

context 'when there are incomplete decisions' do
before do
args = {
application_id: application_id,
user_id: SecureRandom.uuid,
decision_id: SecureRandom.uuid
}

Reviewing::AddDecision.call(**args)
Deciding::CreateDraft.call(**args)
end

it 'throws an error' do
expect do
command.call
end.to raise_error(Reviewing::IncompleteDecisions)
end
end
end

0 comments on commit 81d695a

Please sign in to comment.