Skip to content

Commit

Permalink
Merge pull request #9877 from DFE-Digital/pr3-2315-remove-default-by-…
Browse files Browse the repository at this point in the history
…default-at-column

[2315] part 3, Ignore redundant decline_by_default columns
  • Loading branch information
elceebee authored Oct 3, 2024
2 parents dea9864 + 92174ae commit 84fbee2
Show file tree
Hide file tree
Showing 13 changed files with 50 additions and 135 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,6 @@ def offer_count
@application_form.application_choices.offer.count
end

def decline_by_default_at
@application_form.application_choices.offer.map(&:decline_by_default_at).min || Time.zone.now
end

def days_left_to_respond
duration_in_days = (decline_by_default_date.to_date - Date.current).to_i
[0, duration_in_days].max
Expand Down
2 changes: 2 additions & 0 deletions app/models/application_choice.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ class ApplicationChoice < ApplicationRecord
include Chased
include TouchApplicationFormState

self.ignored_columns += %w[decline_by_default_at decline_by_default_days]

before_create :set_initial_status

belongs_to :application_form, touch: true
Expand Down
49 changes: 25 additions & 24 deletions app/services/candidate_interface/sort_application_choices.rb
Original file line number Diff line number Diff line change
@@ -1,30 +1,31 @@
module CandidateInterface
class SortApplicationChoices
def self.call(application_choices:)
scope = application_choices.from <<~WITH_GROUP.squish
(
SELECT application.*,
CASE
WHEN (status IN ('offer')) THEN 'offers_received'
WHEN (status IN ('unsubmitted', 'application_not_sent', 'cancelled')) THEN 'draft'
WHEN (status IN ('rejected', 'conditions_not_met')) THEN 'unsuccessful'
WHEN (status IN ('interviewing', 'inactive', 'awaiting_provider_decision')) THEN 'in_progress'
WHEN (status IN ('offer_withdrawn', 'withdrawn')) THEN 'withdrawn'
WHEN (status IN ('declined')) THEN 'declined'
ELSE ''
END AS application_choices_group_name,
CASE
WHEN (status IN ('offer')) THEN 1
WHEN (status IN ('unsubmitted', 'application_not_sent', 'cancelled')) THEN 2
WHEN (status IN ('rejected', 'conditions_not_met')) THEN 3
WHEN (status IN ('interviewing', 'inactive', 'awaiting_provider_decision')) THEN 4
WHEN (status IN ('offer_withdrawn', 'withdrawn')) THEN 5
WHEN (status IN ('declined')) THEN 6
ELSE 10
END AS application_choices_group_number
FROM application_choices application
) AS application_choices
WITH_GROUP
# Explicitly list the columns so that the 'ignored_columns' on the model are not included in the raw SQL.
columns = ApplicationChoice.new.attribute_names.map { |key| "application_choices.#{key}" }.join(', ')

scope = application_choices.select(
"#{columns},
CASE
WHEN status IN ('offer') THEN 'offers_received'
WHEN status IN ('unsubmitted', 'application_not_sent', 'cancelled') THEN 'draft'
WHEN status IN ('rejected', 'conditions_not_met') THEN 'unsuccessful'
WHEN status IN ('interviewing', 'inactive', 'awaiting_provider_decision') THEN 'in_progress'
WHEN status IN ('offer_withdrawn', 'withdrawn') THEN 'withdrawn'
WHEN status IN ('declined') THEN 'declined'
ELSE ''
END AS application_choices_group_name,
CASE
WHEN status IN ('offer') THEN 1
WHEN status IN ('unsubmitted', 'application_not_sent', 'cancelled') THEN 2
WHEN status IN ('rejected', 'conditions_not_met') THEN 3
WHEN status IN ('interviewing', 'inactive', 'awaiting_provider_decision') THEN 4
WHEN status IN ('offer_withdrawn', 'withdrawn') THEN 5
WHEN status IN ('declined') THEN 6
ELSE 10
END AS application_choices_group_number",
)

scope.order('application_choices_group_number ASC, application_choices.sent_to_provider_at DESC')
end
end
Expand Down

This file was deleted.

37 changes: 18 additions & 19 deletions app/services/provider_interface/sort_application_choices.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,26 +9,25 @@ def self.call(application_choices:)
end

