update_spec.rb 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. # Copyright (C) 2012-2024 Zammad Foundation, https://zammad-foundation.org/
  2. require 'rails_helper'
  3. RSpec.describe Gql::Mutations::User::Current::CalendarSubscription::Update, type: :graphql do
  4. let(:user) { create(:agent) }
  5. let(:mutation) do
  6. <<~GQL
  7. mutation userCurrentCalendarSubscriptionUpdate($input: UserCalendarSubscriptionsConfigInput!) {
  8. userCurrentCalendarSubscriptionUpdate(input: $input) {
  9. success
  10. errors {
  11. message
  12. field
  13. }
  14. }
  15. }
  16. GQL
  17. end
  18. let(:variables) do
  19. {
  20. input: {
  21. alarm: true,
  22. newOpen: { own: false, notAssigned: false },
  23. pending: { own: true, notAssigned: true },
  24. escalation: { own: true, notAssigned: false },
  25. }
  26. }
  27. end
  28. def execute_graphql_query
  29. gql.execute(mutation, variables: variables)
  30. end
  31. context 'when user is not authenticated' do
  32. before { execute_graphql_query }
  33. it_behaves_like 'graphql responds with error if unauthenticated'
  34. end
  35. context 'when user is authenticated', authenticated_as: :user do
  36. it 'updates preferences', aggregate_failures: true do
  37. execute_graphql_query
  38. expect(user.reload.preferences[:calendar_subscriptions])
  39. .to include(
  40. tickets: include(
  41. new_open: include(own: false, not_assigned: false),
  42. pending: include(own: true, not_assigned: true),
  43. escalation: include(own: true, not_assigned: false),
  44. alarm: true
  45. )
  46. )
  47. end
  48. it 'sends correct data to the service', aggregate_failures: true do
  49. allow(Service::User::CalendarSubscription::Update).to receive(:new).and_call_original
  50. expect_any_instance_of(Service::User::CalendarSubscription::Update).to receive(:execute)
  51. execute_graphql_query
  52. expect(Service::User::CalendarSubscription::Update)
  53. .to have_received(:new)
  54. .with(
  55. user,
  56. include(
  57. input: include(
  58. alarm: true,
  59. new_open: include(own: false, not_assigned: false),
  60. )
  61. )
  62. )
  63. end
  64. context 'when user has insufficicent permissions' do
  65. let(:user) { create(:customer) }
  66. before { execute_graphql_query }
  67. it_behaves_like 'graphql responds with error if unauthenticated'
  68. end
  69. end
  70. end