jam-cloud/monitor/spec/production_spec.rb

96 lines
3.3 KiB
Ruby
Raw Normal View History

2014-05-07 03:35:00 +00:00
require 'spec_helper'
# these tests should be idempotent, and not spammy to other JK users
# because they DO use actual production user accounts on www (see the TestUsers below)
2014-05-07 03:35:00 +00:00
# Jenkins executes rspec on this folder every 15 minutes or so.
# SO don't use this to test something like a public session unless you want all the world to see
www = ENV['MONITOR_URL'] || 'http://www.jamkazam.com'
describe "Deployed site at #{www}", :js => true, :type => :feature, :capybara_feature => true do
2014-05-07 03:35:00 +00:00
subject { page }
before(:all) do
Capybara.javascript_driver = :poltergeist
Capybara.current_driver = Capybara.javascript_driver
Capybara.app_host = www
Capybara.run_server = false
Capybara.default_wait_time = 10
end
TestUser = Class.new do
attr_accessor :email, :password, :first_name, :last_name, :id
def initialize(h)
h.each {|k,v| send("#{k}=",v)}
end
alias :to_s :first_name
def name
first_name + ' ' + last_name
end
end
user1 = TestUser.new({ email: 'anthony+jim@jamkazam.com', password: 'j4m!t3st3r', first_name: 'Jim', last_name: 'Smith', id: '68e8eea2-140d-44c1-b711-10d07ce70f96' })
user2 = TestUser.new({ email: 'anthony+john@jamkazam.com', password: 'j4m!t3st3r', first_name: 'John', last_name: 'Jones', id: '5bbcf689-2f73-452d-815a-c4f44e9e7f3e' })
# before(:each) do
# emulate_client
# end
it "is possible for #{user1} to sign in and not get disconnected within 30 seconds" do
in_client(user1) do
sign_in_poltergeist user1
repeat_for(30.seconds) do
expect(page).to_not have_selector('.no-websocket-connection') #looks for reconnect dialog every 1 second
end
end
end
it "is possible for #{user1} and #{user2} to see each other online, and to send messages" do
# this example heavily based on text_message_spec.rb in 'web'
2014-05-07 03:35:00 +00:00
in_client(user1) do
sign_in_poltergeist(user1)
end
test_message = "#{SecureRandom.uuid} - Hey #{user1}!"
test_response = "#{SecureRandom.uuid} - Hey yourself, #{user2}!"
test_goodbye = "#{SecureRandom.uuid} - OK bye!"
in_client(user2) do
sign_in_poltergeist(user2)
expect(page).to have_xpath(
"//div[@class='friend-name' and @user-id='#{user1.id}']/span[@class='friend-status']",
:text => "Available" )
site_search(user1.name, expand: true)
find("#search-results a[user-id=\"#{user1.id}\"][hoveraction=\"musician\"]", text: user1.name).hover_intent
find('#musician-hover #btnMessage').trigger(:click)
find('h1', text: 'conversation with ' + user1.name)
send_text_message(test_message)
end
in_client(user1) do
expect(page).to have_xpath(
"//div[@class='friend-name' and @user-id='#{user2.id}']/span[@class='friend-status']",
:text => "Available" )
find('#notification #ok-button').trigger(:click)
find('h1', text: 'conversation with ' + user2.name)
find('.previous-message-text', text: test_message)
send_text_message(test_response, close_on_send: true)
end
in_client(user2) do
find('.previous-message-text', text: test_response)
send_text_message(test_goodbye, close_on_send: true)
end
in_client(user1) { sign_out_poltergeist }
in_client(user2) { sign_out_poltergeist }
end
end