channel.rb 6.2 KB

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