jam-cloud/ruby/spec/jam_ruby/resque/google_analytics_event_spec.rb

114 lines
5.2 KiB
Ruby
Raw Permalink Normal View History

2014-03-09 13:38:46 +00:00
require 'spec_helper'
describe GoogleAnalyticsEvent do
let(:ga) { GoogleAnalyticsEvent.new }
2014-04-15 17:02:51 +00:00
after(:each) do
Timecop.return
end
describe "track band analytics" do
it 'reports first recording' do
pending "job is commented out"
2014-04-14 10:57:21 +00:00
ResqueSpec.reset!
user = FactoryGirl.create(:user)
band = FactoryGirl.create(:band)
2014-05-06 13:34:38 +00:00
music_session = FactoryGirl.create(:active_music_session,
:creator => user,
:musician_access => true,
:band => band)
recording = Recording.start(music_session, user)
expect(Recording.where(:band_id => band.id).count).to eq(1)
2014-03-09 13:38:46 +00:00
GoogleAnalyticsEvent.should have_queued(GoogleAnalyticsEvent::CAT_BAND,
GoogleAnalyticsEvent::ACTION_BAND_REC,
nil)
2014-03-09 13:38:46 +00:00
end
it 'reports first real session' do
2016-06-01 00:20:03 +00:00
pending "job is commented out"
ResqueSpec.reset!
JamRuby::GoogleAnalyticsEvent::BandSessionTracker.should have_schedule_size_of(0)
user = FactoryGirl.create(:user)
user1 = FactoryGirl.create(:user)
band = FactoryGirl.create(:band)
band.users << user
band.users << user1
band.reload
2014-05-06 13:34:38 +00:00
music_session = FactoryGirl.create(:active_music_session, :creator => user,
:musician_access => true, :band => band)
expect(band.band_musicians.count).to eq(2)
expect(band.did_real_session).to eq(false)
connection = FactoryGirl.create(:connection, :user => user, :as_musician => true,
:aasm_state => Connection::CONNECT_STATE.to_s,
:music_session => music_session)
connection = FactoryGirl.create(:connection, :user => user1, :as_musician => true,
:aasm_state => Connection::CONNECT_STATE.to_s,
:music_session => music_session)
music_session.reload
expect(music_session.connected_participant_count).to eq(2)
2014-04-14 10:57:21 +00:00
expect(band.did_real_session).to eq(false)
2014-03-09 13:38:46 +00:00
2014-04-14 10:57:21 +00:00
ResqueSpec.queues["#{GoogleAnalyticsEvent::QUEUE_BAND_TRACKER}_scheduled"].select do |qq|
qq[:class] == GoogleAnalyticsEvent::BandSessionTracker.name
end.count.should eq(1)
# GoogleAnalyticsEvent::BandSessionTracker.should have_schedule_size_of_at_least(1)
GoogleAnalyticsEvent.should_not have_queued(GoogleAnalyticsEvent::CAT_BAND, GoogleAnalyticsEvent::ACTION_BAND_SESS, nil)
Timecop.freeze((GoogleAnalyticsEvent::BAND_SESSION_MIN_DURATION + 1).minutes.from_now)
2014-04-14 10:57:21 +00:00
qname = "#{ResqueSpec.queue_name(JamRuby::GoogleAnalyticsEvent::BandSessionTracker)}_scheduled"
expect(ResqueSpec.peek(qname).present?).to eq(true)
ResqueSpec.perform_next(qname)
GoogleAnalyticsEvent.should have_queued(GoogleAnalyticsEvent::CAT_BAND,
GoogleAnalyticsEvent::ACTION_BAND_SESS,
nil)
band.reload
expect(band.did_real_session).to eq(true)
2014-03-09 13:38:46 +00:00
end
2014-03-09 13:38:46 +00:00
end
describe "track session analytics" do
before :each do
ResqueSpec.reset!
end
it 'reports size increment' do
2016-06-01 00:20:03 +00:00
pending "job is commented out"
user = FactoryGirl.create(:user)
2014-05-06 13:34:38 +00:00
music_session = FactoryGirl.create(:active_music_session,
:creator => user,
:musician_access => true)
connection = FactoryGirl.create(:connection, :user => user,
:as_musician => true,
:aasm_state => Connection::CONNECT_STATE.to_s,
:music_session => music_session)
GoogleAnalyticsEvent.should have_queued(GoogleAnalyticsEvent::CAT_SESS_SIZE,
GoogleAnalyticsEvent::ACTION_SESS_SIZE,
music_session.connected_participant_count)
2014-03-09 13:38:46 +00:00
end
it 'reports duration' do
2016-06-01 00:20:03 +00:00
pending "job is commented out"
user = FactoryGirl.create(:user)
2014-04-14 10:57:21 +00:00
JamRuby::GoogleAnalyticsEvent::SessionDurationTracker.should have_schedule_size_of(0)
2014-05-06 13:34:38 +00:00
music_session = FactoryGirl.create(:active_music_session,
:creator => user,
:musician_access => true)
2014-04-14 10:57:21 +00:00
GoogleAnalyticsEvent::SessionDurationTracker.should have_schedule_size_of(1)
GoogleAnalyticsEvent::SESSION_INTERVALS.each do |interval|
Timecop.travel((interval + 1).minutes.from_now)
qname = "#{ResqueSpec.queue_name(JamRuby::GoogleAnalyticsEvent::SessionDurationTracker)}_scheduled"
next unless ResqueSpec.peek(qname).present?
ResqueSpec.perform_next(qname)
GoogleAnalyticsEvent.should have_queued(GoogleAnalyticsEvent::CAT_SESS_DUR,
GoogleAnalyticsEvent::ACTION_SESS_DUR,
interval)
end
GoogleAnalyticsEvent.should have_queue_size_of(GoogleAnalyticsEvent::SESSION_INTERVALS.count - 1)
2014-03-09 13:38:46 +00:00
end
end
end