remove_linked_account_spec.rb 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. # Copyright (C) 2012-2024 Zammad Foundation, https://zammad-foundation.org/
  2. require 'rails_helper'
  3. RSpec.describe Gql::Mutations::User::Current::RemoveLinkedAccount, type: :graphql do
  4. let(:user) { create(:agent) }
  5. let(:authorization) { create(:twitter_authorization, user: user) }
  6. let(:provider) { authorization.provider }
  7. let(:uid) { authorization.uid }
  8. let(:mutation) do
  9. <<~GQL
  10. mutation userCurrentRemoveLinkedAccount($provider: EnumAuthenticationProvider!, $uid: String!) {
  11. userCurrentRemoveLinkedAccount(provider: $provider, uid: $uid) {
  12. success
  13. }
  14. }
  15. GQL
  16. end
  17. let(:variables) { { provider:, uid: } }
  18. before do
  19. gql.execute(mutation, variables: variables)
  20. end
  21. context 'when user is authenticated', authenticated_as: :user do
  22. context 'with a valid authorization' do
  23. it 'removes the linked account' do
  24. expect { authorization.reload }.to raise_error(ActiveRecord::RecordNotFound)
  25. end
  26. end
  27. context 'without required permission' do
  28. let(:user) do
  29. create(:agent).tap do |user|
  30. user.roles.each { |role| role.permission_revoke('user_preferences') }
  31. end
  32. end
  33. it 'raises an error' do
  34. expect(gql.result.error_type).to eq(Exceptions::Forbidden)
  35. end
  36. end
  37. context 'without a valid authorization' do
  38. let(:uid) { 'invalid-uid' }
  39. it 'raises an error' do
  40. expect(gql.result.error_type).to eq(Exceptions::UnprocessableEntity)
  41. end
  42. end
  43. end
  44. it_behaves_like 'graphql responds with error if unauthenticated'
  45. end