twitter_browser_test.rb 9.8 KB

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