Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fixup! Update request base calculated status
Browse files Browse the repository at this point in the history
gbp committed Oct 27, 2023
1 parent 82fce05 commit c7c54e5
Showing 5 changed files with 67 additions and 24 deletions.
7 changes: 2 additions & 5 deletions app/models/info_request.rb
Original file line number Diff line number Diff line change
@@ -757,7 +757,7 @@ def must_be_internal_or_external
end
end

def internally_reviewed?
def internal_review_requested?
outgoing_messages.where(what_doing: 'internal_review').any?
end

@@ -1043,10 +1043,7 @@ def calculate_status(cached_value_ok=false)
end

def base_calculate_status
if awaiting_description
return 'internal_review' if internally_reviewed?
return 'waiting_classification'
end
return 'waiting_classification' if awaiting_description
return described_state unless described_state == "waiting_response"
# Compare by date, so only overdue on next day, not if 1 second late
return 'waiting_response_very_overdue' if
13 changes: 10 additions & 3 deletions app/models/info_request/state/calculator.rb
Original file line number Diff line number Diff line change
@@ -93,7 +93,10 @@ def transitions(opts = {})
other: {}
}
end
opts.merge!(in_internal_review: state == 'internal_review')
opts.merge!(
in_internal_review: state == 'internal_review',
internal_review_requested: @info_request.internal_review_requested?
)
build_transitions_hash(opts)
end

@@ -132,7 +135,11 @@ def pending_states(opts)
if opts.fetch(:in_internal_review, false)
states = %w[internal_review gone_postal]
else
states = %w[
states = []
if opts.fetch(:internal_review_requested, false)
states += ['internal_review']
end
states += %w[
waiting_response
waiting_clarification
gone_postal
@@ -141,7 +148,7 @@ def pending_states(opts)
states += ['internal_review']
end
end
states
states.uniq
end

def complete_states(_opts = {})
6 changes: 4 additions & 2 deletions app/models/info_request/state/transitions.rb
Original file line number Diff line number Diff line change
@@ -86,7 +86,8 @@ def self.owner_gone_postal_transition_label(_opts = {})
end

def self.owner_internal_review_transition_label(opts = {})
if opts.fetch(:in_internal_review, false)
if opts.fetch(:in_internal_review, false) ||
opts.fetch(:internal_review_requested, false)
_("I'm still <strong>waiting</strong> for the internal review")
else
_("I'm waiting for an <strong>internal review</strong> response")
@@ -139,7 +140,8 @@ def self.other_user_gone_postal_transition_label(_opts = {})
end

def self.other_user_internal_review_transition_label(opts = {})
if opts.fetch(:in_internal_review, false)
if opts.fetch(:in_internal_review, false) ||
opts.fetch(:internal_review_requested, false)
_("Still awaiting an <strong>internal review</strong>")
else
# To match what would happen if this method didn't exist, because
61 changes: 49 additions & 12 deletions spec/models/info_request/state/calculator_spec.rb
Original file line number Diff line number Diff line change
@@ -195,7 +195,11 @@
end
end

shared_examples 'internal_review' do
context "when the request is in internal_review" do
before :each do
info_request.set_described_state("internal_review")
end

context "and the user is the owner" do
it "returns only two pending states" do
transitions = calculator.transitions(
@@ -233,23 +237,56 @@
end
end

context "when the request is in internal_review" do
before :each do
info_request.set_described_state("internal_review")
end

include_examples 'internal_review'
end

context "when the request was in internal_review" do
context "when the request received a response after being in internal_review" do
let(:info_request) do
FactoryBot.create(
:info_request, :with_internal_review_request,
awaiting_description: true, described_state: 'waiting_response'
described_state: 'waiting_response'
)
end

include_examples 'internal_review'
before do
mail = Mail.new
mail.to info_request.incoming_email
mail.body 'Internal review reply'
info_request.receive(mail, mail.to_s)
end

context "and the user is the owner" do
it "returns only two pending states" do
transitions = calculator.transitions(
is_owning_user: true,
user_asked_to_update_status: false)
expected = %w[internal_review waiting_response waiting_clarification gone_postal]
expect(transitions[:pending].keys).to eq(expected)
end

it "returns a different label for the internal_review status" do
transitions = calculator.transitions(
is_owning_user: true,
user_asked_to_update_status: false)
expected = "I'm still <strong>waiting</strong> for the internal review"
expect(transitions[:pending]["internal_review"]).to eq expected
end
end

context "and the user is some other user" do
it "returns only two pending states" do
transitions = calculator.transitions(
is_owning_user: false,
user_asked_to_update_status: false)
expected = %w[internal_review waiting_response waiting_clarification gone_postal]
expect(transitions[:pending].keys).to eq(expected)
end

it "returns a different label for the internal_review status" do
transitions = calculator.transitions(
is_owning_user: false,
user_asked_to_update_status: false)
expected = "Still awaiting an <strong>internal review</strong>"
expect(transitions[:pending]["internal_review"]).to eq expected
end
end
end

context "when the request is in an 'other' state" do
4 changes: 2 additions & 2 deletions spec/models/info_request_spec.rb
Original file line number Diff line number Diff line change
@@ -1631,8 +1631,8 @@
end
end

describe '#internally_reviewed?' do
subject { info_request.internally_reviewed? }
describe '#internal_review_requested?' do
subject { info_request.internal_review_requested? }

context 'when internal review has been sent' do
let(:info_request) do

0 comments on commit c7c54e5

Please sign in to comment.