2014-06-09 20:43:16 +00:00
|
|
|
require 'spec_helper'
|
|
|
|
|
|
|
|
|
|
describe ApiUsersController do
|
|
|
|
|
render_views
|
|
|
|
|
|
2014-11-11 22:21:46 +00:00
|
|
|
let (:user) { FactoryGirl.create(:user) }
|
2014-08-18 15:37:55 +00:00
|
|
|
let (:conn) { FactoryGirl.create(:connection, user: user, last_jam_audio_latency: 5) }
|
2014-06-09 20:43:16 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
before(:each) do
|
|
|
|
|
controller.current_user = user
|
|
|
|
|
end
|
|
|
|
|
|
2014-11-11 22:21:46 +00:00
|
|
|
describe "update mod" do
|
|
|
|
|
it "empty mod" do
|
|
|
|
|
post :update, id:user.id, mods: {}, :format=>'json'
|
|
|
|
|
response.should be_success
|
|
|
|
|
user.mods_json.should == {}
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
it "no_show mod" do
|
|
|
|
|
user_id = user.id
|
|
|
|
|
mods = {"no_show" => {"something1" => true}}
|
|
|
|
|
post :update, id:user.id, mods: mods, :format=>'json'
|
|
|
|
|
response.should be_success
|
|
|
|
|
|
|
|
|
|
# verify that the user object has the mods data
|
|
|
|
|
user_again = User.find(user_id)
|
|
|
|
|
user_again.mods_json.should == mods
|
|
|
|
|
|
|
|
|
|
# verify that the response shows the mods structure
|
|
|
|
|
json = JSON.parse(response.body)
|
|
|
|
|
json["mods"].should == mods
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
2015-02-08 07:23:08 +00:00
|
|
|
describe 'site validation' do
|
|
|
|
|
|
|
|
|
|
it 'checks valid and invalid site types' do
|
|
|
|
|
site_types = Utils::SITE_TYPES.clone << 'bandcamp-fan'
|
|
|
|
|
site_types.each do |sitetype|
|
|
|
|
|
case sitetype
|
|
|
|
|
when 'url'
|
|
|
|
|
valid, invalid = 'http://jamkazam.com', 'http://jamkazamxxx.com'
|
|
|
|
|
when 'youtube'
|
|
|
|
|
valid, invalid = 'jonathankolyer', 'jonathankolyerxxx'
|
|
|
|
|
when 'facebook'
|
|
|
|
|
valid, invalid = 'jamkazam', 'jamkazamxxxx'
|
|
|
|
|
when 'twitter'
|
|
|
|
|
valid, invalid = 'jamkazam', 'jamkazamxxxx'
|
|
|
|
|
when 'soundcloud'
|
|
|
|
|
valid, invalid = 'zedisdead', 'zedisdeadxxxx'
|
|
|
|
|
when 'reverbnation'
|
|
|
|
|
valid, invalid = 'jessicabrown', 'jessicabrownasdf'
|
|
|
|
|
when 'bandcamp'
|
|
|
|
|
valid, invalid = 'hucci', 'huccixxxxxx'
|
|
|
|
|
when 'bandcamp-fan'
|
|
|
|
|
valid, invalid = 'iguanaden', 'iguanadenxxxxxx'
|
|
|
|
|
when 'fandalism'
|
|
|
|
|
valid, invalid = 'pud', 'pudxxxx'
|
|
|
|
|
else
|
|
|
|
|
valid, invalid = '', ''
|
|
|
|
|
end
|
|
|
|
|
next if valid.blank?
|
|
|
|
|
2.times do |nn|
|
|
|
|
|
get :validate_data, sitetype:sitetype, data: 0==nn ? valid : invalid
|
|
|
|
|
response.should be_success
|
|
|
|
|
json = JSON.parse(response.body)
|
|
|
|
|
expect(json['message']).to eq(0==nn ? 'Valid Site' : 'Invalid Site')
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
2014-06-09 20:43:16 +00:00
|
|
|
describe "audio_latency" do
|
|
|
|
|
it "updates both connection and user" do
|
|
|
|
|
|
2014-08-18 15:37:55 +00:00
|
|
|
post :audio_latency, id: user.id, client_id: conn.client_id, audio_latency: 3.5, :format => 'json'
|
2014-06-09 20:43:16 +00:00
|
|
|
response.should be_success
|
|
|
|
|
|
|
|
|
|
conn.reload
|
2014-08-18 15:37:55 +00:00
|
|
|
conn.last_jam_audio_latency.should == 3.5
|
2014-06-09 20:43:16 +00:00
|
|
|
|
|
|
|
|
user.reload
|
2014-08-18 15:37:55 +00:00
|
|
|
conn.user.last_jam_audio_latency.should == 3.5
|
2014-06-09 20:43:16 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
|
|
it "if connection does not exist, user is still updated" do
|
|
|
|
|
|
2014-08-18 15:37:55 +00:00
|
|
|
post :audio_latency, id: user.id, client_id: 'nothingness', audio_latency: 3.5, :format => 'json'
|
2014-06-09 20:43:16 +00:00
|
|
|
response.should be_success
|
|
|
|
|
|
|
|
|
|
user.reload
|
2014-08-18 15:37:55 +00:00
|
|
|
conn.user.last_jam_audio_latency.should == 3.5
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
it "ignores latencies of 2 or less" do
|
|
|
|
|
post :audio_latency, id: user.id, client_id: conn.client_id, audio_latency: 2, :format => 'json'
|
|
|
|
|
response.should be_success
|
|
|
|
|
|
|
|
|
|
conn.reload
|
|
|
|
|
conn.last_jam_audio_latency.should == 5
|
|
|
|
|
|
|
|
|
|
user.reload
|
|
|
|
|
conn.user.last_jam_audio_latency.should == 5
|
2014-06-09 20:43:16 +00:00
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
end
|