def self.for_task_view(application_choices)
application_choices.from <<~WITH_TASK_VIEW_GROUP.squish
(
SELECT a.*,
CASE
WHEN #{inactive} THEN 1
WHEN #{awaiting_provider_decision} THEN 2
WHEN #{deferred_offers_pending_reconfirmation} THEN 3
WHEN #{give_feedback_for_rbd} THEN 4
WHEN #{interviewing} THEN 5
WHEN #{pending_conditions_previous_cycle} THEN 6
WHEN #{waiting_on_candidate} THEN 7
WHEN #{pending_conditions_current_cycle} THEN 8
WHEN #{successful_candidates} THEN 9
WHEN #{deferred_offers_current_cycle} THEN 10
ELSE 999
END AS task_view_group
# Explicitly list the columns so that the 'ignored_columns' on the model are not included in the raw SQL.
columns = ApplicationChoice.new.attribute_names.map { |key| "application_choices.#{key}" }.join(', ')

FROM application_choices a
) AS application_choices
WITH_TASK_VIEW_GROUP
application_choices.select(
"#{columns},
CASE
WHEN #{inactive} THEN 1
WHEN #{awaiting_provider_decision} THEN 2
WHEN #{deferred_offers_pending_reconfirmation} THEN 3
WHEN #{give_feedback_for_rbd} THEN 4
WHEN #{interviewing} THEN 5
WHEN #{pending_conditions_previous_cycle} THEN 6
WHEN #{waiting_on_candidate} THEN 7
WHEN #{pending_conditions_current_cycle} THEN 8
WHEN #{successful_candidates} THEN 9
WHEN #{deferred_offers_current_cycle} THEN 10
ELSE 999
END AS task_view_group",
)
end

def self.deferred_offers_pending_reconfirmation
Expand Down
2 changes: 0 additions & 2 deletions config/analytics.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@ shared:
- original_course_option_id
- course_option_id
- current_course_option_id
- decline_by_default_at
- decline_by_default_days
- declined_at
- declined_by_default
- id
Expand Down
2 changes: 2 additions & 0 deletions config/analytics_blocklist.yml
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,8 @@
:application_choices:
- provider_ids
- current_recruitment_cycle_year
- decline_by_default_at
- decline_by_default_days
:site_settings:
- id
- name
Expand Down
1 change: 0 additions & 1 deletion lib/tasks/data.rake
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
DATA_MIGRATION_SERVICES = [
# do not delete or edit this line - services added below by generator
'DataMigrations::SetDeclineByDefaultAtAndDeclineByDefaultDaysToNil',
'DataMigrations::BackfillApplicationChoicesWithWorkExperiences',
'DataMigrations::MarkUnsubmittedApplicationsWithoutEnglishProficiencyAsElfIncomplete',
'DataMigrations::BackfillEnglishProficiencyRecordsForCarriedOverApplications',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ def create_application_form_with_course_choices(statuses:, apply_again: false)
:application_choice,
application_form:,
status:,
decline_by_default_at: status == 'offer' ? 10.days.from_now : nil,
)
end

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@
status: 'offer',
declined_at: nil,
declined_by_default: false,
decline_by_default_at: nil,
})

expect(course_choice.audits.last.comment).to include(zendesk_ticket)
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -103,8 +103,8 @@

it 'according to their task_view_group, rbd and updated_at' do
expected = application_choices.map(&:id)
actual = described_class.call(application_choices: ApplicationChoice.all).pluck(:id)
expect(actual.to_a).to eq(expected)
actual = described_class.call(application_choices: ApplicationChoice.all).map(&:id)
expect(actual).to eq(expected)
end
end
end
5 changes: 1 addition & 4 deletions spec/services/reinstate_declined_offer_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,21 +20,18 @@
application_form = create(:completed_application_form)

declined_course_choice = create(:application_choice, :declined, application_form:)
offered_course_choice = create(:application_choice, :offered, application_form:)
create(:application_choice, :offered, application_form:)
course_choice_awaiting_decision = create(:application_choice, status: :awaiting_provider_decision, application_form:)

described_class.new(course_choice: declined_course_choice, zendesk_ticket:).save!

expect(declined_course_choice).to have_attributes({
status: 'offer',
declined_at: nil,
decline_by_default_at: nil,
})

expect(declined_course_choice.audits.last.comment).to eq "Reinstate offer Zendesk request: #{zendesk_ticket}"

expect(offered_course_choice.reload.decline_by_default_at).to be_nil

expect(course_choice_awaiting_decision.reload).to eq course_choice_awaiting_decision
end
end
Expand Down

0 comments on commit 84fbee2

Please sign in to comment.