From 3e0667e24dce867654d2a2e0471d5637ffb7f240 Mon Sep 17 00:00:00 2001 From: Scott Comer Date: Tue, 20 May 2014 09:46:45 -0500 Subject: [PATCH 1/3] added Scores.score_conns to help with making scores for tests; comments for usage of musician_filter; optional score_dt for Score.createx; betterify query for connection in scoring api --- ruby/lib/jam_ruby/models/score.rb | 6 ++++- ruby/lib/jam_ruby/models/search.rb | 24 ++++++++++++++--- .../jam_ruby/models/musician_search_spec.rb | 4 +-- ruby/spec/jam_ruby/models/score_spec.rb | 27 +++++++++++++++++++ web/app/controllers/api_scoring_controller.rb | 14 +++++----- web/app/controllers/api_search_controller.rb | 7 ++--- .../api_scoring_controller_spec.rb | 8 +++--- 7 files changed, 69 insertions(+), 21 deletions(-) diff --git a/ruby/lib/jam_ruby/models/score.rb b/ruby/lib/jam_ruby/models/score.rb index 570d409f4..9fce6a089 100644 --- a/ruby/lib/jam_ruby/models/score.rb +++ b/ruby/lib/jam_ruby/models/score.rb @@ -9,7 +9,7 @@ module JamRuby default_scope order('score_dt desc') - def self.createx(alocidispid, anodeid, aaddr, blocidispid, bnodeid, baddr, score, score_dt) + def self.createx(alocidispid, anodeid, aaddr, blocidispid, bnodeid, baddr, score, score_dt=nil) score_dt = Time.new.utc if score_dt.nil? Score.create(alocidispid: alocidispid, anodeid: anodeid, aaddr: aaddr, blocidispid: blocidispid, bnodeid: bnodeid, baddr: baddr, score: score, scorer: 0, score_dt: score_dt) Score.create(alocidispid: blocidispid, anodeid: bnodeid, aaddr: baddr, blocidispid: alocidispid, bnodeid: anodeid, baddr: aaddr, score: score, scorer: 1, score_dt: score_dt) if alocidispid != blocidispid @@ -25,5 +25,9 @@ module JamRuby return -1 if s.nil? return s.score end + + def self.score_conns(c1, c2, score) + self.createx(c1.locidispid, c1.client_id, c1.addr, c2.locidispid, c2.client_id, c2.addr, score) + end end end diff --git a/ruby/lib/jam_ruby/models/search.rb b/ruby/lib/jam_ruby/models/search.rb index 29931e17c..2274e1fd0 100644 --- a/ruby/lib/jam_ruby/models/search.rb +++ b/ruby/lib/jam_ruby/models/search.rb @@ -120,14 +120,32 @@ module JamRuby ordering.blank? ? keys[0] : keys.detect { |oo| oo.to_s == ordering } end - def self.musician_filter(params={}, current_user=nil) + # produce a list of musicians (users where musician is true) + # params: + # instrument - instrument to search for or blank + # handled by relation_pagination: + # page - page number to fetch (origin 1) + # per_page - number of entries per page + # handled by order_param: + # orderby - ??? (followed, plays, playing) + # handled by where_latlng: + # distance - defunct + # city - defunct + # remote_ip - defunct + def self.musician_filter(params={}, user=nil, conn=nil) rel = User.musicians unless (instrument = params[:instrument]).blank? rel = rel.joins("RIGHT JOIN musicians_instruments AS minst ON minst.user_id = users.id") .where(['minst.instrument_id = ? AND users.id IS NOT NULL', instrument]) end - # todo scott - rel = MaxMindGeo.where_latlng(rel, params, current_user) + locidispid = (conn ? conn.locidispid : (user ? user.last_jam_locidispid : 0)) + + # to find appropriate musicians we need to join users with connections to get to their locidispid, + # then join scores with alocidispid found above with the musicians' locidispid to weed out users + # with no scores or bad scores + + # todo scott - rel = MaxMindGeo.where_latlng(rel, params, user) sel_str = 'users.*' case ordering = self.order_param(params) @@ -157,7 +175,7 @@ module JamRuby srch = Search.new srch.search_type = :musicians_filter srch.page_num, srch.page_count = page, objs.total_pages - srch.musician_results_for_user(objs, current_user) + srch.musician_results_for_user(objs, user) end def self.relation_pagination(rel, params) diff --git a/ruby/spec/jam_ruby/models/musician_search_spec.rb b/ruby/spec/jam_ruby/models/musician_search_spec.rb index 40255b4a1..2a3ca0ced 100644 --- a/ruby/spec/jam_ruby/models/musician_search_spec.rb +++ b/ruby/spec/jam_ruby/models/musician_search_spec.rb @@ -3,8 +3,8 @@ require 'spec_helper' describe 'Musician search' do before(:each) do - @geocode1 = FactoryGirl.create(:geocoder) - @geocode2 = FactoryGirl.create(:geocoder) + # @geocode1 = FactoryGirl.create(:geocoder) + # @geocode2 = FactoryGirl.create(:geocoder) @users = [] @users << @user1 = FactoryGirl.create(:user) @users << @user2 = FactoryGirl.create(:user) diff --git a/ruby/spec/jam_ruby/models/score_spec.rb b/ruby/spec/jam_ruby/models/score_spec.rb index 84efb6127..604622b9e 100644 --- a/ruby/spec/jam_ruby/models/score_spec.rb +++ b/ruby/spec/jam_ruby/models/score_spec.rb @@ -92,4 +92,31 @@ describe Score do Score.findx(3456, 3456).should == -1 end + it "test shortcut for making scores from connections" do + user1 = FactoryGirl.create(:user) + conn1 = FactoryGirl.create(:connection, user: user1, addr: 0x01020304, locidispid: 5) + user2 = FactoryGirl.create(:user) + conn2 = FactoryGirl.create(:connection, user: user2, addr: 0x11121314, locidispid: 6) + user3 = FactoryGirl.create(:user) + conn3 = FactoryGirl.create(:connection, user: user3, addr: 0x21222324, locidispid: 7) + + Score.findx(5, 6).should == -1 + Score.findx(6, 5).should == -1 + Score.findx(5, 7).should == -1 + Score.findx(7, 5).should == -1 + Score.findx(6, 7).should == -1 + Score.findx(7, 6).should == -1 + + Score.score_conns(conn1, conn2, 12) + Score.score_conns(conn1, conn3, 13) + Score.score_conns(conn2, conn3, 23) + + Score.findx(5, 6).should == 12 + Score.findx(6, 5).should == 12 + Score.findx(5, 7).should == 13 + Score.findx(7, 5).should == 13 + Score.findx(6, 7).should == 23 + Score.findx(7, 6).should == 23 + end + end diff --git a/web/app/controllers/api_scoring_controller.rb b/web/app/controllers/api_scoring_controller.rb index 5ba61122d..4178fac6b 100644 --- a/web/app/controllers/api_scoring_controller.rb +++ b/web/app/controllers/api_scoring_controller.rb @@ -7,11 +7,10 @@ class ApiScoringController < ApiController clientid = params[:clientid] if clientid.nil? then render :json => {message: 'clientid not specified'}, :status => 400; return end - conn = Connection.where(client_id: clientid).first + conn = Connection.where(client_id: clientid, user_id: current_user.id).first if conn.nil? then render :json => {message: 'session not found'}, :status => 404; return end - if !current_user.id.eql?(conn.user.id) then render :json => {message: 'session not owned by user'}, :status => 403; return end + # if !current_user.id.eql?(conn.user.id) then render :json => {message: 'session not owned by user'}, :status => 403; return end - # todo this method is a stub #puts "ApiScoringController#work(#{clientid}) => locidispid #{c.locidispid}" result_client_id = JamRuby::GetWork.get_work(conn.locidispid) #result_client_id = clientid+'peer' @@ -23,11 +22,10 @@ class ApiScoringController < ApiController clientid = params[:clientid] if clientid.nil? then render :json => {message: 'clientid not specified'}, :status => 400; return end - conn = Connection.where(client_id: clientid).first + conn = Connection.where(client_id: clientid, user_id: current_user.id).first if conn.nil? then render :json => {message: 'session not found'}, :status => 404; return end - if !current_user.id.eql?(conn.user.id) then render :json => {message: 'session not owned by user'}, :status => 403; return end + # if !current_user.id.eql?(conn.user.id) then render :json => {message: 'session not owned by user'}, :status => 403; return end - # todo this method is a stub result_client_ids = JamRuby::GetWork.get_work_list(conn.locidispid) #result_client_ids = [clientid+'peer1', clientid+'peer2'] @@ -61,10 +59,10 @@ class ApiScoringController < ApiController if !score.is_a? Numeric then render :json => {message: 'score not valid numeric'}, :status => 400; return end - aconn = Connection.where(client_id: aclientid).first + aconn = Connection.where(client_id: aclientid, user_id: current_user.id).first if aconn.nil? then render :json => {message: 'a\'s session not found'}, :status => 404; return end if aAddr != aconn.addr then render :json => {message: 'a\'s session addr does not match aAddr'}, :status => 403; return end - if !current_user.id.eql?(aconn.user.id) then render :json => {message: 'a\'s session not owned by user'}, :status => 403; return end + # if !current_user.id.eql?(aconn.user.id) then render :json => {message: 'a\'s session not found'}, :status => 403; return end bconn = Connection.where(client_id: bclientid).first if bconn.nil? then render :json => {message: 'b\'s session not found'}, :status => 404; return end diff --git a/web/app/controllers/api_search_controller.rb b/web/app/controllers/api_search_controller.rb index 81baf7b6c..0ed3f9fd0 100644 --- a/web/app/controllers/api_search_controller.rb +++ b/web/app/controllers/api_search_controller.rb @@ -9,13 +9,14 @@ class ApiSearchController < ApiController if 1 == params[Search::PARAM_MUSICIAN].to_i || 1 == params[Search::PARAM_BAND].to_i query = params.clone query[:remote_ip] = request.remote_ip - if 1 == params[Search::PARAM_MUSICIAN].to_i - @search = Search.musician_filter(query, current_user) + if 1 == query[Search::PARAM_MUSICIAN].to_i + clientid = params[:clientid] + conn = (clientid ? Connection.where(client_id: clientid, user_id: current_user.id).first : nil) + @search = Search.musician_filter(query, current_user, conn) else @search = Search.band_filter(query, current_user) end respond_with @search, responder: ApiResponder, :status => 200 - elsif 1 == params[Search::PARAM_SESSION_INVITE].to_i @search = Search.session_invite_search(params[:query], current_user) else diff --git a/web/spec/controllers/api_scoring_controller_spec.rb b/web/spec/controllers/api_scoring_controller_spec.rb index 7a3b71911..11df2af83 100644 --- a/web/spec/controllers/api_scoring_controller_spec.rb +++ b/web/spec/controllers/api_scoring_controller_spec.rb @@ -103,7 +103,7 @@ describe ApiScoringController do response.should_not be_success json = JSON.parse(response.body, :symbolize_names => true) json.length.should == 1 - json[:message].should eql('session not owned by user') + json[:message].should eql('session not found') end it 'try work with mike login and mary' do @@ -112,7 +112,7 @@ describe ApiScoringController do response.should_not be_success json = JSON.parse(response.body, :symbolize_names => true) json.length.should == 1 - json[:message].should eql('session not owned by user') + json[:message].should eql('session not found') end end @@ -181,7 +181,7 @@ describe ApiScoringController do response.should_not be_success json = JSON.parse(response.body, :symbolize_names => true) json.length.should == 1 - json[:message].should eql('session not owned by user') + json[:message].should eql('session not found') end end @@ -302,7 +302,7 @@ describe ApiScoringController do response.should_not be_success json = JSON.parse(response.body, :symbolize_names => true) json.length.should == 1 - json[:message].should eql('a\'s session not owned by user') + json[:message].should eql('a\'s session not found') end it 'record with mary login, mary, mary_addr, mary, mary_addr, score' do From 4a76e0c9832b84629bf2cdb17faba56f4718169e Mon Sep 17 00:00:00 2001 From: Scott Comer Date: Wed, 21 May 2014 14:05:45 -0500 Subject: [PATCH 2/3] get_work has a larger radius and excludes the current connections address --- db/manifest | 1 + db/up/update_get_work_for_larger_radius.sql | 16 +++++++ resetdb.sh | 2 +- ruby/lib/jam_ruby/models/get_work.rb | 8 ++-- ruby/lib/jam_ruby/models/score.rb | 2 + ruby/spec/jam_ruby/models/get_work_spec.rb | 4 +- web/app/controllers/api_scoring_controller.rb | 4 +- .../api_scoring_controller_spec.rb | 47 ++++++++++--------- 8 files changed, 54 insertions(+), 30 deletions(-) create mode 100644 db/up/update_get_work_for_larger_radius.sql diff --git a/db/manifest b/db/manifest index 0eed9fba8..899773187 100755 --- a/db/manifest +++ b/db/manifest @@ -155,3 +155,4 @@ session_ratings.sql scheduled_sessions.sql add_last_jam_user_fields.sql remove_lat_lng_user_fields.sql +update_get_work_for_larger_radius.sql diff --git a/db/up/update_get_work_for_larger_radius.sql b/db/up/update_get_work_for_larger_radius.sql new file mode 100644 index 000000000..f2edb5123 --- /dev/null +++ b/db/up/update_get_work_for_larger_radius.sql @@ -0,0 +1,16 @@ +DROP FUNCTION get_work (mylocidispid BIGINT); +CREATE FUNCTION get_work (mylocidispid BIGINT, myaddr BIGINT) RETURNS TABLE (client_id VARCHAR(64)) ROWS 5 VOLATILE AS $$ +BEGIN + CREATE TEMPORARY TABLE foo (locidispid BIGINT, locid INT); + INSERT INTO foo SELECT DISTINCT locidispid, locidispid/1000000 FROM connections WHERE client_type = 'client'; + DELETE FROM foo WHERE locidispid IN (SELECT DISTINCT blocidispid FROM current_scores WHERE alocidispid = mylocidispid AND (current_timestamp - score_dt) < INTERVAL '24 hours'); + DELETE FROM foo WHERE locid NOT IN (SELECT locid FROM geoiplocations WHERE geog && st_buffer((SELECT geog FROM geoiplocations WHERE locid = mylocidispid/1000000), 4023360)); + CREATE TEMPORARY TABLE bar (client_id VARCHAR(64), locidispid BIGINT, r DOUBLE PRECISION); + INSERT INTO bar SELECT l.client_id, l.locidispid, random() FROM connections l, foo f WHERE l.locidispid = f.locidispid AND l.client_type = 'client' AND addr != myaddr; + DROP TABLE foo; + DELETE FROM bar b WHERE r != (SELECT MAX(r) FROM bar b0 WHERE b0.locidispid = b.locidispid); + RETURN QUERY SELECT b.client_id FROM bar b ORDER BY r LIMIT 5; + DROP TABLE bar; + RETURN; +END; +$$ LANGUAGE plpgsql; diff --git a/resetdb.sh b/resetdb.sh index 5a06c1ff0..10b0bee88 100755 --- a/resetdb.sh +++ b/resetdb.sh @@ -4,4 +4,4 @@ dropdb jam_db_build dropdb jam_ruby_test dropdb jam_web_test dropdb jam_websocket_test -createdb -Upostgres jam +sudo su postgres -c "createdb jam" diff --git a/ruby/lib/jam_ruby/models/get_work.rb b/ruby/lib/jam_ruby/models/get_work.rb index f82ca00f4..2d52615c8 100644 --- a/ruby/lib/jam_ruby/models/get_work.rb +++ b/ruby/lib/jam_ruby/models/get_work.rb @@ -3,15 +3,15 @@ module JamRuby self.table_name = "connections" - def self.get_work(mylocidispid) - list = self.get_work_list(mylocidispid) + def self.get_work(mylocidispid, myaddr) + list = self.get_work_list(mylocidispid, myaddr) return nil if list.nil? return nil if list.length == 0 return list[0] end - def self.get_work_list(mylocidispid) - r = GetWork.select(:client_id).find_by_sql("select get_work(#{mylocidispid}) as client_id") + def self.get_work_list(mylocidispid, myaddr) + r = GetWork.select(:client_id).find_by_sql("select get_work(#{mylocidispid}, #{myaddr}) as client_id") #puts("r = #{r}") a = r.map {|i| i.client_id} #puts("a = #{a}") diff --git a/ruby/lib/jam_ruby/models/score.rb b/ruby/lib/jam_ruby/models/score.rb index 9fce6a089..962acd7c1 100644 --- a/ruby/lib/jam_ruby/models/score.rb +++ b/ruby/lib/jam_ruby/models/score.rb @@ -11,6 +11,8 @@ module JamRuby def self.createx(alocidispid, anodeid, aaddr, blocidispid, bnodeid, baddr, score, score_dt=nil) score_dt = Time.new.utc if score_dt.nil? + score = score.ceil + raise "score must be positive" if score <= 0 Score.create(alocidispid: alocidispid, anodeid: anodeid, aaddr: aaddr, blocidispid: blocidispid, bnodeid: bnodeid, baddr: baddr, score: score, scorer: 0, score_dt: score_dt) Score.create(alocidispid: blocidispid, anodeid: bnodeid, aaddr: baddr, blocidispid: alocidispid, bnodeid: anodeid, baddr: aaddr, score: score, scorer: 1, score_dt: score_dt) if alocidispid != blocidispid end diff --git a/ruby/spec/jam_ruby/models/get_work_spec.rb b/ruby/spec/jam_ruby/models/get_work_spec.rb index 9f8349b33..4e12d2ab0 100644 --- a/ruby/spec/jam_ruby/models/get_work_spec.rb +++ b/ruby/spec/jam_ruby/models/get_work_spec.rb @@ -7,13 +7,13 @@ describe GetWork do end it "get_work_1" do - x = GetWork.get_work(1) + x = GetWork.get_work(1, 0) #puts x.inspect x.should be_nil end it "get_work_list_1" do - x = GetWork.get_work_list(1) + x = GetWork.get_work_list(1, 0) #puts x.inspect x.should eql([]) end diff --git a/web/app/controllers/api_scoring_controller.rb b/web/app/controllers/api_scoring_controller.rb index 4178fac6b..fa9f042b1 100644 --- a/web/app/controllers/api_scoring_controller.rb +++ b/web/app/controllers/api_scoring_controller.rb @@ -12,7 +12,7 @@ class ApiScoringController < ApiController # if !current_user.id.eql?(conn.user.id) then render :json => {message: 'session not owned by user'}, :status => 403; return end #puts "ApiScoringController#work(#{clientid}) => locidispid #{c.locidispid}" - result_client_id = JamRuby::GetWork.get_work(conn.locidispid) + result_client_id = JamRuby::GetWork.get_work(conn.locidispid, conn.addr) #result_client_id = clientid+'peer' render :json => {:clientid => result_client_id}, :status => 200 @@ -26,7 +26,7 @@ class ApiScoringController < ApiController if conn.nil? then render :json => {message: 'session not found'}, :status => 404; return end # if !current_user.id.eql?(conn.user.id) then render :json => {message: 'session not owned by user'}, :status => 403; return end - result_client_ids = JamRuby::GetWork.get_work_list(conn.locidispid) + result_client_ids = JamRuby::GetWork.get_work_list(conn.locidispid, conn.addr) #result_client_ids = [clientid+'peer1', clientid+'peer2'] render :json => {:clientids => result_client_ids}, :status => 200 diff --git a/web/spec/controllers/api_scoring_controller_spec.rb b/web/spec/controllers/api_scoring_controller_spec.rb index 11df2af83..eae99ebd9 100644 --- a/web/spec/controllers/api_scoring_controller_spec.rb +++ b/web/spec/controllers/api_scoring_controller_spec.rb @@ -9,15 +9,15 @@ describe ApiScoringController do MARY_IP_ADDRESS = '75.92.54.210' # 1264334546, 4B.5C.36.D2 MARY_ADDR = 1264334546 - MARY_LOCIDISPID = 17192008423 + MARY_LOCIDISPID = 1807000004 MIKE_IP_ADDRESS = '173.172.108.1' # 2913758209, AD.AC.6C.01 MIKE_ADDR = 2913758209 - MIKE_LOCIDISPID = 17192043640 + MIKE_LOCIDISPID = 1539000002 JOHN_IP_ADDRESS = '255.255.1.2' # 4294902018, FF.FF.01.02 JOHN_ADDR = 4294902018 - JOHN_LOCIDISPID = 0 + JOHN_LOCIDISPID = 98765432 before do @mary = FactoryGirl.create(:user, first_name: 'mary') @@ -83,8 +83,9 @@ describe ApiScoringController do response.should be_success json = JSON.parse(response.body, :symbolize_names => true) json.length.should == 1 - json[:clientid].should_not be_nil - [@mary_client_id, @mike_client_id].should include(json[:clientid]) + clientid = json[:clientid] + clientid.should_not be_nil + [@mike_client_id].should include(clientid) end it 'try work with mike login and mike' do @@ -93,8 +94,9 @@ describe ApiScoringController do response.should be_success json = JSON.parse(response.body, :symbolize_names => true) json.length.should == 1 - json[:clientid].should_not be_nil - [@mary_client_id, @mike_client_id].should include(json[:clientid]) + clientid = json[:clientid] + clientid.should_not be_nil + [@mary_client_id].should include(clientid) end it 'try work with mary login and mike' do @@ -152,13 +154,11 @@ describe ApiScoringController do response.should be_success json = JSON.parse(response.body, :symbolize_names => true) json.length.should == 1 - json[:clientids].should_not be_nil - json[:clientids].should_receive :length - json[:clientids].length == 2 - [@mary_client_id, @mike_client_id].should include(json[:clientids][0]) - [@mary_client_id, @mike_client_id].should include(json[:clientids][1]) - json[:clientids][0].should_not eql(json[:clientids][1]) - + clientids = json[:clientids] + clientids.should_not be_nil + clientids.should respond_to :length + clientids.length.should == 1 + [@mike_client_id].should include(clientids[0]) end it 'try worklist with mike login and mike' do @@ -167,12 +167,11 @@ describe ApiScoringController do response.should be_success json = JSON.parse(response.body, :symbolize_names => true) json.length.should == 1 - json[:clientids].should_not be_nil - json[:clientids].should_receive :length - json[:clientids].length == 2 - [@mary_client_id, @mike_client_id].should include(json[:clientids][0]) - [@mary_client_id, @mike_client_id].should include(json[:clientids][1]) - json[:clientids][0].should_not eql(json[:clientids][1]) + clientids = json[:clientids] + clientids.should_not be_nil + clientids.should respond_to :length + clientids.length.should == 1 + [@mary_client_id].should include(clientids[0]) end it 'try worklist with mary login and mike' do @@ -359,12 +358,15 @@ describe ApiScoringController do json[:message].should eql('b\'s location or isp not found') end - it 'record with mary login, mary, mary_addr, mike, mike_addr, score' do + it 'record with mary login, mary, mary_addr, mike, mike_addr, score (integer)' do controller.current_user = @mary post :record, {:format => 'json', :aclientid => @mary_client_id, :aAddr => MARY_IP_ADDRESS, :bclientid => @mike_client_id, :bAddr => MIKE_IP_ADDRESS, :score => 20} response.should be_success json = JSON.parse(response.body, :symbolize_names => true) json.length.should == 0 + score = Score.findx(MARY_LOCIDISPID, MIKE_LOCIDISPID) + score.should_not be_nil + score.should eq(20) end it 'record with mary login, mary, mary_addr, mike, mike_addr, score (floating pt)' do @@ -373,6 +375,9 @@ describe ApiScoringController do response.should be_success json = JSON.parse(response.body, :symbolize_names => true) json.length.should == 0 + score = Score.findx(MARY_LOCIDISPID, MIKE_LOCIDISPID) + score.should_not be_nil + score.should eq(22) end end From dc9b17fa46578d294fa51d5a6e769f29509a9243 Mon Sep 17 00:00:00 2001 From: Anthony Davis Date: Wed, 21 May 2014 21:51:28 +0000 Subject: [PATCH 3/3] production_spec.rb moved to 'monitor' subproject --- web/spec/features/production_spec.rb | 92 ---------------------------- 1 file changed, 92 deletions(-) delete mode 100644 web/spec/features/production_spec.rb diff --git a/web/spec/features/production_spec.rb b/web/spec/features/production_spec.rb deleted file mode 100644 index 152bb94bc..000000000 --- a/web/spec/features/production_spec.rb +++ /dev/null @@ -1,92 +0,0 @@ -require 'spec_helper' - -# these tests MUST be idempotent and DO use actual production user accounts on www -www = 'http://www.jamkazam.com' - -describe "Production site at #{www}", :test_www => true, :js => true, :type => :feature, :capybara_feature => true do - - 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_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 -