123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904 |
- require 'integration_test_helper'
- class TwitterTest < ActiveSupport::TestCase
- self.test_order = :sorted
- self.use_transactional_tests = false
- # set system mode to done / to activate
- Setting.set('system_init_done', true)
- # needed to check correct behavior
- group = Group.create_if_not_exists(
- name: 'Twitter',
- note: 'All Tweets.',
- updated_by_id: 1,
- created_by_id: 1
- )
- {
- 'TWITTER_CONSUMER_KEY' => '1234',
- 'TWITTER_CONSUMER_SECRET' => '1234',
- 'TWITTER_SYSTEM_LOGIN' => '@system',
- 'TWITTER_SYSTEM_ID' => '1405469528',
- 'TWITTER_SYSTEM_TOKEN' => '1234',
- 'TWITTER_SYSTEM_TOKEN_SECRET' => '1234',
- 'TWITTER_CUSTOMER_LOGIN' => '@customer',
- 'TWITTER_CUSTOMER_TOKEN' => '1234',
- 'TWITTER_CUSTOMER_TOKEN_SECRET' => '1234',
- }.each do |key, example_value|
- next if ENV[key]
- raise "ERROR: Need ENV #{key} - hint: export #{key}='#{example_value}'"
- end
- # app config
- consumer_key = ENV['TWITTER_CONSUMER_KEY']
- consumer_secret = ENV['TWITTER_CONSUMER_SECRET']
- # armin_theo (is system and is following marion_bauer)
- system_login = ENV['TWITTER_SYSTEM_LOGIN']
- system_id = ENV['TWITTER_SYSTEM_ID']
- system_login_without_at = system_login[1, system_login.length]
- system_token = ENV['TWITTER_SYSTEM_TOKEN']
- system_token_secret = ENV['TWITTER_SYSTEM_TOKEN_SECRET']
- hash_tag1 = "#zarepl#{rand(999)}"
- hash_tag2 = "#citheo#{rand(999)}"
- # me_bauer (is customer and is following armin_theo)
- customer_login = ENV['TWITTER_CUSTOMER_LOGIN']
- customer_login_without_at = customer_login[1, customer_login.length]
- customer_token = ENV['TWITTER_CUSTOMER_TOKEN']
- customer_token_secret = ENV['TWITTER_CUSTOMER_TOKEN_SECRET']
- # ensure channel configuration
- Channel.where(area: 'Twitter::Account').each(&:destroy)
- channel = Channel.create!(
- area: 'Twitter::Account',
- options: {
- adapter: 'twitter',
- auth: {
- consumer_key: consumer_key,
- consumer_secret: consumer_secret,
- oauth_token: system_token,
- oauth_token_secret: system_token_secret,
- },
- user: {
- screen_name: system_login,
- id: system_id,
- },
- sync: {
- track_retweets: true,
- search: [
- {
- term: hash_tag2,
- group_id: group.id,
- },
- {
- term: hash_tag1,
- group_id: 1,
- },
- ],
- mentions: {
- group_id: group.id,
- },
- direct_messages: {
- group_id: group.id,
- }
- }
- },
- active: true,
- created_by_id: 1,
- updated_by_id: 1,
- )
- test 'a new outbound and reply' do
- hash = "#{hash_tag2}#{rand(999_999)}"
- user = User.find(2)
- text = "Today the weather is really #{rand_word}... #{hash}"
- ticket = Ticket.create!(
- title: text[0, 40],
- customer_id: user.id,
- group_id: group.id,
- state: Ticket::State.find_by(name: 'new'),
- priority: Ticket::Priority.find_by(name: '2 normal'),
- preferences: {
- channel_id: channel.id,
- },
- updated_by_id: 1,
- created_by_id: 1,
- )
- assert(ticket, "outbound ticket created, text: #{text}")
- article = Ticket::Article.create!(
- ticket_id: ticket.id,
- body: text,
- type: Ticket::Article::Type.find_by(name: 'twitter status'),
- sender: Ticket::Article::Sender.find_by(name: 'Agent'),
- internal: false,
- updated_by_id: 1,
- created_by_id: 1,
- )
- Scheduler.worker(true)
- article = Ticket::Article.find(article.id)
- assert(article, "outbound article created, text: #{text}")
- assert_equal(system_login, article.from, 'ticket article from')
- assert_equal('', article.to, 'ticket article to')
- ticket = Ticket.find(article.ticket_id)
- ticket.state = Ticket::State.find_by(name: 'closed')
- ticket.save!
- # reply by me_bauer
- client = Twitter::REST::Client.new do |config|
- config.consumer_key = consumer_key
- config.consumer_secret = consumer_secret
- config.access_token = customer_token
- config.access_token_secret = customer_token_secret
- end
- tweet_found = false
- client.user_timeline(system_login_without_at).each do |tweet|
- next if tweet.id.to_s != article.message_id.to_s
- tweet_found = true
- break
- end
- assert(tweet_found, "found outbound '#{text}' tweet '#{article.message_id}'")
- reply_text = "#{system_login} on my side the weather is nice, too! ๐๐๐ #weather#{rand(999_999)}"
- tweet = client.update(
- reply_text,
- {
- in_reply_to_status_id: article.message_id
- }
- )
- # fetch check system account
- sleep 10
- article = nil
- 2.times do
- Channel.fetch
- # check if follow up article has been created
- article = Ticket::Article.find_by(message_id: tweet.id)
- break if article
- sleep 10
- end
- assert(article, "article tweet '#{tweet.id}' imported")
- assert_equal(customer_login, article.from, 'ticket article from')
- assert_equal(system_login, article.to, 'ticket article to')
- assert_equal(tweet.id.to_s, article.message_id, 'ticket article inbound message_id')
- assert_equal(2, article.ticket.articles.count, 'ticket article inbound count')
- assert_equal(reply_text.utf8_to_3bytesutf8, ticket.articles.last.body, 'ticket article inbound body')
- assert_equal('open', ticket.reload.state.name)
- channel = Channel.find(channel.id)
- assert_equal('', channel.last_log_out)
- assert_equal('ok', channel.status_out)
- assert_equal('', channel.last_log_in)
- assert_equal('ok', channel.status_in)
- end
- test 'b new inbound and reply' do
- # new tweet by me_bauer
- client = Twitter::REST::Client.new do |config|
- config.consumer_key = consumer_key
- config.consumer_secret = consumer_secret
- config.access_token = customer_token
- config.access_token_secret = customer_token_secret
- end
- hash = "#{hash_tag1} ##{hash_gen}"
- text = "Today #{rand_word}... #{hash}"
- tweet = client.update(
- text,
- )
- # fetch check system account
- sleep 20
- article = nil
- 2.times do
- Channel.fetch
- # check if ticket and article has been created
- article = Ticket::Article.find_by(message_id: tweet.id)
- break if article
- sleep 20
- end
- assert(article, "Can't find tweet id #{tweet.id}/#{text}")
- assert_equal(customer_login, article.from, 'ticket article from')
- assert_nil(article.to, 'ticket article to')
- ticket = article.ticket
- assert_equal('new', ticket.reload.state.name)
- # send reply
- reply_text = "#{customer_login} on my side #weather#{hash_gen}"
- article = Ticket::Article.create!(
- ticket_id: ticket.id,
- body: reply_text,
- type: Ticket::Article::Type.find_by(name: 'twitter status'),
- sender: Ticket::Article::Sender.find_by(name: 'Agent'),
- internal: false,
- updated_by_id: 1,
- created_by_id: 1,
- )
- Scheduler.worker(true)
- assert_equal('open', ticket.reload.state.name)
- article = Ticket::Article.find(article.id)
- assert(article, "outbound article created, text: #{reply_text}")
- assert_equal(system_login, article.from, 'ticket article from')
- assert_equal(customer_login, article.to, 'ticket article to')
- sleep 5
- tweet_found = false
- client.user_timeline(system_login_without_at).each do |local_tweet|
- sleep 10
- next if local_tweet.id.to_s != article.message_id.to_s
- tweet_found = true
- break
- end
- assert(tweet_found, "found outbound '#{reply_text}' tweet '#{article.message_id}'")
- channel = Channel.find(channel.id)
- assert_equal('', channel.last_log_out)
- assert_equal('ok', channel.status_out)
- assert_equal('', channel.last_log_in)
- assert_equal('ok', channel.status_in)
- ticket = Ticket.find(article.ticket_id)
- ticket.state = Ticket::State.find_by(name: 'closed')
- ticket.save!
- # reply with zammad user directly
- client = Twitter::REST::Client.new do |config|
- config.consumer_key = consumer_key
- config.consumer_secret = consumer_secret
- config.access_token = system_token
- config.access_token_secret = system_token_secret
- end
- hash = "#{hash_tag1} ##{hash_gen}"
- text = "Today #{system_login} #{rand_word}... #{hash}"
- tweet = client.update(
- text,
- )
- # fetch check system account
- sleep 20
- article = nil
- 2.times do
- Channel.fetch
- # check if ticket and article has been created
- article = Ticket::Article.find_by(message_id: tweet.id)
- break if article
- sleep 20
- end
- assert(article, "Can't find tweet id #{tweet.id}/#{text}")
- assert_equal('closed', ticket.reload.state.name)
- end
- test 'c new by direct message inbound' do
- # cleanup direct messages of system
- client = Twitter::REST::Client.new do |config|
- config.consumer_key = consumer_key
- config.consumer_secret = consumer_secret
- config.access_token = system_token
- config.access_token_secret = system_token_secret
- end
- dms = client.direct_messages(count: 100)
- dms.each do |dm|
- client.destroy_direct_message(dm.id)
- end
- client = Twitter::REST::Client.new(
- consumer_key: consumer_key,
- consumer_secret: consumer_secret,
- access_token: customer_token,
- access_token_secret: customer_token_secret
- )
- dms = client.direct_messages(count: 100)
- dms.each do |dm|
- client.destroy_direct_message(dm.id)
- end
- hash = "#citheo44 #{hash_gen}"
- text = "How about #{rand_word} the details? #{hash} - #{'Long' * 50}"
- dm = client.create_direct_message(
- system_login_without_at,
- text,
- )
- assert(dm, "dm with ##{hash} created")
- # fetch check system account
- sleep 15
- article = nil
- 1.times do
- Channel.fetch
- # check if ticket and article has been created
- article = Ticket::Article.find_by(message_id: dm.id)
- break if article
- sleep 10
- end
- assert(article, "inbound article '#{text}' created")
- assert_equal(customer_login, article.from, 'ticket article from')
- assert_equal(text, article.body, 'ticket article body')
- ticket = article.ticket
- assert(ticket, 'ticket of inbound article exists')
- assert(ticket.articles, 'ticket.articles exists')
- assert_equal(1, ticket.articles.count, 'ticket article inbound count')
- assert_equal(ticket.state.name, 'new')
- # reply via ticket
- outbound_article = Ticket::Article.create!(
- ticket_id: ticket.id,
- to: customer_login,
- body: "Will call you later #{rand_word}!",
- type: Ticket::Article::Type.find_by(name: 'twitter direct-message'),
- sender: Ticket::Article::Sender.find_by(name: 'Agent'),
- internal: false,
- updated_by_id: 1,
- created_by_id: 1,
- )
- Scheduler.worker(true)
- outbound_article = Ticket::Article.find(outbound_article.id)
- assert(outbound_article, 'outbound article created')
- assert_equal(2, outbound_article.ticket.articles.count, 'ticket article outbound count')
- assert_equal(system_login, outbound_article.from, 'ticket article from')
- assert_equal(customer_login, outbound_article.to, 'ticket article to')
- ticket.state = Ticket::State.find_by(name: 'pending reminder')
- ticket.save
- text = "#{rand_word}. #{hash}"
- dm = client.create_direct_message(
- system_login_without_at,
- text,
- )
- assert(dm, "second dm with ##{hash} created")
- # fetch check system account
- sleep 15
- article = nil
- 1.times do
- Channel.fetch
- # check if ticket and article has been created
- article = Ticket::Article.find_by(message_id: dm.id)
- break if article
- sleep 10
- end
- assert(article, "inbound article '#{text}' created")
- assert_equal(customer_login, article.from, 'ticket article inbound from')
- assert_equal(system_login, article.to, 'ticket article inbound to')
- assert_equal(article.ticket.id, ticket.id, 'still the same ticket')
- ticket = article.ticket
- assert(ticket, 'ticket of inbound article exists')
- assert(ticket.articles, 'ticket.articles exists')
- assert_equal(3, ticket.articles.count, 'ticket article inbound count')
- assert_equal(ticket.state.name, 'open')
- # close dm ticket, next dm should open a new
- ticket.state = Ticket::State.find_by(name: 'closed')
- ticket.save
- text = "Thanks #{rand_word} for your call. I just have one question. #{hash}"
- dm = client.create_direct_message(
- system_login_without_at,
- text,
- )
- assert(dm, "third dm with ##{hash} created")
- # fetch check system account
- sleep 15
- article = nil
- 1.times do
- Channel.fetch
- # check if ticket and article has been created
- article = Ticket::Article.find_by(message_id: dm.id)
- break if article
- sleep 15
- end
- assert(article, "inbound article '#{text}' created with dm id #{dm.id}")
- assert_equal(customer_login, article.from, 'ticket article inbound from')
- assert_equal(system_login, article.to, 'ticket article inbound to')
- ticket = article.ticket
- assert(ticket, 'ticket of inbound article exists')
- assert(ticket.articles, 'ticket.articles exists')
- assert_equal(1, ticket.articles.count, 'ticket article inbound count')
- assert_equal(ticket.state.name, 'new')
- channel = Channel.find(channel.id)
- assert_equal('', channel.last_log_out)
- assert_equal('ok', channel.status_out)
- assert_equal('', channel.last_log_in)
- assert_equal('ok', channel.status_in)
- end
- test 'c new by direct message outbound without required parameters' do
- # cleanup direct messages of system
- client = Twitter::REST::Client.new do |config|
- config.consumer_key = consumer_key
- config.consumer_secret = consumer_secret
- config.access_token = system_token
- config.access_token_secret = system_token_secret
- end
- dms = client.direct_messages(count: 100)
- dms.each do |dm|
- client.destroy_direct_message(dm.id)
- end
- client = Twitter::REST::Client.new(
- consumer_key: consumer_key,
- consumer_secret: consumer_secret,
- access_token: customer_token,
- access_token_secret: customer_token_secret
- )
- dms = client.direct_messages(count: 100)
- dms.each do |dm|
- client.destroy_direct_message(dm.id)
- end
- hash = "#citheo44 #{hash_gen}"
- text = "How about #{rand_word} the details? #{hash} - #{'Long' * 50}"
- dm = client.create_direct_message(
- system_login_without_at,
- text,
- )
- assert(dm, "dm with ##{hash} created")
- # fetch check system account
- sleep 15
- article = nil
- 1.times do
- Channel.fetch
- # check if ticket and article has been created
- article = Ticket::Article.find_by(message_id: dm.id)
- break if article
- sleep 10
- end
- assert(article, "inbound article '#{text}' created")
- assert_equal(customer_login, article.from, 'ticket article from')
- assert_equal(text, article.body, 'ticket article body')
- ticket = article.ticket
- assert(ticket, 'ticket of inbound article exists')
- assert(ticket.articles, 'ticket.articles exists')
- assert_equal(1, ticket.articles.count, 'ticket article inbound count')
- assert_equal(ticket.state.name, 'closed')
- # reply via ticket
- reply = assert_raises(Exceptions::UnprocessableEntity) do
- Ticket::Article.create!(
- ticket_id: ticket.id,
- in_reply_to: '123456789',
- body: "Will call you later #{rand_word}!",
- type: Ticket::Article::Type.find_by(name: 'twitter direct-message'),
- sender: Ticket::Article::Sender.find_by(name: 'Agent'),
- internal: false,
- updated_by_id: 1,
- created_by_id: 1,
- )
- end
- assert_equal('twitter to: parameter is missing', reply.message)
- end
- test 'd track_retweets enabled' do
- # enable track_retweets
- channel[:options]['sync']['track_retweets'] = true
- channel.save!
- client = Twitter::REST::Client.new do |config|
- config.consumer_key = consumer_key
- config.consumer_secret = consumer_secret
- config.access_token = system_token
- config.access_token_secret = system_token_secret
- end
- hash = "#{hash_tag1} ##{hash_gen}"
- text = "Retweet me - I'm #{system_login} - #{rand_word}... #{hash}"
- tweet = client.update(text)
- client = Twitter::REST::Client.new(
- consumer_key: consumer_key,
- consumer_secret: consumer_secret,
- access_token: customer_token,
- access_token_secret: customer_token_secret
- )
- retweet = client.retweet(tweet).first
- # fetch check system account
- sleep 15
- article = nil
- 2.times do
- Channel.fetch
- # check if ticket and article has been created
- article = Ticket::Article.find_by(message_id: retweet.id)
- break if article
- sleep 10
- end
- assert(article, "retweet article '#{text}' created")
- end
- test 'e track_retweets disabled' do
- # disable track_retweets
- channel[:options]['sync']['track_retweets'] = false
- channel.save!
- client = Twitter::REST::Client.new do |config|
- config.consumer_key = consumer_key
- config.consumer_secret = consumer_secret
- config.access_token = system_token
- config.access_token_secret = system_token_secret
- end
- hash = "#{hash_tag1} ##{hash_gen}"
- text = "Retweet me - I'm #{system_login} - #{rand_word}... #{hash}"
- tweet = client.update(text)
- client = Twitter::REST::Client.new(
- consumer_key: consumer_key,
- consumer_secret: consumer_secret,
- access_token: customer_token,
- access_token_secret: customer_token_secret
- )
- retweet = client.retweet(tweet).first
- # fetch check system account
- sleep 15
- article = nil
- 2.times do
- Channel.fetch
- # check if ticket and article has been created
- article = Ticket::Article.find_by(message_id: retweet.id)
- break if article
- sleep 10
- end
- assert_nil(article, "retweet article '#{text}' not created")
- end
- test 'f streaming test' do
- thread = Thread.new do
- Channel.stream
- end
- sleep 10
- # new tweet I - by me_bauer
- client = Twitter::REST::Client.new do |config|
- config.consumer_key = consumer_key
- config.consumer_secret = consumer_secret
- config.access_token = customer_token
- config.access_token_secret = customer_token_secret
- end
- hash = "#{hash_tag1} ##{hash_gen}"
- text = "Today... #{rand_word} #{hash}"
- tweet = client.update(
- text,
- )
- article = nil
- 5.times do
- Scheduler.worker(true)
- article = Ticket::Article.find_by(message_id: tweet.id)
- break if article
- ActiveRecord::Base.clear_all_connections!
- ActiveRecord::Base.connection.query_cache.clear
- sleep 10
- end
- assert(article, "article from customer with text '#{text}' message_id '#{tweet.id}' created")
- assert_equal(customer_login, article.from, 'ticket article from')
- assert_nil(article.to, 'ticket article to')
- # new tweet II - by me_bauer
- client = Twitter::REST::Client.new do |config|
- config.consumer_key = consumer_key
- config.consumer_secret = consumer_secret
- config.access_token = customer_token
- config.access_token_secret = customer_token_secret
- end
- hash = "#{hash_tag1} ##{rand(999_999)}"
- text = "Today... #{rand_word} #{hash}"
- tweet = client.update(
- text,
- )
- article = nil
- 5.times do
- Scheduler.worker(true)
- article = Ticket::Article.find_by(message_id: tweet.id)
- break if article
- ActiveRecord::Base.clear_all_connections!
- ActiveRecord::Base.connection.query_cache.clear
- sleep 10
- end
- assert(article, "article from customer with text '#{text}' message_id '#{tweet.id}' created")
- assert_equal(customer_login, article.from, 'ticket article from')
- assert_nil(article.to, 'ticket article to')
- # send reply
- reply_text = "RE #{text}"
- article = Ticket::Article.create!(
- ticket_id: article.ticket_id,
- body: reply_text,
- type: Ticket::Article::Type.find_by(name: 'twitter status'),
- sender: Ticket::Article::Sender.find_by(name: 'Agent'),
- internal: false,
- updated_by_id: 1,
- created_by_id: 1,
- )
- Scheduler.worker(true)
- article = Ticket::Article.find(article.id)
- assert(article, "outbound article created, text: #{reply_text}")
- assert_equal(system_login, article.from, 'ticket article from')
- assert_equal('', article.to, 'ticket article to')
- sleep 5
- tweet_found = false
- client.user_timeline(system_login_without_at).each do |local_tweet|
- sleep 10
- next if local_tweet.id.to_s != article.message_id.to_s
- tweet_found = true
- break
- end
- assert(tweet_found, "found outbound '#{reply_text}' tweet '#{article.message_id}'")
- count = Ticket::Article.where(message_id: article.message_id).count
- assert_equal(1, count, "tweet #{article.message_id}")
- channel_id = article.ticket.preferences[:channel_id]
- assert(channel_id)
- channel = Channel.find(channel_id)
- assert_equal('', channel.last_log_out)
- assert_equal('ok', channel.status_out)
- # get dm via stream
- client = Twitter::REST::Client.new(
- consumer_key: consumer_key,
- consumer_secret: consumer_secret,
- access_token: customer_token,
- access_token_secret: customer_token_secret
- )
- hash = "#citheo44#{rand(999_999)}"
- text = "How about the #{rand_word}? #{hash}"
- dm = client.create_direct_message(
- system_login_without_at,
- text,
- )
- assert(dm, "dm with ##{hash} created")
- article = nil
- 5.times do
- Scheduler.worker(true)
- article = Ticket::Article.find_by(message_id: dm.id)
- break if article
- sleep 10
- end
- assert(article, "inbound article '#{text}' message_id '#{dm.id}' created")
- assert_equal(customer_login, article.from, 'ticket article from')
- assert_equal(system_login, article.to, 'ticket article to')
- thread.exit
- thread.join
- end
- test 'g streaming test retweet enabled' do
- thread = Thread.new do
- # enable track_retweets in current thread
- # since Threads are not spawned in the same scope
- # as the current test is running in .....
- channel_thread = Channel.find(channel.id)
- channel_thread[:options]['sync']['track_retweets'] = true
- channel_thread.save!
- Channel.stream
- end
- sleep 10
- client = Twitter::REST::Client.new do |config|
- config.consumer_key = consumer_key
- config.consumer_secret = consumer_secret
- config.access_token = system_token
- config.access_token_secret = system_token_secret
- end
- hash = "#{hash_tag1} ##{hash_gen}"
- text = "Retweet me - I'm #{system_login} - #{rand_word}... #{hash}"
- tweet = client.update(text)
- client = Twitter::REST::Client.new(
- consumer_key: consumer_key,
- consumer_secret: consumer_secret,
- access_token: customer_token,
- access_token_secret: customer_token_secret
- )
- retweet = client.retweet(tweet).first
- # fetch check system account
- sleep 15
- article = nil
- 2.times do
- Channel.fetch
- # check if ticket and article has been created
- article = Ticket::Article.find_by(message_id: retweet.id)
- break if article
- ActiveRecord::Base.clear_all_connections!
- ActiveRecord::Base.connection.query_cache.clear
- sleep 10
- end
- assert(article, "retweet article '#{text}' created")
- thread.exit
- thread.join
- end
- test 'h streaming test retweet disabled' do
- thread = Thread.new do
- # disable track_retweets in current thread
- # since Threads are not spawned in the same scope
- # as the current test is running in .....
- channel_thread = Channel.find(channel.id)
- channel_thread[:options]['sync']['track_retweets'] = false
- channel_thread.save!
- Channel.stream
- end
- sleep 10
- client = Twitter::REST::Client.new do |config|
- config.consumer_key = consumer_key
- config.consumer_secret = consumer_secret
- config.access_token = system_token
- config.access_token_secret = system_token_secret
- end
- hash = "#{hash_tag1} ##{hash_gen}"
- text = "Retweet me - I'm #{system_login} - #{rand_word}... #{hash}"
- tweet = client.update(text)
- client = Twitter::REST::Client.new(
- consumer_key: consumer_key,
- consumer_secret: consumer_secret,
- access_token: customer_token,
- access_token_secret: customer_token_secret
- )
- retweet = client.retweet(tweet).first
- # fetch check system account
- article = nil
- 4.times do
- # check if ticket and article has been created
- article = Ticket::Article.find_by(message_id: retweet.id)
- break if article
- sleep 10
- end
- assert_nil(article, "retweet article '#{text}' not created")
- thread.exit
- thread.join
- end
- test 'i restart stream after config of channel has changed' do
- hash = "#citheo#{rand(999)}"
- thread = Thread.new do
- Channel.stream
- sleep 10
- item = {
- term: hash,
- group_id: group.id,
- }
- channel_thread = Channel.find(channel.id)
- channel_thread[:options]['sync']['search'].push item
- channel_thread.save!
- end
- sleep 60
- # new tweet - by me_bauer
- client = Twitter::REST::Client.new do |config|
- config.consumer_key = consumer_key
- config.consumer_secret = consumer_secret
- config.access_token = customer_token
- config.access_token_secret = customer_token_secret
- end
- hash = "#{hash_tag1} ##{hash_gen}"
- text = "Today... #{rand_word} #{hash}"
- tweet = client.update(
- text,
- )
- article = nil
- 5.times do
- Channel.fetch
- Scheduler.worker(true)
- article = Ticket::Article.find_by(message_id: tweet.id)
- break if article
- ActiveRecord::Base.clear_all_connections!
- ActiveRecord::Base.connection.query_cache.clear
- sleep 10
- end
- assert(article, "article from customer with text '#{text}' message_id '#{tweet.id}' created")
- assert_equal(customer_login, article.from, 'ticket article from')
- assert_nil(article.to, 'ticket article to')
- thread.exit
- thread.join
- channel_thread = Channel.find(channel.id)
- channel_thread[:options]['sync']['search'].pop
- channel_thread.save!
- end
- def hash_gen
- rand(999).to_s + (0...10).map { ('a'..'z').to_a[rand(26)] }.join
- end
- def rand_word
- [
- 'dog',
- 'cat',
- 'house',
- 'home',
- 'yesterday',
- 'tomorrow',
- 'new york',
- 'berlin',
- 'coffee script',
- 'java script',
- 'bob smith',
- 'be open',
- 'really nice',
- 'stay tuned',
- 'be a good boy',
- 'invent new things',
- ].sample
- end
- end
|