delete_spec.rb 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. # Copyright (C) 2012-2024 Zammad Foundation, https://zammad-foundation.org/
  2. require 'rails_helper'
  3. RSpec.describe Gql::Mutations::OnlineNotification::Delete, authenticated_as: :user, type: :graphql do
  4. let(:user) { create(:agent) }
  5. let(:notification) { create(:online_notification, user: user) }
  6. let(:another_user_notification) { create(:online_notification, user: create(:user)) }
  7. let(:query) do
  8. <<~QUERY
  9. mutation onlineNotificationDelete($onlineNotificationId: ID!) {
  10. onlineNotificationDelete(onlineNotificationId: $onlineNotificationId) {
  11. success
  12. }
  13. }
  14. QUERY
  15. end
  16. let(:variables) { { onlineNotificationId: notification_to_delete.to_gid_param } }
  17. before do
  18. gql.execute(query, variables: variables)
  19. end
  20. context 'when deleting a notification' do
  21. let(:notification_to_delete) { notification }
  22. it 'deletes notification' do
  23. expect(notification.class).not_to exist(notification.id)
  24. end
  25. end
  26. context 'when deleting inaccessible notification' do
  27. let(:notification_to_delete) { another_user_notification }
  28. it 'does not delete notification' do
  29. expect(notification.class).to exist(notification.id)
  30. end
  31. end
  32. end