Skip to content

Commit

Permalink
Merge pull request #8638 from DFE-Digital/732-apply-candidates-incorr…
Browse files Browse the repository at this point in the history
…ectly-able-to-enter-apply-again-status

Fix apply again bug on continuous applications
  • Loading branch information
tomas-stefano authored Oct 6, 2023
2 parents 003dd90 + c67e2b2 commit b528565
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 1 deletion.
2 changes: 1 addition & 1 deletion app/models/application_form.rb
Original file line number Diff line number Diff line change
Expand Up @@ -321,7 +321,7 @@ def successful?

def any_offer_accepted?
application_choices.present? &&
application_choices.map(&:status).map(&:to_sym).any? { |status| ApplicationStateChange::ACCEPTED_STATES.include?(status) }
application_choices.map(&:status).map(&:to_sym).any? { |status| (ApplicationStateChange::ACCEPTED_STATES - [:conditions_not_met]).include?(status) }
end

def ended_without_success?
Expand Down
8 changes: 8 additions & 0 deletions spec/models/application_form_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -792,6 +792,14 @@ def application_form_with_course_option_for_provider_with(level:)
expect(application_form.any_offer_accepted?).to be(false)
end

it 'returns false if there is no accepted offer and there is conditions not met on any of the application choices' do
offer_choice = create(:application_choice, :offered)
other_choice = create(:application_choice, :withdrawn)
another_choice = create(:application_choice, :conditions_not_met)
application_form = create(:completed_application_form, application_choices: [offer_choice, other_choice, another_choice])
expect(application_form.any_offer_accepted?).to be(false)
end

it 'returns true if there is an application choice with an accepted offer' do
accepted_offer_choice = create(:application_choice, :accepted)
other_choice = create(:application_choice, :rejected)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
require 'rails_helper'

RSpec.feature 'Redirects away from complete page', :continuous_applications do
include CandidateHelper

scenario 'Candidate with an application' do
ApplicationChoice.statuses.each_value do |status|
@status = status
@candidate = create(:candidate)

given_i_am_signed_in
and_i_have_an_application_choice
when_i_visit_the_complete_page
then_i_should_be_redirected_away_from_complete_page
end
end

def given_i_am_signed_in
create_and_sign_in_candidate(candidate: @candidate)
end

def and_i_have_an_application_choice
application_form = create(:application_form, candidate: @candidate)
create(:application_choice, @status, application_form:)
end

def when_i_visit_the_complete_page
visit candidate_interface_application_complete_path
end

def then_i_should_be_redirected_away_from_complete_page
expect(page).to have_current_path(expected_path)
end

def expected_path
case @status.to_sym
when :unsubmitted, :cancelled, :awaiting_provider_decision, :inactive, :interviewing, :application_not_sent, :offer_withdrawn, :declined, :withdrawn, :conditions_not_met, :offer, :rejected
candidate_interface_continuous_applications_details_path
when :pending_conditions, :offer_deferred, :recruited
candidate_interface_application_offer_dashboard_path
end
end
end

0 comments on commit b528565

Please sign in to comment.