diff --git a/spec/factories/authorization.rb b/spec/factories/authorization.rb new file mode 100644 index 000000000..11dcf043f --- /dev/null +++ b/spec/factories/authorization.rb @@ -0,0 +1,14 @@ +FactoryBot.define do + factory :authorization do + transient do + user { create(:customer_user) } + end + + factory :twitter_authorization do + provider { 'twitter' } + uid { Faker::Number.number(10) } + username { Faker::Internet.username } + user_id { user.id } + end + end +end diff --git a/spec/factories/external_credential.rb b/spec/factories/external_credential.rb index 39e1a3e8a..f9571b632 100644 --- a/spec/factories/external_credential.rb +++ b/spec/factories/external_credential.rb @@ -29,10 +29,10 @@ FactoryBot.define do # Instead, store your twitter API credentials in env vars to utilize this factory. # (Try https://github.com/direnv/direnv to set env vars automatically.) transient do - consumer_key { 'REDACTED' } - consumer_secret { 'REDACTED' } - oauth_token { 'REDACTED' } - oauth_token_secret { 'REDACTED' } + consumer_key { ENV.fetch('TWITTER_CONSUMER_KEY') { 'REDACTED' } } + consumer_secret { ENV.fetch('TWITTER_CONSUMER_SECRET') { 'REDACTED' } } + oauth_token { ENV.fetch('TWITTER_OAUTH_TOKEN') { 'REDACTED' } } + oauth_token_secret { ENV.fetch('TWITTER_OAUTH_TOKEN_SECRET') { 'REDACTED' } } end trait :invalid do diff --git a/spec/factories/ticket/article.rb b/spec/factories/ticket/article.rb index 9f151e3d5..d52e45b7f 100644 --- a/spec/factories/ticket/article.rb +++ b/spec/factories/ticket/article.rb @@ -34,6 +34,42 @@ FactoryBot.define do association :ticket, factory: :twitter_ticket body { Faker::Lorem.sentence } + + trait :pending_delivery do + transient do + recipient { create(:twitter_authorization) } + sender_id { Faker::Number.number(10) } + end + + from { User.with_permissions('ticket.agent').first.fullname } + to { recipient.username } + in_reply_to { Faker::Number.number(19) } + content_type { 'text/plain' } + end + + trait :delivered do + pending_delivery + message_id { Faker::Number.number(19) } + preferences do + { + delivery_retry: 1, + twitter: { + recipient_id: recipient.uid, + sender_id: sender_id + }, + links: [ + { + url: "https://twitter.com/messages/#{recipient.uid}-#{sender_id}", + target: '_blank', + name: 'on Twitter' + } + ], + delivery_status_message: nil, + delivery_status: 'success', + delivery_status_date: Time.current + } + end + end end end end