channel.rb 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264
  1. # Copyright (C) 2012-2023 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: 'APITesting001',
  40. name: 'Test API Account',
  41. },
  42. auth: {
  43. external_credential_id: external_credential.id,
  44. oauth_token: oauth_token,
  45. oauth_token_secret: oauth_token_secret,
  46. consumer_key: consumer_key,
  47. consumer_secret: consumer_secret,
  48. },
  49. sync: {
  50. webhook_id: '',
  51. mentions: {
  52. group_id: Group.first.id
  53. },
  54. direct_messages: {
  55. group_id: Group.first.id
  56. },
  57. search: [
  58. {
  59. term: search_term,
  60. group_id: Group.first.id
  61. },
  62. ],
  63. },
  64. subscribed_to_webhook_id: external_credential.credentials[:webhook_id],
  65. }.deep_merge(custom_options)
  66. end
  67. transient do
  68. custom_options { {} }
  69. external_credential { create(:twitter_credential) }
  70. oauth_token { external_credential.credentials[:oauth_token] }
  71. oauth_token_secret { external_credential.credentials[:oauth_token_secret] }
  72. consumer_key { external_credential.credentials[:consumer_key] }
  73. consumer_secret { external_credential.credentials[:consumer_secret] }
  74. search_term { 'zammad' }
  75. end
  76. trait :legacy do
  77. transient do
  78. custom_options { { sync: { import_older_tweets: true } } }
  79. end
  80. end
  81. trait :invalid do
  82. transient do
  83. external_credential { create(:twitter_credential, :invalid) }
  84. end
  85. end
  86. end
  87. factory :facebook_channel do
  88. area { 'Facebook::Account' }
  89. options do
  90. {
  91. adapter: 'facebook',
  92. user: {
  93. id: ENV['FACEBOOK_ADMIN_USER_ID'],
  94. name: "#{ENV['FACEBOOK_ADMIN_FIRSTNAME']} #{ENV['FACEBOOK_ADMIN_LASTNAME']}",
  95. },
  96. auth: {
  97. access_token: ENV['FACEBOOK_ADMIN_ACCESS_TOKEN'],
  98. },
  99. sync: {
  100. pages: {
  101. ENV['FACEBOOK_PAGE_1_ID'] => {
  102. group_id: Group.first.id,
  103. }
  104. }
  105. },
  106. pages: [
  107. {
  108. id: ENV['FACEBOOK_PAGE_1_ID'],
  109. name: ENV['FACEBOOK_PAGE_1_NAME'],
  110. access_token: ENV['FACEBOOK_PAGE_1_ACCCESS_TOKEN'],
  111. },
  112. {
  113. id: ENV['FACEBOOK_PAGE_2_ID'],
  114. name: ENV['FACEBOOK_PAGE_2_NAME'],
  115. access_token: ENV['FACEBOOK_PAGE_2_ACCCESS_TOKEN'],
  116. }
  117. ],
  118. }
  119. end
  120. end
  121. factory :google_channel do
  122. area { 'Google::Account' }
  123. options do
  124. {
  125. 'inbound' => {
  126. 'adapter' => 'imap',
  127. 'options' => {
  128. 'auth_type' => 'XOAUTH2',
  129. 'host' => 'imap.gmail.com',
  130. 'ssl' => 'ssl',
  131. 'user' => ENV['GMAIL_USER'],
  132. 'folder' => '',
  133. 'keep_on_server' => false,
  134. }
  135. },
  136. 'outbound' => {
  137. 'adapter' => 'smtp',
  138. 'options' => {
  139. 'host' => 'smtp.gmail.com',
  140. 'port' => 465,
  141. 'ssl' => true,
  142. 'user' => ENV['GMAIL_USER'],
  143. 'authentication' => 'xoauth2',
  144. }
  145. },
  146. 'auth' => {
  147. 'type' => 'XOAUTH2',
  148. 'provider' => 'google',
  149. 'access_token' => 'xxx',
  150. 'expires_in' => 3599,
  151. 'refresh_token' => ENV['GMAIL_REFRESH_TOKEN'],
  152. 'scope' => 'https://www.googleapis.com/auth/userinfo.email https://www.googleapis.com/auth/userinfo.profile https://mail.google.com/ openid',
  153. 'token_type' => 'Bearer',
  154. 'id_token' => 'xxx',
  155. 'created_at' => 30.days.ago,
  156. 'client_id' => ENV['GMAIL_CLIENT_ID'],
  157. 'client_secret' => ENV['GMAIL_CLIENT_SECRET'],
  158. }
  159. }
  160. end
  161. end
  162. factory :microsoft365_channel do
  163. area { 'Microsoft365::Account' }
  164. options do
  165. {
  166. 'inbound' => {
  167. 'adapter' => 'imap',
  168. 'options' => {
  169. 'auth_type' => 'XOAUTH2',
  170. 'host' => 'outlook.office365.com',
  171. 'ssl' => 'ssl',
  172. 'user' => ENV['MICROSOFT365_USER'],
  173. 'folder' => '',
  174. 'keep_on_server' => false,
  175. }
  176. },
  177. 'outbound' => {
  178. 'adapter' => 'smtp',
  179. 'options' => {
  180. 'host' => 'smtp.office365.com',
  181. 'port' => 587,
  182. 'user' => ENV['MICROSOFT365_USER'],
  183. 'authentication' => 'xoauth2',
  184. }
  185. },
  186. 'auth' => {
  187. 'type' => 'XOAUTH2',
  188. 'provider' => 'microsoft365',
  189. 'access_token' => 'xxx',
  190. 'expires_in' => 3599,
  191. 'refresh_token' => ENV['MICROSOFT365_REFRESH_TOKEN'],
  192. 'scope' => 'https://outlook.office.com/IMAP.AccessAsUser.All https://outlook.office.com/SMTP.Send offline_access openid profile email',
  193. 'token_type' => 'Bearer',
  194. 'id_token' => 'xxx',
  195. 'created_at' => 30.days.ago,
  196. 'client_id' => ENV['MICROSOFT365_CLIENT_ID'],
  197. 'client_secret' => ENV['MICROSOFT365_CLIENT_SECRET'],
  198. 'client_tenant' => ENV['MICROSOFT365_CLIENT_TENANT'],
  199. }
  200. }
  201. end
  202. end
  203. factory :sms_message_bird_channel do
  204. area { 'Sms::Account' }
  205. status_in { 'ok' }
  206. status_out { 'ok' }
  207. options do
  208. {
  209. adapter: 'sms/message_bird',
  210. webhook: "http://localhost:3000/api/v1/sms_webhook/#{webhook_token}",
  211. sender: '+490123456789',
  212. token: external_credential.credentials['token'],
  213. webhook_token: webhook_token,
  214. }.deep_merge(custom_options)
  215. end
  216. transient do
  217. custom_options { {} }
  218. external_credential { create(:sms_message_bird_credential) }
  219. webhook_token { Faker::Crypto.md5 }
  220. end
  221. end
  222. factory :telegram_channel do
  223. area { 'Telegram::Bot' }
  224. options do
  225. {
  226. bot: {
  227. id: bid,
  228. username: "#{Faker::Internet.username}bot",
  229. first_name: Faker::Name.unique.first_name,
  230. last_name: Faker::Name.unique.last_name,
  231. },
  232. callback_token: callback_token,
  233. callback_url: "http://localhost:3000/api/v1/channels_telegram_webhook/#{callback_token}?bid=#{bid}",
  234. api_token: "#{bid}:#{external_credential.credentials['api_token']}",
  235. welcome: Faker::Lorem.sentence,
  236. goodbye: Faker::Lorem.sentence,
  237. }.deep_merge(custom_options)
  238. end
  239. transient do
  240. custom_options { {} }
  241. external_credential { create(:telegram_credential) }
  242. bid { Faker::Number.unique.number(digits: 10) }
  243. callback_token { Faker::Alphanumeric.alphanumeric(number: 14) }
  244. end
  245. end
  246. end
  247. end