twitter_browser_test.rb 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301
  1. require 'browser_test_helper'
  2. class TwitterBrowserTest < TestCase
  3. def test_add_config
  4. # app config
  5. if !ENV['TWITTER_BT_CONSUMER_KEY']
  6. raise "ERROR: Need TWITTER_BT_CONSUMER_KEY - hint TWITTER_BT_CONSUMER_KEY='1234'"
  7. end
  8. consumer_key = ENV['TWITTER_BT_CONSUMER_KEY']
  9. if !ENV['TWITTER_BT_CONSUMER_SECRET']
  10. raise "ERROR: Need TWITTER_BT_CONSUMER_SECRET - hint TWITTER_BT_CONSUMER_SECRET='1234'"
  11. end
  12. consumer_secret = ENV['TWITTER_BT_CONSUMER_SECRET']
  13. if !ENV['TWITTER_BT_USER_LOGIN']
  14. raise "ERROR: Need TWITTER_BT_USER_LOGIN - hint TWITTER_BT_USER_LOGIN='1234'"
  15. end
  16. twitter_user_login = ENV['TWITTER_BT_USER_LOGIN']
  17. if !ENV['TWITTER_BT_USER_PW']
  18. raise "ERROR: Need TWITTER_BT_USER_PW - hint TWITTER_BT_USER_PW='1234'"
  19. end
  20. twitter_user_pw = ENV['TWITTER_BT_USER_PW']
  21. if !ENV['TWITTER_BT_CUSTOMER_TOKEN']
  22. raise "ERROR: Need TWITTER_BT_CUSTOMER_TOKEN - hint TWITTER_BT_CUSTOMER_TOKEN='1234'"
  23. end
  24. twitter_customer_token = ENV['TWITTER_BT_CUSTOMER_TOKEN']
  25. if !ENV['TWITTER_BT_CUSTOMER_TOKEN_SECRET']
  26. raise "ERROR: Need TWITTER_BT_CUSTOMER_TOKEN_SECRET - hint TWITTER_BT_CUSTOMER_TOKEN_SECRET='1234'"
  27. end
  28. twitter_customer_token_secret = ENV['TWITTER_BT_CUSTOMER_TOKEN_SECRET']
  29. hash = "#sweet#{hash_gen}"
  30. @browser = browser_instance
  31. login(
  32. username: 'master@example.com',
  33. password: 'test',
  34. url: browser_url,
  35. auto_wizard: true,
  36. )
  37. tasks_close_all()
  38. click(css: 'a[href="#manage"]')
  39. click(css: '.content.active a[href="#channels/twitter"]')
  40. click(css: '.content.active .js-configApp')
  41. sleep 2
  42. set(
  43. css: '.content.active .modal [name=consumer_key]',
  44. value: consumer_key,
  45. )
  46. set(
  47. css: '.content.active .modal [name=consumer_secret]',
  48. value: 'wrong',
  49. )
  50. click(css: '.content.active .modal .js-submit')
  51. watch_for(
  52. css: '.content.active .modal .alert',
  53. value: 'Authorization Required',
  54. )
  55. set(
  56. css: '.content.active .modal [name=consumer_secret]',
  57. value: consumer_secret,
  58. )
  59. click(css: '.content.active .modal .js-submit')
  60. watch_for_disappear(
  61. css: '.content.active .modal .alert',
  62. value: 'Authorization Required',
  63. )
  64. watch_for(
  65. css: '.content.active .js-new',
  66. value: 'add account',
  67. )
  68. click(css: '.content.active .js-configApp')
  69. set(
  70. css: '.content.active .modal [name=consumer_secret]',
  71. value: 'wrong',
  72. )
  73. click(css: '.content.active .modal .js-submit')
  74. watch_for(
  75. css: '.content.active .modal .alert',
  76. value: 'Authorization Required',
  77. )
  78. set(
  79. css: '.content.active .modal [name=consumer_secret]',
  80. value: consumer_secret,
  81. )
  82. click(css: '.content.active .modal .js-submit')
  83. watch_for_disappear(
  84. css: '.content.active .modal .alert',
  85. value: 'Authorization Required',
  86. )
  87. watch_for(
  88. css: '.content.active .js-new',
  89. value: 'add account',
  90. )
  91. click(css: '.content.active .js-new')
  92. sleep 10
  93. set(
  94. css: '#username_or_email',
  95. value: twitter_user_login,
  96. no_click: true, # <label> other element would receive the click
  97. )
  98. set(
  99. css: '#password',
  100. value: twitter_user_pw,
  101. no_click: true, # <label> other element would receive the click
  102. )
  103. click(css: '#allow')
  104. #watch_for(
  105. # css: '.notice.callback',
  106. # value: 'Redirecting you back to the application',
  107. #)
  108. watch_for(
  109. css: '.content.active .modal',
  110. value: 'Search Terms',
  111. )
  112. # add hash tag to search
  113. click(css: '.content.active .modal .js-searchTermAdd')
  114. set(css: '.content.active .modal [name="search::term"]', value: hash)
  115. select(css: '.content.active .modal [name="search::group_id"]', value: 'Users')
  116. click(css: '.content.active .modal .js-submit')
  117. modal_disappear
  118. watch_for(
  119. css: '.content.active',
  120. value: 'Bob Mutschler',
  121. )
  122. watch_for(
  123. css: '.content.active',
  124. value: "@#{twitter_user_login}",
  125. )
  126. exists(
  127. css: '.content.active .main .action:nth-child(1)'
  128. )
  129. exists_not(
  130. css: '.content.active .main .action:nth-child(2)'
  131. )
  132. # add account again
  133. click(css: '.content.active .js-new')
  134. sleep 10
  135. click(css: '#allow')
  136. watch_for(
  137. css: '.content.active .modal',
  138. value: 'Search Terms',
  139. )
  140. click(css: '.content.active .modal .js-close')
  141. watch_for(
  142. css: '.content.active',
  143. value: 'Bob Mutschler',
  144. )
  145. watch_for(
  146. css: '.content.active',
  147. value: "@#{twitter_user_login}",
  148. )
  149. exists(
  150. css: '.content.active .main .action:nth-child(1)'
  151. )
  152. exists_not(
  153. css: '.content.active .main .action:nth-child(2)'
  154. )
  155. # wait till new streaming of channel is active
  156. sleep 80
  157. # start tweet from customer
  158. client = Twitter::REST::Client.new do |config|
  159. config.consumer_key = consumer_key
  160. config.consumer_secret = consumer_secret
  161. config.access_token = twitter_customer_token
  162. config.access_token_secret = twitter_customer_token_secret
  163. end
  164. text = "Today #{rand_word}... #{hash} #{hash_gen}"
  165. tweet = client.update(
  166. text,
  167. )
  168. # watch till tweet is in app
  169. click(text: 'Overviews')
  170. # enable full overviews
  171. execute(
  172. js: '$(".content.active .sidebar").css("display", "block")',
  173. )
  174. click(text: 'Unassigned & Open')
  175. watch_for(
  176. css: '.content.active',
  177. value: hash,
  178. timeout: 36,
  179. )
  180. ticket_open_by_title(
  181. title: hash,
  182. )
  183. # reply via app
  184. click(css: '.content.active [data-type="twitterStatusReply"]')
  185. ticket_update(
  186. data: {
  187. body: '@dzucker6 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890',
  188. },
  189. do_not_submit: true,
  190. )
  191. click(
  192. css: '.content.active .js-submit',
  193. )
  194. sleep 10
  195. click(
  196. css: '.content.active .js-reset',
  197. )
  198. sleep 2
  199. match_not(
  200. css: '.content.active',
  201. value: '1234567890',
  202. )
  203. click(css: '.content.active [data-type="twitterStatusReply"]')
  204. sleep 2
  205. re_hash = "#{hash}re#{rand(99_999)}"
  206. ticket_update(
  207. data: {
  208. body: "@dzucker6 #{rand_word} reply #{re_hash} #{rand(999_999)}",
  209. },
  210. )
  211. sleep 20
  212. match(
  213. css: '.content.active .ticket-article',
  214. value: re_hash,
  215. )
  216. # watch till tweet reached customer
  217. sleep 10
  218. text = nil
  219. client.search(re_hash, result_type: 'mixed').collect do |local_tweet|
  220. text = local_tweet.text
  221. end
  222. assert(text)
  223. end
  224. def hash_gen
  225. (0...10).map { ('a'..'z').to_a[rand(26)] }.join + rand(999).to_s
  226. end
  227. def rand_word
  228. words = [
  229. 'dog',
  230. 'cat',
  231. 'house',
  232. 'home',
  233. 'yesterday',
  234. 'tomorrow',
  235. 'new york',
  236. 'berlin',
  237. 'coffee script',
  238. 'java script',
  239. 'bob smith',
  240. 'be open',
  241. 'really nice',
  242. 'stay tuned',
  243. 'be a good boy',
  244. 'invent new things',
  245. ]
  246. words[rand(words.length)]
  247. end
  248. end