notification_preferences_reset_spec.rb 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. # Copyright (C) 2012-2024 Zammad Foundation, https://zammad-foundation.org/
  2. require 'rails_helper'
  3. RSpec.describe Gql::Mutations::User::Current::NotificationPreferencesReset, :aggregate_failures, type: :graphql do
  4. let(:user) { create(:agent) }
  5. let(:mutation) do
  6. <<~GQL
  7. mutation userCurrentNotificationPreferencesReset {
  8. userCurrentNotificationPreferencesReset {
  9. user {
  10. personalSettings {
  11. notificationSound {
  12. enabled
  13. file
  14. }
  15. }
  16. }
  17. }
  18. }
  19. GQL
  20. end
  21. def execute_graphql_query
  22. gql.execute(mutation)
  23. end
  24. context 'when user is not authenticated' do
  25. it 'returns an error' do
  26. expect(execute_graphql_query.error_message).to eq('Authentication required')
  27. end
  28. end
  29. context 'when user is authenticated', authenticated_as: :user do
  30. context 'without sufficient permissions', authenticated_as: :user do
  31. let(:user) do
  32. create(:agent).tap do |user|
  33. user.roles.each { |role| role.permission_revoke('user_preferences') }
  34. end
  35. end
  36. it 'returns an error' do
  37. expect(execute_graphql_query.error_type).to eq(Exceptions::Forbidden)
  38. end
  39. end
  40. context 'with sufficient permissions' do
  41. before do
  42. allow(User).to receive(:reset_notifications_preferences!)
  43. end
  44. it 'resets user preferences' do
  45. execute_graphql_query
  46. expect(gql.result.data['notificationSound']).to be_nil
  47. expect(User).to have_received(:reset_notifications_preferences!).with(user)
  48. end
  49. end
  50. end
  51. end