wip new user recommendation email
This commit is contained in:
parent
46202a2373
commit
fad3b73d67
|
|
@ -0,0 +1,11 @@
|
||||||
|
class UserMatchEmailSendingsDefaultSentUserIds < ActiveRecord::Migration
|
||||||
|
def self.up
|
||||||
|
execute("ALTER TABLE public.user_match_email_sendings
|
||||||
|
ALTER COLUMN sent_user_ids SET DEFAULT array[]::varchar[];")
|
||||||
|
end
|
||||||
|
|
||||||
|
def self.down
|
||||||
|
execute("ALTER TABLE public.user_match_email_sendings
|
||||||
|
ALTER COLUMN sent_user_ids DROP DEFAULT;")
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
@ -3,7 +3,7 @@
|
||||||
execute(<<-SQL
|
execute(<<-SQL
|
||||||
CREATE TABLE public.user_match_email_sendings (
|
CREATE TABLE public.user_match_email_sendings (
|
||||||
id character varying(64) DEFAULT public.uuid_generate_v4() PRIMARY KEY NOT NULL,
|
id character varying(64) DEFAULT public.uuid_generate_v4() PRIMARY KEY NOT NULL,
|
||||||
sent_user_ids varchar[],
|
sent_user_ids text,
|
||||||
total_recipients integer,
|
total_recipients integer,
|
||||||
created_at timestamp without time zone DEFAULT now() NOT NULL,
|
created_at timestamp without time zone DEFAULT now() NOT NULL,
|
||||||
completed_at timestamp without time zone
|
completed_at timestamp without time zone
|
||||||
|
|
|
||||||
|
|
@ -342,6 +342,7 @@ require "jam_ruby/models/mobile_recording_upload"
|
||||||
require "jam_ruby/models/temp_token"
|
require "jam_ruby/models/temp_token"
|
||||||
require "jam_ruby/models/ad_campaign"
|
require "jam_ruby/models/ad_campaign"
|
||||||
require "jam_ruby/models/user_asset"
|
require "jam_ruby/models/user_asset"
|
||||||
|
require "jam_ruby/models/user_match_email_sending"
|
||||||
|
|
||||||
|
|
||||||
include Jampb
|
include Jampb
|
||||||
|
|
|
||||||
|
|
@ -407,7 +407,7 @@ module JamRuby
|
||||||
|
|
||||||
mail(:to => user.email, :subject => EmailNewMusicianMatch.subject) do |format|
|
mail(:to => user.email, :subject => EmailNewMusicianMatch.subject) do |format|
|
||||||
format.text
|
format.text
|
||||||
format.html
|
format.html{ render layout: "user_mailer_beta" }
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1 +1,72 @@
|
||||||
EMAIL BODY HERE: <%= @musicians_data.inspect -%>
|
<style>
|
||||||
|
.container{
|
||||||
|
width: 65%;
|
||||||
|
margin: 0 auto;
|
||||||
|
padding: 2em;
|
||||||
|
background-color: #fff;
|
||||||
|
font-size: 1.2rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
.row {
|
||||||
|
display: flex;
|
||||||
|
align-items: stretch;
|
||||||
|
justify-content: flex-start;
|
||||||
|
row-gap: 1em;
|
||||||
|
column-gap: 1em;
|
||||||
|
margin-top: 2em;
|
||||||
|
}
|
||||||
|
.row > div{
|
||||||
|
flex-grow: 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
.row .photo{
|
||||||
|
flex-grow: 1;
|
||||||
|
}
|
||||||
|
.row .details{
|
||||||
|
flex-grow: 2;
|
||||||
|
}
|
||||||
|
.row .instruments{
|
||||||
|
flex-grow: 2;
|
||||||
|
}
|
||||||
|
.row .links{
|
||||||
|
flex-grow: 1;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
|
|
||||||
|
<section class="container">
|
||||||
|
<p>
|
||||||
|
Hi <%= @user.first_name -%>,
|
||||||
|
</p>
|
||||||
|
<p>The following musicians have joined JamKazam within the last week and have low internet latency to you that will support enjoyable sessions. If you'd like to make more musical connections, we encourage you to use the links below to send these new users a welcome message and perhaps arrange a session to play together.</p>
|
||||||
|
<% @musicians_data.each do | data | -%>
|
||||||
|
<%
|
||||||
|
musicians = data[:musicians]
|
||||||
|
latencies = data[:latencies]
|
||||||
|
musicians.each do |musician|
|
||||||
|
latency = latencies.find{|l| l[:user_id] == musician.id }
|
||||||
|
-%>
|
||||||
|
<div class="row">
|
||||||
|
<div class="photo">
|
||||||
|
photo
|
||||||
|
</div>
|
||||||
|
<div class="details">
|
||||||
|
<div><strong><%= musician.first_name %> <%= musician.last_name %></strong></div>
|
||||||
|
<div>Latency To You: <%= latency[:ars_total_latency] %></div>
|
||||||
|
<div>Last Active On: </div>
|
||||||
|
</div>
|
||||||
|
<div class="instruments">
|
||||||
|
<% musician.instruments.each do |instrument| -%>
|
||||||
|
<div>
|
||||||
|
<%= instrument.description %><%= instrument.inspect %>
|
||||||
|
</div>
|
||||||
|
<% end -%>
|
||||||
|
</div>
|
||||||
|
<div class="links">
|
||||||
|
<div><a href="<%= APP_CONFIG.spa_origin %>">View Profile</a></div>
|
||||||
|
<div><a href="<%= APP_CONFIG.spa_origin %>">Send Message</a></div>
|
||||||
|
<div><a href="<%= APP_CONFIG.spa_origin %>">Send Friend Request</a></div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<% end -%>
|
||||||
|
<% end -%>
|
||||||
|
</section>
|
||||||
|
|
@ -1 +1 @@
|
||||||
EMAIL BODY HERE: <%= @musicians_data.inspect -%>
|
EMAIL BODY HERE: <%#= @musicians_data.inspect -%>
|
||||||
|
|
@ -0,0 +1,26 @@
|
||||||
|
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
|
||||||
|
<html>
|
||||||
|
<head>
|
||||||
|
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
|
||||||
|
<title>JamKazam</title>
|
||||||
|
|
||||||
|
<style>
|
||||||
|
body{
|
||||||
|
margin-top:10px;
|
||||||
|
font-family:Arial, Helvetica, sans-serif;
|
||||||
|
}
|
||||||
|
p {
|
||||||
|
margin-bottom:0px;
|
||||||
|
line-height:140%;
|
||||||
|
}
|
||||||
|
a {
|
||||||
|
color: lightblue !important;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
|
|
||||||
|
</head>
|
||||||
|
|
||||||
|
<body bgcolor="#eee" >
|
||||||
|
<%= yield -%>
|
||||||
|
<body>
|
||||||
|
</html>
|
||||||
|
|
@ -1,15 +1,18 @@
|
||||||
module JamRuby
|
module JamRuby
|
||||||
class EmailNewMusicianMatch
|
class EmailNewMusicianMatch
|
||||||
|
|
||||||
PER_PAGE = 20
|
PER_PAGE = 20
|
||||||
JOINED_WITHIN_DAYS = ""
|
JOINED_WITHIN_DAYS = "7"
|
||||||
ACTIVE_WITHIN_DAYS = ""
|
ACTIVE_WITHIN_DAYS = "7"
|
||||||
|
|
||||||
|
PRIORITY_RECIPIENTS = %w(seth@jamkazam.com david@jamkazam.com peter@jamkazam.com nuwan@jamkazam.com)
|
||||||
|
|
||||||
def self.subject
|
def self.subject
|
||||||
"New musicians with good Internet connections to you have joined JamKazam!"
|
"New musicians with good Internet connections to you have joined JamKazam!"
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.send_new_musicians
|
def self.send_new_musicians
|
||||||
|
|
||||||
params = {
|
params = {
|
||||||
latency_good: true,
|
latency_good: true,
|
||||||
latency_fair: true,
|
latency_fair: true,
|
||||||
|
|
@ -24,38 +27,64 @@ module JamRuby
|
||||||
}
|
}
|
||||||
|
|
||||||
begin
|
begin
|
||||||
|
|
||||||
nextOffset = 0
|
|
||||||
|
|
||||||
email_sending = UserMatchEmailSending.most_recent
|
email_sending = UserMatchEmailSending.most_recent
|
||||||
if email_sending.completed?
|
if email_sending.nil? || email_sending.completed?
|
||||||
email_sending = UserMatchEmailSending.create
|
email_sending = UserMatchEmailSending.create
|
||||||
end
|
end
|
||||||
|
|
||||||
recipients = User.where(subscribe_email: true, subscribe_email_for_user_match: true).where("users.id NOT IN ?", email_sending.sent_user_ids)
|
AdminMailer.ugly({to: APP_CONFIG.user_match_monitoring_email,
|
||||||
|
subject:"Weekly user match email sending started.",
|
||||||
|
body: "#{email_sending.sent_user_ids.any?? "Weekly email sending is resuming. It was originally started at #{email_sending.created_at} and has been sent to #{email_sending.sent_user_ids.size} user(s) so far." : "Weekly email sending was started at #{email_sending.created_at}" }"}).deliver_now
|
||||||
|
|
||||||
#User.where(email: "nuwan@jamkazam.com").each do |user|
|
priority_recipients = User.where(email: PRIORITY_RECIPIENTS).where("users.subscribe_email = ? OR users.subscribe_email_for_user_match = ?", true, true)
|
||||||
recipients.order("updated_at DESC, last_join_session_at DESC").each do |user|
|
|
||||||
|
user_recipients = User.where("users.subscribe_email = ? OR users.subscribe_email_for_user_match = ?", true, true).where.not(id: email_sending.sent_user_ids).order("updated_at DESC, last_jam_updated_at DESC")
|
||||||
|
|
||||||
|
recipients = (priority_recipients + user_recipients).uniq
|
||||||
|
|
||||||
|
recipients.each do |user|
|
||||||
|
|
||||||
ip = '127.0.0.1' #TODO: get this from user data?
|
ip = '127.0.0.1' #TODO: get this from user data?
|
||||||
matched_musician_data = []
|
matched_musician_data = []
|
||||||
|
nextOffset = 0
|
||||||
while !nextOffset.nil? && nextOffset >= 0 do
|
while !nextOffset.nil? && nextOffset >= 0 do
|
||||||
|
|
||||||
params.merge!({ offset: nextOffset })
|
params.merge!({ offset: nextOffset })
|
||||||
search, latency_data, nextOffset = JamRuby::MusicianFilter.filter(user, ip, params)
|
|
||||||
matched_musician_data << [search, latency_data] if search.results.size > 0
|
|
||||||
end
|
|
||||||
|
|
||||||
|
results, latency_data, nextOffset = JamRuby::MusicianFilter.filter(user, ip, params)
|
||||||
|
|
||||||
|
matched_musician_data << [{ musicians: results, latencies: latency_data }] if results && results.size > 0
|
||||||
|
end
|
||||||
|
#debugger
|
||||||
if matched_musician_data.size > 0
|
if matched_musician_data.size > 0
|
||||||
|
|
||||||
UserMailer.new_musicians_match(user, matched_musician_data).deliver_now
|
UserMailer.new_musicians_match(user, matched_musician_data).deliver_now
|
||||||
|
|
||||||
user.update_column(:user_match_email_sent_at, Time.now)
|
user.update_column(:user_match_email_sent_at, Time.now)
|
||||||
email_sending.sent_user_ids.push(user.id)
|
email_sending.sent_user_ids.push(user.id)
|
||||||
email_sending.save!
|
email_sending.save!
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
email_sending.total_recipients = email_sending.sent_user_ids.size
|
email_sending.total_recipients = email_sending.sent_user_ids.size
|
||||||
email_sending.completed_at = Time.now
|
email_sending.completed_at = Time.now
|
||||||
email_sending.save!
|
email_sending.save!
|
||||||
|
|
||||||
|
AdminMailer.ugly({
|
||||||
|
to: APP_CONFIG.user_match_monitoring_email,
|
||||||
|
subject:"Weekly user match email sending completed.",
|
||||||
|
body: "Weekly email sending job was completed at #{Time.now}. It was sent to #{email_sending.sent_user_ids.size} user(s)"
|
||||||
|
}).deliver_now
|
||||||
|
|
||||||
rescue => exception
|
rescue => exception
|
||||||
raise exception
|
begin
|
||||||
|
AdminMailer.ugly({to: APP_CONFIG.user_match_monitoring_email,
|
||||||
|
subject:"Error occured when sending weekly user match email.",
|
||||||
|
body: "An error was encountered at #{Time.now} while sending weekly user match email - #{exception.message}."}).deliver_now
|
||||||
|
rescue
|
||||||
|
Bugsnag.notify(exception)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -10,6 +10,7 @@ module JamRuby
|
||||||
};
|
};
|
||||||
|
|
||||||
def self.filter(user, remote_ip, params)
|
def self.filter(user, remote_ip, params)
|
||||||
|
#debugger
|
||||||
latency_good = ActiveRecord::Type::Boolean.new.type_cast_from_user(params[:latency_good])
|
latency_good = ActiveRecord::Type::Boolean.new.type_cast_from_user(params[:latency_good])
|
||||||
latency_fair = ActiveRecord::Type::Boolean.new.type_cast_from_user(params[:latency_fair])
|
latency_fair = ActiveRecord::Type::Boolean.new.type_cast_from_user(params[:latency_fair])
|
||||||
latency_high = ActiveRecord::Type::Boolean.new.type_cast_from_user(params[:latency_high])
|
latency_high = ActiveRecord::Type::Boolean.new.type_cast_from_user(params[:latency_high])
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,13 @@
|
||||||
module JamRuby
|
module JamRuby
|
||||||
class UserMatchEmailSending < ActiveRecord::Base
|
class UserMatchEmailSending < ActiveRecord::Base
|
||||||
|
|
||||||
|
serialize :sent_user_ids, Array
|
||||||
|
|
||||||
|
def sent_user_ids=(ids)
|
||||||
|
ids = ids.split(',') if ids.is_a?(String)
|
||||||
|
super(ids)
|
||||||
|
end
|
||||||
|
|
||||||
def completed?
|
def completed?
|
||||||
!completed_at.nil?
|
!completed_at.nil?
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,81 @@
|
||||||
|
require 'spec_helper'
|
||||||
|
|
||||||
|
describe EmailNewMusicianMatch do
|
||||||
|
let(:user1) { FactoryGirl.create(:user) }
|
||||||
|
let(:user2) { FactoryGirl.create(:user) }
|
||||||
|
let(:user3) { FactoryGirl.create(:user) }
|
||||||
|
let(:user4) { FactoryGirl.create(:user) }
|
||||||
|
let(:user5) { FactoryGirl.create(:user) }
|
||||||
|
let(:user6) { FactoryGirl.create(:user) }
|
||||||
|
let(:user7) { FactoryGirl.create(:user, subscribe_email: false) }
|
||||||
|
let(:user8) { FactoryGirl.create(:user, subscribe_email: false, subscribe_email_for_user_match: false) }
|
||||||
|
let(:user9) { FactoryGirl.create(:user, email: 'seth@jamkazam.com') } #a priority user
|
||||||
|
let(:user10) { FactoryGirl.create(:user, email: 'david@jamkazam.com', subscribe_email: false) } #a priority user. but not included as he has marked not to receive email notifications
|
||||||
|
|
||||||
|
let(:search_result){ [[user1, user2, user3, user4, user5], [user6, user7, user8, user9, user10] ] }
|
||||||
|
|
||||||
|
let (:mail) { double("Mail") }
|
||||||
|
let (:admin_mail) { double("Admin Mail") }
|
||||||
|
|
||||||
|
before(:each) do
|
||||||
|
ActionMailer::Base.delivery_method = :test
|
||||||
|
ActionMailer::Base.perform_deliveries = true
|
||||||
|
ActionMailer::Base.deliveries = []
|
||||||
|
User.delete_all
|
||||||
|
allow(JamRuby::MusicianFilter).to receive(:filter).and_return(search_result)
|
||||||
|
end
|
||||||
|
|
||||||
|
after(:each) do
|
||||||
|
ActionMailer::Base.deliveries.clear
|
||||||
|
end
|
||||||
|
|
||||||
|
it "notify admin" do
|
||||||
|
allow(AdminMailer).to receive(:ugly).and_return(admin_mail)
|
||||||
|
expect(admin_mail).to receive(:deliver_now).exactly(2).times
|
||||||
|
JamRuby::EmailNewMusicianMatch.send_new_musicians
|
||||||
|
end
|
||||||
|
|
||||||
|
it "does not sent to whom have not been opted to receive emails" do
|
||||||
|
ActionMailer::Base.deliveries.map{|d| d['to'].to_s }.include?("david@example.com").should be_falsey
|
||||||
|
JamRuby::EmailNewMusicianMatch.send_new_musicians
|
||||||
|
end
|
||||||
|
|
||||||
|
it "delivers the new musicians notification email" do
|
||||||
|
allow(UserMailer).to receive(:new_musicians_match).and_return(mail)
|
||||||
|
expect(mail).to receive(:deliver_now).exactly(7).times
|
||||||
|
JamRuby::EmailNewMusicianMatch.send_new_musicians
|
||||||
|
end
|
||||||
|
|
||||||
|
fit "delivers to priority recipients first" do
|
||||||
|
JamRuby::EmailNewMusicianMatch.send_new_musicians
|
||||||
|
ActionMailer::Base.deliveries[1]['to'].to_s.should == "seth@jamkazam.com" #NOTE: the first email is sent to user_match_monitoring_email. The second email should be sent to the first priority user in the priority user list
|
||||||
|
end
|
||||||
|
|
||||||
|
describe "halfway done job" do
|
||||||
|
before(:each) do
|
||||||
|
UserMailer.deliveries.clear
|
||||||
|
allow_any_instance_of(UserMatchEmailSending).to receive(:sent_user_ids).and_return([user1.id, user2.id])
|
||||||
|
end
|
||||||
|
|
||||||
|
it "does not deliver to already delivered users" do
|
||||||
|
allow(UserMailer).to receive(:new_musicians_match).and_return(mail)
|
||||||
|
expect(mail).to receive(:deliver_now).exactly(5).times
|
||||||
|
JamRuby::EmailNewMusicianMatch.send_new_musicians
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
describe "catching errors" do
|
||||||
|
|
||||||
|
before do
|
||||||
|
JamRuby::MusicianFilter.stub(:filter).and_raise
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'notifies admin about the error' do
|
||||||
|
JamRuby::EmailNewMusicianMatch.send_new_musicians
|
||||||
|
ActionMailer::Base.deliveries.length.should == 2
|
||||||
|
ActionMailer::Base.deliveries[1]['subject'].to_s.should == "Error occured when sending weekly user match email."
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
|
end
|
||||||
|
|
@ -0,0 +1,223 @@
|
||||||
|
require 'spec_helper'
|
||||||
|
require 'webmock/rspec'
|
||||||
|
|
||||||
|
describe MusicianFilter do
|
||||||
|
let(:latency_data_uri) { /\S+\/search_users/ }
|
||||||
|
let(:user) { FactoryGirl.create(:user) }
|
||||||
|
let(:remote_ip) { "127.0.0.1" }
|
||||||
|
|
||||||
|
let(:user1) { FactoryGirl.create(:user) }
|
||||||
|
let(:user2) { FactoryGirl.create(:user) }
|
||||||
|
let(:user3) { FactoryGirl.create(:user) }
|
||||||
|
let(:user4) { FactoryGirl.create(:user) }
|
||||||
|
let(:user5) { FactoryGirl.create(:user) }
|
||||||
|
let(:user6) { FactoryGirl.create(:user) }
|
||||||
|
let(:user7) { FactoryGirl.create(:user) }
|
||||||
|
let(:user8) { FactoryGirl.create(:user) }
|
||||||
|
|
||||||
|
let(:response_body) { mock_latency_response([
|
||||||
|
{ user: user1, ars_total_latency: 1.0, ars_internet_latency: 0.4, audio_latency: 0.6 }, #GOOD
|
||||||
|
{ user: user2, ars_total_latency: 40.0, ars_internet_latency: 25.0, audio_latency: 15.0 }, #GOOD
|
||||||
|
{ user: user3, ars_total_latency: 40.1, ars_internet_latency: 25, audio_latency: 15.1 }, #FAIR
|
||||||
|
{ user: user4, ars_total_latency: 60.0, ars_internet_latency: 30, audio_latency: 30.0 }, #FAIR
|
||||||
|
{ user: user5, ars_total_latency: 60.1, ars_internet_latency: 30.1, audio_latency: 30 }, #HIGH
|
||||||
|
{ user: user6, ars_total_latency: 100.0, ars_internet_latency: 50.0, audio_latency: 50.0 }, #HIGH
|
||||||
|
{ user: user7, ars_total_latency: -2, ars_internet_latency: -1, audio_latency: -1 }, #UNKNOWN
|
||||||
|
{ user: user8, ars_total_latency: 10, ars_internet_latency: 5, audio_latency: 0 } #GOOD (NOTE: audio_latency from neo4j is 0 here)
|
||||||
|
])
|
||||||
|
}
|
||||||
|
|
||||||
|
let(:response_body_pop) { mock_latency_response([
|
||||||
|
{ user: user1, ars_total_latency: 1.0, ars_internet_latency: 0.4, audio_latency: 0.6 }, #GOOD
|
||||||
|
{ user: user2, ars_total_latency: 40.0, ars_internet_latency: 25.0, audio_latency: 15.0 }, #GOOD
|
||||||
|
{ user: user3, ars_total_latency: 40.1, ars_internet_latency: 25, audio_latency: 15.1 }, #FAIR
|
||||||
|
])
|
||||||
|
}
|
||||||
|
|
||||||
|
let(:response_body_pop_and_rap) { mock_latency_response([
|
||||||
|
{ user: user1, ars_total_latency: 1.0, ars_internet_latency: 0.4, audio_latency: 0.6 }, #GOOD
|
||||||
|
])
|
||||||
|
}
|
||||||
|
|
||||||
|
let(:response_body_drums_intermediate) { mock_latency_response([
|
||||||
|
{ user: user1, ars_total_latency: 1.0, ars_internet_latency: 0.4, audio_latency: 0.6 },
|
||||||
|
{ user: user2, ars_total_latency: 40.0, ars_internet_latency: 25.0, audio_latency: 15.0 },
|
||||||
|
{ user: user3, ars_total_latency: 40.1, ars_internet_latency: 25, audio_latency: 15.1 },
|
||||||
|
{ user: user4, ars_total_latency: 60.0, ars_internet_latency: 30, audio_latency: 30.0 }
|
||||||
|
])
|
||||||
|
}
|
||||||
|
|
||||||
|
let(:response_body_drums_violin_expert) { mock_latency_response([
|
||||||
|
{ user: user2, ars_total_latency: 40.0, ars_internet_latency: 25.0, audio_latency: 15.0 },
|
||||||
|
{ user: user3, ars_total_latency: 40.1, ars_internet_latency: 25, audio_latency: 15.1 },
|
||||||
|
])
|
||||||
|
}
|
||||||
|
|
||||||
|
let(:response_body_active_within_one_day) { mock_latency_response([
|
||||||
|
{ user: user4, ars_total_latency: 60.0, ars_internet_latency: 30, audio_latency: 30.0 }, #FAIR
|
||||||
|
])
|
||||||
|
}
|
||||||
|
|
||||||
|
let(:response_body_joined_within_one_day) { mock_latency_response([
|
||||||
|
{ user: user4, ars_total_latency: 60.0, ars_internet_latency: 30, audio_latency: 30.0 }, #FAIR
|
||||||
|
{ user: user5, ars_total_latency: 60.1, ars_internet_latency: 30.1, audio_latency: 30 }, #HIGH
|
||||||
|
])
|
||||||
|
}
|
||||||
|
|
||||||
|
before(:each) do
|
||||||
|
User.delete_all
|
||||||
|
|
||||||
|
stub_request(:post, latency_data_uri)
|
||||||
|
.with(:headers => {'Accept'=>'*/*', 'Content-Type'=>'application/json', 'User-Agent'=>'Ruby'})
|
||||||
|
.to_return( body: response_body, status: 200)
|
||||||
|
|
||||||
|
stub_request(:post, latency_data_uri).
|
||||||
|
with(
|
||||||
|
body: hash_including({ genres: ["pop"]}),
|
||||||
|
:headers => {'Accept'=>'*/*', 'Content-Type'=>'application/json', 'User-Agent'=>'Ruby'}
|
||||||
|
)
|
||||||
|
.to_return( body: response_body_pop, status: 200)
|
||||||
|
|
||||||
|
stub_request(:post, latency_data_uri).
|
||||||
|
with(
|
||||||
|
body: hash_including({ genres: ["pop", "rap"]}),
|
||||||
|
:headers => {'Accept'=>'*/*', 'Content-Type'=>'application/json', 'User-Agent'=>'Ruby'}
|
||||||
|
)
|
||||||
|
.to_return( body: response_body_pop_and_rap, status: 200)
|
||||||
|
|
||||||
|
stub_request(:post, latency_data_uri).
|
||||||
|
with(
|
||||||
|
body: hash_including({ instruments: [{id: 'drums', proficiency: 2}]}),
|
||||||
|
:headers => {'Accept'=>'*/*', 'Content-Type'=>'application/json', 'User-Agent'=>'Ruby'}
|
||||||
|
)
|
||||||
|
.to_return( body: response_body_drums_intermediate, status: 200)
|
||||||
|
|
||||||
|
stub_request(:post, latency_data_uri).
|
||||||
|
with(
|
||||||
|
body: hash_including({ instruments: [{id: 'drums', proficiency: 3}, {id: 'violin', proficiency: 3}]}),
|
||||||
|
:headers => {'Accept'=>'*/*', 'Content-Type'=>'application/json', 'User-Agent'=>'Ruby'}
|
||||||
|
)
|
||||||
|
.to_return( body: response_body_drums_violin_expert, status: 200)
|
||||||
|
|
||||||
|
stub_request(:post, latency_data_uri).
|
||||||
|
with(
|
||||||
|
body: hash_including({ active_within_days: 1}),
|
||||||
|
:headers => {'Accept'=>'*/*', 'Content-Type'=>'application/json', 'User-Agent'=>'Ruby'}
|
||||||
|
)
|
||||||
|
.to_return( body: response_body_active_within_one_day, status: 200)
|
||||||
|
|
||||||
|
stub_request(:post, latency_data_uri).
|
||||||
|
with(
|
||||||
|
body: hash_including({ joined_within_days: 1 }),
|
||||||
|
:headers => {'Accept'=>'*/*', 'Content-Type'=>'application/json', 'User-Agent'=>'Ruby'}
|
||||||
|
)
|
||||||
|
.to_return( body: response_body_joined_within_one_day, status: 200)
|
||||||
|
end
|
||||||
|
|
||||||
|
it "when no latency option is selected" do
|
||||||
|
opts = { latency_good: false, latency_fair: false, latency_high: false }
|
||||||
|
search, latency_data, nextOffset = JamRuby::MusicianFilter.filter(user, remote_ip, opts)
|
||||||
|
puts search.results
|
||||||
|
puts "===="
|
||||||
|
puts latency_data
|
||||||
|
puts "===="
|
||||||
|
puts nextOffset
|
||||||
|
expect(search.results.size).to eq(8)
|
||||||
|
expect(latency_data).not_to eq(nil)
|
||||||
|
expect(latency_data[0][:audio_latency]).not_to eq(nil)
|
||||||
|
expect(latency_data[0][:ars_total_latency]).not_to eq(nil)
|
||||||
|
expect(latency_data[0][:ars_internet_latency]).not_to eq(nil)
|
||||||
|
end
|
||||||
|
|
||||||
|
it "filter musicians for all latency options" do
|
||||||
|
opts = { latency_good: true, latency_fair: true, latency_high: true }
|
||||||
|
search, latency_data, nextOffset = JamRuby::MusicianFilter.filter(user, remote_ip, opts)
|
||||||
|
|
||||||
|
expect(search.results.size).to eq(7)
|
||||||
|
expect(latency_data).not_to eq(nil)
|
||||||
|
expect(latency_data[0][:audio_latency]).not_to eq(nil)
|
||||||
|
expect(latency_data[0][:ars_total_latency]).not_to eq(nil)
|
||||||
|
expect(latency_data[0][:ars_internet_latency]).not_to eq(nil)
|
||||||
|
|
||||||
|
#sort by latency
|
||||||
|
expect(search.results[0][:id]).to eq(user1.id)
|
||||||
|
expect(search.results[1][:id]).to eq(user2.id)
|
||||||
|
expect(search.results[2][:id]).to eq(user3.id)
|
||||||
|
expect(search.results[3][:id]).to eq(user4.id)
|
||||||
|
expect(search.results[4][:id]).to eq(user5.id)
|
||||||
|
expect(search.results[5][:id]).to eq(user6.id)
|
||||||
|
expect(search.results[6][:id]).to eq(user8.id)
|
||||||
|
|
||||||
|
end
|
||||||
|
|
||||||
|
it "filter GOOD latency users" do
|
||||||
|
opts = { latency_good: true, latency_fair: false, latency_high: false }
|
||||||
|
search, latency_data, nextOffset = JamRuby::MusicianFilter.filter(user, remote_ip, opts)
|
||||||
|
expect(search.results.size).to eq(3)
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
|
it "filter FAIR latency musicians" do
|
||||||
|
opts = { latency_good: false, latency_fair: true, latency_high: false }
|
||||||
|
search, latency_data, nextOffset = JamRuby::MusicianFilter.filter(user, remote_ip, opts)
|
||||||
|
expect(search.results.size).to eq(2)
|
||||||
|
end
|
||||||
|
|
||||||
|
it "filter HIGH latency musicians" do
|
||||||
|
opts = { latency_good: false, latency_fair: false, latency_high: true }
|
||||||
|
search, latency_data, nextOffset = JamRuby::MusicianFilter.filter(user, remote_ip, opts)
|
||||||
|
expect(search.results.size).to eq(2)
|
||||||
|
end
|
||||||
|
|
||||||
|
it "filter GOOD and FAIR latency musicians" do
|
||||||
|
opts = { latency_good: true, latency_fair: true, latency_high: false }
|
||||||
|
search, latency_data, nextOffset = JamRuby::MusicianFilter.filter(user, remote_ip, opts)
|
||||||
|
expect(search.results.size).to eq(5)
|
||||||
|
end
|
||||||
|
|
||||||
|
it "filter GOOD and HIGH latency musicians" do
|
||||||
|
opts = { latency_good: true, latency_fair: false, latency_high: true }
|
||||||
|
search, latency_data, nextOffset = JamRuby::MusicianFilter.filter(user, remote_ip, opts)
|
||||||
|
expect(search.results.size).to eq(5)
|
||||||
|
end
|
||||||
|
|
||||||
|
it "filter GOOD, FAIR and HIGH latency musicians" do
|
||||||
|
opts = { latency_good: true, latency_fair: true, latency_high: true }
|
||||||
|
search, latency_data, nextOffset = JamRuby::MusicianFilter.filter(user, remote_ip, opts)
|
||||||
|
expect(search.results.size).to eq(7)
|
||||||
|
end
|
||||||
|
|
||||||
|
it "filter musicians by genres" do
|
||||||
|
opts = { latency_good: true, latency_fair: true, latency_high: true, genres: ['pop'] }
|
||||||
|
search, latency_data, nextOffset = JamRuby::MusicianFilter.filter(user, remote_ip, opts)
|
||||||
|
expect(search.results.size).to eq(3)
|
||||||
|
|
||||||
|
opts = { latency_good: true, latency_fair: true, latency_high: true, genres: ['pop', 'rap'] }
|
||||||
|
search, latency_data, nextOffset = JamRuby::MusicianFilter.filter(user, remote_ip, opts)
|
||||||
|
expect(search.results.size).to eq(1)
|
||||||
|
end
|
||||||
|
|
||||||
|
it "filter musicians by instruments they play" do
|
||||||
|
|
||||||
|
opts = { latency_good: true, latency_fair: true, latency_high: true, instruments: [{value: "drums", label: "Drums"}], proficiency_intermediate: true }
|
||||||
|
search, latency_data, nextOffset = JamRuby::MusicianFilter.filter(user, remote_ip, opts)
|
||||||
|
expect(search.results.size).to eq(4)
|
||||||
|
|
||||||
|
opts = { latency_good: true, latency_fair: true, latency_high: true, instruments: [{value: "drums", label: "Drums"}, {value: 'violin', label: 'Violin'}], proficiency_expert: true }
|
||||||
|
search, latency_data, nextOffset = JamRuby::MusicianFilter.filter(user, remote_ip, opts)
|
||||||
|
expect(search.results.size).to eq(2)
|
||||||
|
end
|
||||||
|
|
||||||
|
it "filter musicians by days ago that they joined" do
|
||||||
|
opts = { latency_good: true, latency_fair: true, latency_high: true, joined_within_days: 1 }
|
||||||
|
search, latency_data, nextOffset = JamRuby::MusicianFilter.filter(user, remote_ip, opts)
|
||||||
|
expect(search.results.size).to eq(2)
|
||||||
|
end
|
||||||
|
|
||||||
|
it "finds user updated_at is within a day ago" do
|
||||||
|
opts = { latency_good: true, latency_fair: true, latency_high: true, active_within_days: 1 }
|
||||||
|
search, latency_data, nextOffset = JamRuby::MusicianFilter.filter(user, remote_ip, opts)
|
||||||
|
expect(search.results.size).to eq(1)
|
||||||
|
end
|
||||||
|
|
||||||
|
end
|
||||||
|
|
@ -523,6 +523,35 @@ describe "RenderMailers" do
|
||||||
@filename="daily_sessions"; scheduled_batch.deliver_batch
|
@filename="daily_sessions"; scheduled_batch.deliver_batch
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
describe "New Musician Match email" do
|
||||||
|
let(:user) { FactoryGirl.create(:user) }
|
||||||
|
let(:user1) { FactoryGirl.create(:user) }
|
||||||
|
let(:user2) { FactoryGirl.create(:user) }
|
||||||
|
let(:matched_musician_data){
|
||||||
|
[
|
||||||
|
{
|
||||||
|
musicians: [user1, user2],
|
||||||
|
latencies: [
|
||||||
|
{:user_id=> user1.id, :audio_latency=>4, :ars_total_latency=>12, :ars_internet_latency=>8},
|
||||||
|
{:user_id=> user2.id, :audio_latency=>4, :ars_total_latency=>12, :ars_internet_latency=>8}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
|
||||||
|
before(:each) do
|
||||||
|
ActionMailer::Base.deliveries.clear
|
||||||
|
end
|
||||||
|
|
||||||
|
after(:each) do
|
||||||
|
ActionMailer::Base.deliveries.length.should == 1
|
||||||
|
mail = ActionMailer::Base.deliveries[0]
|
||||||
|
save_emails_to_disk(mail, @filename)
|
||||||
|
end
|
||||||
|
|
||||||
|
fit { @filename="new_musicians_match"; UserMailer.new_musicians_match(user, matched_musician_data).deliver_now }
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def save_emails_to_disk(mail, filename)
|
def save_emails_to_disk(mail, filename)
|
||||||
|
|
|
||||||
|
|
@ -26,7 +26,6 @@ describe UserMailer do
|
||||||
UserMailer.confirm_email(user, signup_confirmation_url_with_token).deliver_now
|
UserMailer.confirm_email(user, signup_confirmation_url_with_token).deliver_now
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
it { UserMailer.deliveries.length.should == 1 }
|
it { UserMailer.deliveries.length.should == 1 }
|
||||||
it { mail['from'].to_s.should == UserMailer::DEFAULT_SENDER }
|
it { mail['from'].to_s.should == UserMailer::DEFAULT_SENDER }
|
||||||
it { mail['to'].to_s.should == user.email }
|
it { mail['to'].to_s.should == user.email }
|
||||||
|
|
|
||||||
|
|
@ -181,6 +181,8 @@ class ApiSearchController < ApiController
|
||||||
def filter
|
def filter
|
||||||
begin
|
begin
|
||||||
@search, @latency_data, @nextOffset = JamRuby::MusicianFilter.filter(current_user, request.remote_ip, params)
|
@search, @latency_data, @nextOffset = JamRuby::MusicianFilter.filter(current_user, request.remote_ip, params)
|
||||||
|
Rails.logger.debug("=====SEARCH : #{@search.results.inspect}")
|
||||||
|
Rails.logger.debug("=====LATENCY : #{@latency_data}")
|
||||||
respond_with @search, responder: ApiResponder, status: 201, template: 'api_search/filter'
|
respond_with @search, responder: ApiResponder, status: 201, template: 'api_search/filter'
|
||||||
rescue
|
rescue
|
||||||
render json: {}, status: 500
|
render json: {}, status: 500
|
||||||
|
|
|
||||||
|
|
@ -516,6 +516,6 @@ if defined?(Bundler)
|
||||||
config.latency_data_host_auth_code = "c2VydmVyOnBhc3N3b3Jk"
|
config.latency_data_host_auth_code = "c2VydmVyOnBhc3N3b3Jk"
|
||||||
config.manual_override_installer_ends_with = "JamKazam-1.0.3776.dmg"
|
config.manual_override_installer_ends_with = "JamKazam-1.0.3776.dmg"
|
||||||
config.spa_origin = "http://beta.jamkazam.local:3000"
|
config.spa_origin = "http://beta.jamkazam.local:3000"
|
||||||
|
config.user_match_monitoring_email = "user_match_monitoring_email@jamkazam.com"
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -133,7 +133,7 @@ describe "Musician Filter API", type: :request do
|
||||||
expect(JSON.parse(response.body)["musicians"].size).to eq(8)
|
expect(JSON.parse(response.body)["musicians"].size).to eq(8)
|
||||||
end
|
end
|
||||||
|
|
||||||
it "filter musicians when no latency option is selected", focus: true do
|
it "filter musicians when no latency option is selected" do
|
||||||
post '/api/filter.json', { latency_good: false, latency_fair: false, latency_high: false }
|
post '/api/filter.json', { latency_good: false, latency_fair: false, latency_high: false }
|
||||||
expect(JSON.parse(response.body)["musicians"].size).to eq(8)
|
expect(JSON.parse(response.body)["musicians"].size).to eq(8)
|
||||||
expect(JSON.parse(response.body)["musicians"][0]["latency_data"]).not_to eq(nil)
|
expect(JSON.parse(response.body)["musicians"][0]["latency_data"]).not_to eq(nil)
|
||||||
|
|
@ -222,7 +222,7 @@ describe "Musician Filter API", type: :request do
|
||||||
expect(JSON.parse(response.body)["musicians"].size).to eq(2)
|
expect(JSON.parse(response.body)["musicians"].size).to eq(2)
|
||||||
end
|
end
|
||||||
|
|
||||||
it "filter musicians by days ago that they joined" do
|
fit "filter musicians by days ago that they joined" do
|
||||||
post '/api/filter.json', { latency_good: true, latency_fair: true, latency_high: true, joined_within_days: 1 }
|
post '/api/filter.json', { latency_good: true, latency_fair: true, latency_high: true, joined_within_days: 1 }
|
||||||
expect(JSON.parse(response.body)["musicians"].size).to eq(2)
|
expect(JSON.parse(response.body)["musicians"].size).to eq(2)
|
||||||
end
|
end
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue