-
Notifications
You must be signed in to change notification settings - Fork 0
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
CRIMAPP-1597 store overall_result type rather than string #805
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
module Deciding | ||
class OverallResultCalculator | ||
def initialize(decision) | ||
@decision = decision | ||
end | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The overall result is now displayed to the user in the format In the datastore, these values are stored as types, such as This class determines the |
||
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 |
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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
☝️ removes redundant code. The overall result is now calculated in the same way across all application types.