article.rb 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. FactoryBot.define do
  2. factory :'ticket/article', aliases: %i[ticket_article] do
  3. transient do
  4. type_name { 'email' }
  5. sender_name { 'Customer' }
  6. end
  7. association :ticket, strategy: :create # or else build(:ticket_article).save fails
  8. from { 'factory-customer-1@example.com' }
  9. to { 'factory-customer-1@example.com' }
  10. subject { 'factory article' }
  11. message_id { 'factory@id_com_1' }
  12. body { 'some message 123' }
  13. internal { false }
  14. sender { Ticket::Article::Sender.find_by(name: sender_name) }
  15. type { Ticket::Article::Type.find_by(name: type_name) }
  16. updated_by_id { 1 }
  17. created_by_id { 1 }
  18. factory :twitter_article do
  19. transient do
  20. type_name { 'twitter status' }
  21. end
  22. association :ticket, factory: :twitter_ticket
  23. message_id { '775410014383026176' }
  24. body { Faker::Lorem.sentence }
  25. sender_name { 'Agent' }
  26. trait :reply do
  27. in_reply_to { Faker::Number.number(19) }
  28. end
  29. end
  30. factory :twitter_dm_article do
  31. transient do
  32. type_name { 'twitter direct-message' }
  33. end
  34. association :ticket, factory: :twitter_ticket
  35. body { Faker::Lorem.sentence }
  36. trait :pending_delivery do
  37. transient do
  38. recipient { create(:twitter_authorization) }
  39. sender_id { Faker::Number.number(10) }
  40. end
  41. from { ticket.owner.fullname }
  42. to { recipient.username }
  43. in_reply_to { Faker::Number.number(19) }
  44. content_type { 'text/plain' }
  45. end
  46. trait :delivered do
  47. pending_delivery
  48. message_id { Faker::Number.number(19) }
  49. preferences do
  50. {
  51. delivery_retry: 1,
  52. twitter: {
  53. recipient_id: recipient.uid,
  54. sender_id: sender_id
  55. },
  56. links: [
  57. {
  58. url: "https://twitter.com/messages/#{recipient.uid}-#{sender_id}",
  59. target: '_blank',
  60. name: 'on Twitter'
  61. }
  62. ],
  63. delivery_status_message: nil,
  64. delivery_status: 'success',
  65. delivery_status_date: Time.current
  66. }
  67. end
  68. end
  69. end
  70. end
  71. end