signature_spec.rb 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. # Copyright (C) 2012-2024 Zammad Foundation, https://zammad-foundation.org/
  2. require 'rails_helper'
  3. RSpec.describe Gql::Queries::Ticket::Signature, type: :graphql do
  4. let(:signature) { create(:signature, body: "\#{user.fullname} via \#{config.product_name}") }
  5. let(:group) { create(:group, signature_id: signature.id) }
  6. let(:query) do
  7. <<~QUERY
  8. query ticketSignature($groupId: ID!, $ticketId: ID) {
  9. ticketSignature(groupId: $groupId) {
  10. id
  11. renderedBody(ticketId: $ticketId)
  12. }
  13. }
  14. QUERY
  15. end
  16. let(:variables) { { groupId: gql.id(group) } }
  17. before do
  18. gql.execute(query, variables: variables)
  19. end
  20. context 'with an agent', authenticated_as: :user do
  21. context 'with permission' do
  22. let(:user) { create(:agent, groups: [group]) }
  23. context 'without ticket context' do
  24. it 'returns data' do
  25. expect(gql.result.data).to eq({
  26. 'id' => gql.id(signature),
  27. 'renderedBody' => "#{user.fullname} via #{Setting.get('product_name')}",
  28. })
  29. end
  30. end
  31. context 'with ticket context' do
  32. let(:signature) { create(:signature, body: "\#{user.fullname} via \#{config.product_name} (\#{ticket.number})") }
  33. let(:ticket) { create(:ticket, group: group) }
  34. let(:variables) { { groupId: gql.id(group), ticketId: gql.id(ticket) } }
  35. it 'returns data' do
  36. expect(gql.result.data).to eq({
  37. 'id' => gql.id(signature),
  38. 'renderedBody' => "#{user.fullname} via #{Setting.get('product_name')} (#{ticket.number})",
  39. })
  40. end
  41. end
  42. context 'without assigned signature to the group' do
  43. let(:group) { create(:group) }
  44. it 'returns no data' do
  45. expect(gql.result.data).to be_nil
  46. end
  47. end
  48. context 'with inactive signature' do
  49. let(:signature) { create(:signature, active: false) }
  50. it 'returns no data' do
  51. expect(gql.result.data).to be_nil
  52. end
  53. end
  54. context 'with empty body signature' do
  55. let(:signature) { create(:signature, body: '') }
  56. it 'returns no data' do
  57. expect(gql.result.data).to be_nil
  58. end
  59. end
  60. end
  61. context 'without permission' do
  62. let(:user) { create(:agent) }
  63. it 'raises an error' do
  64. expect(gql.result.error_type).to eq(Exceptions::Forbidden)
  65. end
  66. end
  67. end
  68. context 'with a customer', authenticated_as: :user do
  69. let(:user) { create(:customer) }
  70. it 'raises an error' do
  71. expect(gql.result.error_type).to eq(Exceptions::Forbidden)
  72. end
  73. end
  74. it_behaves_like 'graphql responds with error if unauthenticated'
  75. end