add_spec.rb 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. # Copyright (C) 2012-2024 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. }
  46. end
  47. let(:group) { create(:group) }
  48. let(:variables) do
  49. {
  50. input: {
  51. inboundConfiguration: inbound_configuration,
  52. outboundConfiguration: outbound_configuration,
  53. groupId: gql.id(group),
  54. emailAddress: 'some.sender@example.com',
  55. emailRealname: 'John Doe'
  56. }
  57. }
  58. end
  59. before do
  60. gql.execute(query, variables: variables)
  61. end
  62. context 'when authenticated as admin', authenticated_as: :admin do
  63. let(:admin) { create(:admin) }
  64. let(:options_outbound) do
  65. {
  66. adapter: 'smtp',
  67. options: {
  68. host: 'nonexisting.host.local',
  69. port: 25,
  70. user: 'some@example.com',
  71. password: 'password',
  72. ssl_verify: false,
  73. }
  74. }
  75. end
  76. let(:options_inbound) do
  77. {
  78. adapter: 'imap',
  79. options: {
  80. host: 'nonexisting.host.local',
  81. port: 993,
  82. ssl: 'ssl',
  83. user: 'some@example.com',
  84. password: 'password',
  85. folder: 'some_folder',
  86. keep_on_server: true,
  87. ssl_verify: false,
  88. archive: true,
  89. archive_before: '2012-03-04T00:00:00'.to_time, # rubocop:disable Rails/TimeZone
  90. }
  91. }
  92. end
  93. it 'creates the channel' do
  94. expect(gql.result.data[:channel]).to include(options: include(
  95. inbound: options_inbound, outbound: options_outbound
  96. ))
  97. end
  98. end
  99. context 'when authenticated as non-admin', authenticated_as: :agent do
  100. let(:agent) { create(:agent) }
  101. it 'fails with authentication error' do
  102. expect(gql.result.error_type).to eq(Exceptions::Forbidden)
  103. end
  104. end
  105. it_behaves_like 'graphql responds with error if unauthenticated'
  106. end