Testing: Expand factories for Twitter API testing
This commit is contained in:
parent
5ffad2a7e7
commit
3df00e7e1b
3 changed files with 54 additions and 4 deletions
14
spec/factories/authorization.rb
Normal file
14
spec/factories/authorization.rb
Normal file
|
@ -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
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue