article.rb 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. FactoryBot.define do
  2. factory :'ticket/article', aliases: %i[ticket_article] do
  3. inbound_email
  4. association :ticket, strategy: :create # or else build(:ticket_article).save fails
  5. from { 'factory-customer-1@example.com' }
  6. to { 'factory-customer-1@example.com' }
  7. subject { 'factory article' }
  8. message_id { 'factory@id_com_1' }
  9. body { 'some message 123' }
  10. internal { false }
  11. sender { Ticket::Article::Sender.find_by(name: sender_name) }
  12. type { Ticket::Article::Type.find_by(name: type_name) }
  13. updated_by_id { 1 }
  14. created_by_id { 1 }
  15. trait :inbound_email do
  16. transient do
  17. type_name { 'email' }
  18. sender_name { 'Customer' }
  19. end
  20. end
  21. trait :outbound_email do
  22. transient do
  23. type_name { 'email' }
  24. sender_name { 'Agent' }
  25. end
  26. from { ticket.group.name }
  27. to { "#{ticket.customer.fullname} <#{ticket.customer.email}>" }
  28. end
  29. trait :inbound_phone do
  30. transient do
  31. type_name { 'phone' }
  32. sender_name { 'Customer' }
  33. end
  34. end
  35. trait :outbound_phone do
  36. transient do
  37. type_name { 'phone' }
  38. sender_name { 'Agent' }
  39. end
  40. from { nil }
  41. to { ticket.customer.fullname }
  42. end
  43. trait :outbound_note do
  44. transient do
  45. type_name { 'note' }
  46. sender_name { 'Agent' }
  47. end
  48. from { ticket.group.name }
  49. end
  50. trait :inbound_web do
  51. transient do
  52. type_name { 'web' }
  53. sender_name { 'Customer' }
  54. end
  55. end
  56. trait :outbound_web do
  57. transient do
  58. type_name { 'web' }
  59. sender_name { 'Agent' }
  60. end
  61. end
  62. factory :twitter_article do
  63. transient do
  64. type_name { 'twitter status' }
  65. end
  66. association :ticket, factory: :twitter_ticket
  67. message_id { '775410014383026176' }
  68. body { Faker::Lorem.sentence }
  69. sender_name { 'Agent' }
  70. trait :reply do
  71. in_reply_to { Faker::Number.number(19) }
  72. end
  73. end
  74. factory :twitter_dm_article do
  75. transient do
  76. type_name { 'twitter direct-message' }
  77. end
  78. association :ticket, factory: :twitter_ticket
  79. body { Faker::Lorem.sentence }
  80. trait :pending_delivery do
  81. transient do
  82. recipient { create(:twitter_authorization) }
  83. sender_id { Faker::Number.number(10) }
  84. end
  85. from { ticket.owner.fullname }
  86. to { recipient.username }
  87. in_reply_to { Faker::Number.number(19) }
  88. content_type { 'text/plain' }
  89. end
  90. trait :delivered do
  91. pending_delivery
  92. message_id { Faker::Number.number(19) }
  93. preferences do
  94. {
  95. delivery_retry: 1,
  96. twitter: {
  97. recipient_id: recipient.uid,
  98. sender_id: sender_id
  99. },
  100. links: [
  101. {
  102. url: "https://twitter.com/messages/#{recipient.uid}-#{sender_id}",
  103. target: '_blank',
  104. name: 'on Twitter'
  105. }
  106. ],
  107. delivery_status_message: nil,
  108. delivery_status: 'success',
  109. delivery_status_date: Time.current
  110. }
  111. end
  112. end
  113. end
  114. end
  115. end