-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
CRIMAPP-1597 Store overall result as a type
- Loading branch information
Showing
14 changed files
with
194 additions
and
44 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
module Deciding | ||
class OverallResultCalculator | ||
def initialize(decision) | ||
@decision = decision | ||
end | ||
|
||
def calculate | ||
return unless funding_decision | ||
|
||
Types::OverallResult[ | ||
[funding_decision, qualification].compact.join('_') | ||
] | ||
end | ||
|
||
private | ||
|
||
attr_reader :decision | ||
|
||
def qualification | ||
return refusal_qualification if refused? | ||
|
||
grant_qualification if granted? | ||
end | ||
|
||
def refusal_qualification | ||
return 'failed_ioj_and_means' if failed_means? && failed_ioj? | ||
return 'failed_ioj' if failed_ioj? | ||
|
||
'failed_means' if failed_means? | ||
end | ||
|
||
def grant_qualification | ||
return 'failed_means' if failed_means? | ||
|
||
'with_contribution' if with_contribution? | ||
end | ||
|
||
delegate :funding_decision, to: :decision | ||
|
||
def failed_means? | ||
decision.means&.result == 'failed' | ||
end | ||
|
||
def granted? | ||
funding_decision == 'granted' | ||
end | ||
|
||
def refused? | ||
funding_decision == 'refused' | ||
end | ||
|
||
def with_contribution? | ||
decision.means&.result == 'passed_with_contribution' | ||
end | ||
|
||
def failed_ioj? | ||
decision.interests_of_justice&.result == 'failed' | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
79 changes: 79 additions & 0 deletions
79
spec/aggregates/deciding/overall_result_calculator_spec.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
require 'rails_helper' | ||
|
||
RSpec.describe Deciding::OverallResultCalculator do | ||
describe '#calculate' do | ||
subject do | ||
described_class.new(decision).calculate | ||
end | ||
|
||
let(:decision) do | ||
instance_double( | ||
LaaCrimeSchemas::Structs::Decision, | ||
means: instance_double( | ||
LaaCrimeSchemas::Structs::TestResult, result: means_result | ||
), | ||
funding_decision: funding_decision, | ||
interests_of_justice: instance_double( | ||
LaaCrimeSchemas::Structs::TestResult, result: ioj_result | ||
) | ||
) | ||
end | ||
|
||
context 'when funding is granted' do | ||
let(:funding_decision) { 'granted' } | ||
|
||
context 'when means test is failed' do | ||
let(:ioj_result) { 'passed' } | ||
let(:means_result) { 'failed' } | ||
|
||
it { is_expected.to eq('granted_failed_means') } | ||
end | ||
|
||
context 'when means test passed with contribution' do | ||
let(:ioj_result) { 'passed' } | ||
let(:means_result) { 'passed_with_contribution' } | ||
|
||
it { is_expected.to eq('granted_with_contribution') } | ||
end | ||
|
||
context 'when means test fully passed' do | ||
let(:ioj_result) { 'passed' } | ||
let(:means_result) { 'passed' } | ||
|
||
it { is_expected.to eq('granted') } | ||
end | ||
end | ||
|
||
context 'when funding is refused' do | ||
let(:funding_decision) { 'refused' } | ||
|
||
context 'when both means and IoJ tests failed' do | ||
let(:ioj_result) { 'failed' } | ||
let(:means_result) { 'failed' } | ||
|
||
it { is_expected.to eq('refused_failed_ioj_and_means') } | ||
end | ||
|
||
context 'when only IoJ test failed' do | ||
let(:ioj_result) { 'failed' } | ||
let(:means_result) { 'passed' } | ||
|
||
it { is_expected.to eq('refused_failed_ioj') } | ||
end | ||
|
||
context 'when only means test failed' do | ||
let(:ioj_result) { 'passed' } | ||
let(:means_result) { 'failed' } | ||
|
||
it { is_expected.to eq('refused_failed_means') } | ||
end | ||
|
||
context 'when neither test failed' do | ||
let(:ioj_result) { 'passed' } | ||
let(:means_result) { 'passed' } | ||
|
||
it { is_expected.to eq('refused') } | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters