Skip to content

Commit

Permalink
ProlongTokenWizard properly handles draft and submission event
Browse files Browse the repository at this point in the history
Deleted the listener to the reopen event. When the reopen event, it
means that the authorization_request is a draft and it should not update
the prolong_token_wizard to its "updates_requested" state.

On a reopening, with a submit event, if there is a prolong_token_wizard
expecting for update (ig. its status is "requires_update") then we
should update its status to "updates_requested".
  • Loading branch information
Un3x committed Nov 5, 2024
1 parent 42bc40d commit 6cb5ee1
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 81 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,22 @@ def call # rubocop:disable Metrics/AbcSize
create_or_update_contacts_with_roles
end

context.authorization_request.token.last_prolong_token_wizard.update!(status: 'updates_requested') if expecting_updates?

return if context.authorization_request.save

fail!('Authorization request not valid', 'error', context.authorization_request.errors.to_hash)
end

private

def expecting_updates?
context.reopening &&
%w[submit].include?(context.event) &&
context.authorization_request&.token&.last_prolong_token_wizard.present? &&
context.authorization_request.token.last_prolong_token_wizard.requires_update?
end

def set_reopening_event_flag
context.reopening = reopening_event?
end
Expand Down
19 changes: 0 additions & 19 deletions app/interactors/datapass_webhook/reopen_authorization_request.rb

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,37 @@
end
end

context 'when event is submit' do
let!(:event) { 'submit' }

context 'when there is no token wizard' do
it { is_expected.to be_a_success }

it 'doest not update the authorization request' do
expect {
subject
}.not_to change { authorization_request.reload.last_update.to_i }
end
end

context 'when there is a token wizard expecting updates' do
let!(:token) { create(:token, authorization_request: authorization_request) }
let!(:last_prolong_token_wizard) { create(:prolong_token_wizard, :requires_update, token:) }

it 'doest not update the authorization request' do
expect {
subject
}.not_to change { authorization_request.reload.last_update.to_i }
end

it 'updates the prolong_token_wizard status' do
expect {
subject
}.to change { authorization_request.token.last_prolong_token_wizard.status }
end
end
end

context 'when event is validate' do
let!(:event) { 'validate' }

Expand Down

This file was deleted.

0 comments on commit 6cb5ee1

Please sign in to comment.