channel.rb 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210
  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. 'domain' => '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' => true,
  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. 'domain' => 'office365.com',
  178. 'port' => 587,
  179. 'user' => ENV['MICROSOFT365_USER'],
  180. 'authentication' => 'xoauth2',
  181. }
  182. },
  183. 'auth' => {
  184. 'type' => 'XOAUTH2',
  185. 'provider' => 'microsoft365',
  186. 'access_token' => 'xxx',
  187. 'expires_in' => 3599,
  188. 'refresh_token' => ENV['MICROSOFT365_REFRESH_TOKEN'],
  189. 'scope' => 'https://outlook.office.com/IMAP.AccessAsUser.All https://outlook.office.com/SMTP.Send offline_access openid profile email',
  190. 'token_type' => 'Bearer',
  191. 'id_token' => 'xxx',
  192. 'created_at' => 30.days.ago,
  193. 'client_id' => ENV['MICROSOFT365_CLIENT_ID'],
  194. 'client_secret' => ENV['MICROSOFT365_CLIENT_SECRET'],
  195. }
  196. }
  197. end
  198. end
  199. end
  200. end