add_spec.rb 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. # Copyright (C) 2012-2025 Zammad Foundation, https://zammad-foundation.org/
  2. require 'rails_helper'
  3. RSpec.describe Gql::Mutations::Channel::Email::Add, type: :graphql do
  4. let(:query) do
  5. <<~QUERY
  6. mutation channelEmailAdd($input: ChannelEmailAddInput!) {
  7. channelEmailAdd(input: $input) {
  8. channel {
  9. options
  10. group {
  11. id
  12. }
  13. }
  14. errors {
  15. message
  16. field
  17. }
  18. }
  19. }
  20. QUERY
  21. end
  22. let(:outbound_configuration) do
  23. {
  24. adapter: 'smtp',
  25. host: 'nonexisting.host.local',
  26. port: 25,
  27. user: 'some@example.com',
  28. password: 'password',
  29. sslVerify: false,
  30. }
  31. end
  32. let(:inbound_configuration) do
  33. {
  34. adapter: 'imap',
  35. host: 'nonexisting.host.local',
  36. port: 993,
  37. ssl: 'ssl',
  38. user: 'some@example.com',
  39. password: 'password',
  40. folder: 'some_folder',
  41. keepOnServer: true,
  42. sslVerify: false,
  43. archive: true,
  44. archiveBefore: '2012-03-04T00:00:00',
  45. archiveStateId: Ticket::State.find_by(name: 'closed').id,
  46. }
  47. end
  48. let(:group) { create(:group) }
  49. let(:variables) do
  50. {
  51. input: {
  52. inboundConfiguration: inbound_configuration,
  53. outboundConfiguration: outbound_configuration,
  54. groupId: gql.id(group),
  55. emailAddress: 'some.sender@example.com',
  56. emailRealname: 'John Doe'
  57. }
  58. }
  59. end
  60. before do
  61. gql.execute(query, variables: variables)
  62. end
  63. context 'when authenticated as admin', authenticated_as: :admin do
  64. let(:admin) { create(:admin) }
  65. let(:options_outbound) do
  66. {
  67. adapter: 'smtp',
  68. options: {
  69. host: 'nonexisting.host.local',
  70. port: 25,
  71. user: 'some@example.com',
  72. password: 'password',
  73. ssl_verify: false,
  74. }
  75. }
  76. end
  77. let(:options_inbound) do
  78. {
  79. adapter: 'imap',
  80. options: {
  81. host: 'nonexisting.host.local',
  82. port: 993,
  83. ssl: 'ssl',
  84. user: 'some@example.com',
  85. password: 'password',
  86. folder: 'some_folder',
  87. keep_on_server: true,
  88. ssl_verify: false,
  89. archive: true,
  90. archive_before: '2012-03-04T00:00:00'.to_time, # rubocop:disable Rails/TimeZone,
  91. archive_state_id: Ticket::State.find_by(name: 'closed').id,
  92. }
  93. }
  94. end
  95. it 'creates the channel' do
  96. expect(gql.result.data[:channel]).to include(options: include(
  97. inbound: options_inbound, outbound: options_outbound
  98. ))
  99. end
  100. end
  101. context 'when authenticated as non-admin', authenticated_as: :agent do
  102. let(:agent) { create(:agent) }
  103. it 'fails with authentication error' do
  104. expect(gql.result.error_type).to eq(Exceptions::Forbidden)
  105. end
  106. end
  107. it_behaves_like 'graphql responds with error if unauthenticated'
  108. end