remove_method_spec.rb 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. # Copyright (C) 2012-2024 Zammad Foundation, https://zammad-foundation.org/
  2. require 'rails_helper'
  3. RSpec.describe Service::User::TwoFactor::RemoveMethod do
  4. subject(:service) { described_class.new(user:, method_name:) }
  5. let(:user) { create(:agent) }
  6. context 'when the given method exists' do
  7. let(:method_name) { 'authenticator_app' }
  8. context 'when user has given method configured' do
  9. let(:preference) { create(:user_two_factor_preference, :authenticator_app, user:) }
  10. before { preference }
  11. it 'removes the given method' do
  12. expect { service.execute }
  13. .to change { preference.class.exists?(preference.id) }
  14. .to be_falsey
  15. end
  16. end
  17. context 'when user does not have given method configured' do
  18. it 'does not raise error' do
  19. expect { service.execute }.not_to raise_error
  20. end
  21. end
  22. end
  23. context 'when the given method does not exist' do
  24. let(:method_name) { 'nonsense' }
  25. it 'raises error' do
  26. expect { service.execute }.to raise_error(Exceptions::UnprocessableEntity)
  27. end
  28. end
  29. end