delete_spec.rb 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. # Copyright (C) 2012-2024 Zammad Foundation, https://zammad-foundation.org/
  2. require 'rails_helper'
  3. RSpec.describe Gql::Mutations::User::Current::TaskbarItem::Delete, type: :graphql do
  4. context 'when deleting a taskbar item for the logged-in user', authenticated_as: :agent do
  5. let(:agent) { create(:agent) }
  6. let(:variables) { { id: gql.id(taskbar_item) } }
  7. let(:execute_query) { true }
  8. let(:taskbar_item) { create(:taskbar, user_id: agent.id) }
  9. let(:query) do
  10. <<~QUERY
  11. mutation userCurrentTaskbarItemDelete($id: ID!) {
  12. userCurrentTaskbarItemDelete(id: $id) {
  13. success
  14. errors {
  15. message
  16. field
  17. }
  18. }
  19. }
  20. QUERY
  21. end
  22. before do
  23. next if !execute_query
  24. gql.execute(query, variables: variables)
  25. end
  26. context 'with existing taskbar item' do
  27. it 'returns success' do
  28. expect(gql.result.data[:success]).to be true
  29. end
  30. it 'does not find the taskbar item anymore' do
  31. expect { Taskbar.find(taskbar_item.id) }.to raise_error(ActiveRecord::RecordNotFound)
  32. end
  33. end
  34. context 'with not existing taskbar item', :aggregate_failures do
  35. let(:variables) do
  36. { id: Gql::ZammadSchema.id_from_internal_id(Taskbar, Faker::Number.unique.number) }
  37. end
  38. it 'fails with error' do
  39. expect(gql.result.error_type).to eq(ActiveRecord::RecordNotFound)
  40. end
  41. end
  42. it_behaves_like 'graphql responds with error if unauthenticated'
  43. end
  44. end