channel.rb 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. FactoryBot.define do
  2. factory :channel do
  3. # ensure the `refresh_xoaut2!` `after_initialize` callback gets executed
  4. # https://stackoverflow.com/questions/5916162/problem-with-factory-girl-association-and-after-initialize#comment51639005_28057070
  5. initialize_with { new(attributes) }
  6. area { 'Email::Dummy' }
  7. group { ::Group.find(1) }
  8. active { true }
  9. options {}
  10. preferences {}
  11. updated_by_id { 1 }
  12. created_by_id { 1 }
  13. factory :email_channel do
  14. area { 'Email::Account' }
  15. options do
  16. {
  17. inbound: {
  18. adapter: 'null', options: {}
  19. },
  20. outbound: {
  21. adapter: 'sendmail'
  22. }
  23. }
  24. end
  25. end
  26. factory :twitter_channel do
  27. area { 'Twitter::Account' }
  28. options do
  29. {
  30. adapter: 'twitter',
  31. user: {
  32. id: oauth_token&.split('-')&.first,
  33. screen_name: 'nicole_braun',
  34. name: 'Nicole Braun',
  35. },
  36. auth: {
  37. external_credential_id: external_credential.id,
  38. oauth_token: oauth_token,
  39. oauth_token_secret: oauth_token_secret,
  40. },
  41. sync: {
  42. webhook_id: '',
  43. mentions: {
  44. group_id: Group.first.id
  45. },
  46. direct_messages: {
  47. group_id: Group.first.id
  48. },
  49. search: [
  50. {
  51. term: search_term,
  52. group_id: Group.first.id
  53. },
  54. ],
  55. },
  56. subscribed_to_webhook_id: external_credential.credentials[:webhook_id],
  57. }.deep_merge(custom_options)
  58. end
  59. transient do
  60. custom_options { {} }
  61. external_credential { create(:twitter_credential) }
  62. oauth_token { external_credential.credentials[:oauth_token] }
  63. oauth_token_secret { external_credential.credentials[:oauth_token_secret] }
  64. search_term { 'zammad' }
  65. end
  66. trait :legacy do
  67. transient do
  68. custom_options { { sync: { import_older_tweets: true } } }
  69. end
  70. end
  71. trait :invalid do
  72. transient do
  73. external_credential { create(:twitter_credential, :invalid) }
  74. end
  75. end
  76. end
  77. end
  78. end