channel.rb 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210
  1. # Copyright (C) 2012-2022 Zammad Foundation, https://zammad-foundation.org/
  2. FactoryBot.define do
  3. factory :channel do
  4. area { 'Email::Dummy' }
  5. group { ::Group.find(1) }
  6. active { true }
  7. options { nil }
  8. preferences { nil }
  9. updated_by_id { 1 }
  10. created_by_id { 1 }
  11. factory :email_channel do
  12. area { 'Email::Account' }
  13. options do
  14. {
  15. inbound: inbound,
  16. outbound: outbound,
  17. }
  18. end
  19. transient do
  20. inbound do
  21. {
  22. adapter: 'null', options: {}
  23. }
  24. end
  25. outbound do
  26. {
  27. adapter: 'sendmail'
  28. }
  29. end
  30. end
  31. end
  32. factory :twitter_channel do
  33. area { 'Twitter::Account' }
  34. options do
  35. {
  36. adapter: 'twitter',
  37. user: {
  38. id: oauth_token&.split('-')&.first,
  39. screen_name: 'nicole_braun',
  40. name: 'Nicole Braun',
  41. },
  42. auth: {
  43. external_credential_id: external_credential.id,
  44. oauth_token: oauth_token,
  45. oauth_token_secret: oauth_token_secret,
  46. },
  47. sync: {
  48. webhook_id: '',
  49. mentions: {
  50. group_id: Group.first.id
  51. },
  52. direct_messages: {
  53. group_id: Group.first.id
  54. },
  55. search: [
  56. {
  57. term: search_term,
  58. group_id: Group.first.id
  59. },
  60. ],
  61. },
  62. subscribed_to_webhook_id: external_credential.credentials[:webhook_id],
  63. }.deep_merge(custom_options)
  64. end
  65. transient do
  66. custom_options { {} }
  67. external_credential { create(:twitter_credential) }
  68. oauth_token { external_credential.credentials[:oauth_token] }
  69. oauth_token_secret { external_credential.credentials[:oauth_token_secret] }
  70. search_term { 'zammad' }
  71. end
  72. trait :legacy do
  73. transient do
  74. custom_options { { sync: { import_older_tweets: true } } }
  75. end
  76. end
  77. trait :invalid do
  78. transient do
  79. external_credential { create(:twitter_credential, :invalid) }
  80. end
  81. end
  82. end
  83. factory :facebook_channel do
  84. area { 'Facebook::Account' }
  85. options do
  86. {
  87. adapter: 'facebook',
  88. user: {
  89. id: ENV['FACEBOOK_ADMIN_USER_ID'],
  90. name: "#{ENV['FACEBOOK_ADMIN_FIRSTNAME']} #{ENV['FACEBOOK_ADMIN_LASTNAME']}",
  91. },
  92. auth: {
  93. access_token: ENV['FACEBOOK_ADMIN_ACCESS_TOKEN'],
  94. },
  95. sync: {
  96. pages: {
  97. ENV['FACEBOOK_PAGE_1_ID'] => {
  98. group_id: Group.first.id,
  99. }
  100. }
  101. },
  102. pages: [
  103. {
  104. id: ENV['FACEBOOK_PAGE_1_ID'],
  105. name: ENV['FACEBOOK_PAGE_1_NAME'],
  106. access_token: ENV['FACEBOOK_PAGE_1_ACCCESS_TOKEN'],
  107. },
  108. {
  109. id: ENV['FACEBOOK_PAGE_2_ID'],
  110. name: ENV['FACEBOOK_PAGE_2_NAME'],
  111. access_token: ENV['FACEBOOK_PAGE_2_ACCCESS_TOKEN'],
  112. }
  113. ],
  114. }
  115. end
  116. end
  117. factory :google_channel do
  118. area { 'Google::Account' }
  119. options do
  120. {
  121. 'inbound' => {
  122. 'adapter' => 'imap',
  123. 'options' => {
  124. 'auth_type' => 'XOAUTH2',
  125. 'host' => 'imap.gmail.com',
  126. 'ssl' => 'ssl',
  127. 'user' => ENV['GMAIL_USER'],
  128. 'folder' => '',
  129. 'keep_on_server' => false,
  130. }
  131. },
  132. 'outbound' => {
  133. 'adapter' => 'smtp',
  134. 'options' => {
  135. 'host' => 'smtp.gmail.com',
  136. 'port' => 465,
  137. 'ssl' => true,
  138. 'user' => ENV['GMAIL_USER'],
  139. 'authentication' => 'xoauth2',
  140. }
  141. },
  142. 'auth' => {
  143. 'type' => 'XOAUTH2',
  144. 'provider' => 'google',
  145. 'access_token' => 'xxx',
  146. 'expires_in' => 3599,
  147. 'refresh_token' => ENV['GMAIL_REFRESH_TOKEN'],
  148. 'scope' => 'https://www.googleapis.com/auth/userinfo.email https://www.googleapis.com/auth/userinfo.profile https://mail.google.com/ openid',
  149. 'token_type' => 'Bearer',
  150. 'id_token' => 'xxx',
  151. 'created_at' => 30.days.ago,
  152. 'client_id' => ENV['GMAIL_CLIENT_ID'],
  153. 'client_secret' => ENV['GMAIL_CLIENT_SECRET'],
  154. }
  155. }
  156. end
  157. end
  158. factory :microsoft365_channel do
  159. area { 'Microsoft365::Account' }
  160. options do
  161. {
  162. 'inbound' => {
  163. 'adapter' => 'imap',
  164. 'options' => {
  165. 'auth_type' => 'XOAUTH2',
  166. 'host' => 'outlook.office365.com',
  167. 'ssl' => 'ssl',
  168. 'user' => ENV['MICROSOFT365_USER'],
  169. 'folder' => '',
  170. 'keep_on_server' => false,
  171. }
  172. },
  173. 'outbound' => {
  174. 'adapter' => 'smtp',
  175. 'options' => {
  176. 'host' => 'smtp.office365.com',
  177. 'port' => 587,
  178. 'user' => ENV['MICROSOFT365_USER'],
  179. 'authentication' => 'xoauth2',
  180. }
  181. },
  182. 'auth' => {
  183. 'type' => 'XOAUTH2',
  184. 'provider' => 'microsoft365',
  185. 'access_token' => 'xxx',
  186. 'expires_in' => 3599,
  187. 'refresh_token' => ENV['MICROSOFT365_REFRESH_TOKEN'],
  188. 'scope' => 'https://outlook.office.com/IMAP.AccessAsUser.All https://outlook.office.com/SMTP.Send offline_access openid profile email',
  189. 'token_type' => 'Bearer',
  190. 'id_token' => 'xxx',
  191. 'created_at' => 30.days.ago,
  192. 'client_id' => ENV['MICROSOFT365_CLIENT_ID'],
  193. 'client_secret' => ENV['MICROSOFT365_CLIENT_SECRET'],
  194. }
  195. }
  196. end
  197. end
  198. end
  199. end