Skip to content
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

[#3830] Update request base calculated status #7378

Merged
merged 1 commit into from
Nov 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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"

Check warning on line 271 in spec/models/info_request/state/calculator_spec.rb

View workflow job for this annotation

GitHub Actions / build

[rubocop] reported by reviewdog 🐶 Line is too long. [81/80] (https://rubystyle.guide#max-line-length) Raw Output: spec/models/info_request/state/calculator_spec.rb:271:81: C: Layout/LineLength: Line is too long. [81/80] (https://rubystyle.guide#max-line-length)
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