Skip to content

Commit

Permalink
Merge branch '3830-update-status-internal-review' into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
gbp committed Nov 20, 2023
2 parents dc76af0 + 08d04f0 commit 008009b
Show file tree
Hide file tree
Showing 6 changed files with 93 additions and 5 deletions.
4 changes: 4 additions & 0 deletions app/models/info_request.rb
Original file line number Diff line number Diff line change
Expand Up @@ -758,6 +758,10 @@ def must_be_internal_or_external
end
end

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

def is_external?
external_url.nil? ? false : true
end
Expand Down
12 changes: 9 additions & 3 deletions app/models/info_request/state/calculator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,9 @@ def transitions(opts = {})
other: {}
}
end
opts.merge!(in_internal_review: state == 'internal_review')
opts[:in_internal_review] = state == 'internal_review'
opts[:internal_review_requested] =
@info_request.internal_review_requested?
build_transitions_hash(opts)
end

Expand Down Expand Up @@ -132,7 +134,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
Expand All @@ -141,7 +147,7 @@ def pending_states(opts)
states += ['internal_review']
end
end
states
states.uniq
end

def complete_states(_opts = {})
Expand Down
6 changes: 4 additions & 2 deletions app/models/info_request/state/transitions.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions doc/CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

## Highlighted Features

* Update request base calculated status for internal reviews (Graeme Porteous)
* Automatically apply `not_many_requests` tag to bodies who don't have many
public requests so that they can be found in a public list or have tag-based
notes applied (Gareth Rees)
Expand Down
58 changes: 58 additions & 0 deletions spec/models/info_request/state/calculator_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,64 @@
end
end

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,
described_state: 'waiting_response'
)
end

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 all pending states with internal_review first" 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 all pending states with internal_review first" 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
context "and the user is the owner" do
it_behaves_like(
Expand Down
17 changes: 17 additions & 0 deletions spec/models/info_request_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1631,6 +1631,23 @@
end
end

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

context 'when internal review has been sent' do
let(:info_request) do
FactoryBot.create(:info_request, :with_internal_review_request)
end

it { is_expected.to eq true }
end

context 'when internal review has not been sent' do
let(:info_request) { FactoryBot.create(:info_request) }
it { is_expected.to eq false }
end
end

describe '#is_external?' do

it 'returns true if there is an external url' do
Expand Down

0 comments on commit 008009b

Please sign in to comment.