Skip to content

Commit

Permalink
change validation and do not destroy declarations
Browse files Browse the repository at this point in the history
  • Loading branch information
alkesh committed Jan 22, 2025
1 parent 908f332 commit fbf930c
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 13 deletions.
5 changes: 2 additions & 3 deletions app/services/applications/revert_to_pending.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module Applications
class RevertToPending
REMOVEABLE_DECLARATION_STATES = %w[submitted voided ineligible].freeze
REVERTABLE_DECLARATION_STATES = %w[voided ineligible awaiting_clawback clawed_back].freeze

include ActiveModel::Model
include ActiveModel::Attributes
Expand All @@ -20,7 +20,6 @@ def revert

Application.transaction do
application.application_states.destroy_all
application.declarations.destroy_all
application.funded_place = nil
application.pending_lead_provider_approval_status!

Expand All @@ -31,7 +30,7 @@ def revert
private

def application_has_no_unremoveable_declarations
if application.declarations.where.not(state: REMOVEABLE_DECLARATION_STATES).any?
if application.declarations.where.not(state: REVERTABLE_DECLARATION_STATES).any?
errors.add :base, :pending_unremoveable_declarations
end
end
Expand Down
16 changes: 8 additions & 8 deletions spec/services/applications/revert_to_pending_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@
context "when status set to no" do
let :application do
create(:application, :accepted, funded_place: true).tap do |application|
create(:declaration, :submitted, application:)
create(:declaration, :voided, application:)
create(:application_state, application:)
end
end
Expand Down Expand Up @@ -115,7 +115,7 @@
context "when already pending" do
let :application do
create(:application, :pending, funded_place: true).tap do |application|
create(:declaration, :submitted, application:)
create(:declaration, :voided, application:)
create(:application_state, application:)
end
end
Expand All @@ -141,9 +141,9 @@
end
end

context "when Application already has declarations" do
%i[submitted voided ineligible].each do |declaration_state|
context "with #{declaration_state} state" do
context "when application already has declarations" do
%i[voided ineligible awaiting_clawback clawed_back].each do |declaration_state|
context "with a revertable state: #{declaration_state}" do
let(:application) { create(:declaration, declaration_state).application }

it "returns true" do
Expand All @@ -155,13 +155,13 @@
.to change { application.reload.lead_provider_approval_status }
.from("accepted")
.to("pending")
.and change { application.declarations.count }.to(0)
.and(not_change { application.declarations.count })
end
end
end

%i[eligible payable paid awaiting_clawback clawed_back].each do |declaration_state|
context "with #{declaration_state} state" do
Declaration.states.keys.excluding(%w[voided ineligible awaiting_clawback clawed_back]).each do |declaration_state|
context "with a state that cannot be reverted: #{declaration_state}" do
let(:application) { create(:declaration, declaration_state).application }

it "returns false" do
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
it_behaves_like "changes to pending", "rejected"
end

%i[submitted voided ineligible].each do |state|
Applications::RevertToPending::REVERTABLE_DECLARATION_STATES.each do |state|
context "when the application has #{state} declarations" do
let(:declaration) { create(:declaration, state) }

Expand Down Expand Up @@ -75,7 +75,7 @@
it { expect(run[application_ecf_id]).to eq("Not found") }
end

Declaration.states.keys.excluding("submitted", "voided", "ineligible").each do |state|
Declaration.states.keys.excluding(Applications::RevertToPending::REVERTABLE_DECLARATION_STATES).each do |state|
context "when the application has #{state} declarations" do
let(:declaration) { create(:declaration, state) }
let(:application) { declaration.application }
Expand Down

0 comments on commit fbf930c

Please sign in to comment.