|
|
|
|
@ -13,6 +13,9 @@ describe "Music Session API ", :type => :api do
|
|
|
|
|
|
|
|
|
|
describe "profile page" do
|
|
|
|
|
let(:user) { FactoryGirl.create(:user) }
|
|
|
|
|
|
|
|
|
|
# defopts are used to setup default options for the session
|
|
|
|
|
let(:defopts) { { :description => "a session", :fan_chat => true, :fan_access => true, :approval_required => false, :genres => ["classical"], :musician_access => true, :tracks => [{"instrument_id" => "electric guitar", "sound" => "mono"}]} }
|
|
|
|
|
before do
|
|
|
|
|
#sign_in user
|
|
|
|
|
MusicSession.delete_all
|
|
|
|
|
@ -27,7 +30,7 @@ describe "Music Session API ", :type => :api do
|
|
|
|
|
|
|
|
|
|
it "should create session" do
|
|
|
|
|
client = FactoryGirl.create(:connection, :user => user, :ip_address => "1.1.1.1", :client_id => "1")
|
|
|
|
|
post '/api/sessions.json', { :description => "a session", :client_id => client.client_id, :genres => ["classical"], :musician_access => true, :tracks => [{"instrument_id" => "electric guitar", "sound" => "mono"}]}.to_json, "CONTENT_TYPE" => 'application/json'
|
|
|
|
|
post '/api/sessions.json', defopts.merge({:client_id => client.client_id}).to_json, "CONTENT_TYPE" => 'application/json'
|
|
|
|
|
last_response.status.should eql(201)
|
|
|
|
|
|
|
|
|
|
# now fetch it's data
|
|
|
|
|
@ -38,8 +41,12 @@ describe "Music Session API ", :type => :api do
|
|
|
|
|
music_sessions = JSON.parse(last_response.body)
|
|
|
|
|
music_session = music_sessions[0]
|
|
|
|
|
music_session["id"].should == music_session["id"]
|
|
|
|
|
music_session["musician_access"].should == true
|
|
|
|
|
music_session["musician_access"].should be_true
|
|
|
|
|
music_session["invitations"].should == []
|
|
|
|
|
music_session["fan_invitations"].should == []
|
|
|
|
|
music_session["approval_required"].should be_false
|
|
|
|
|
music_session["fan_chat"].should be_true
|
|
|
|
|
music_session["fan_access"].should be_true
|
|
|
|
|
music_session["participants"].length.should == 1
|
|
|
|
|
participant = music_session["participants"][0]
|
|
|
|
|
participant["ip_address"].should == client.ip_address
|
|
|
|
|
@ -59,7 +66,7 @@ describe "Music Session API ", :type => :api do
|
|
|
|
|
|
|
|
|
|
# create the session
|
|
|
|
|
client = FactoryGirl.create(:connection, :user => user, :ip_address => "1.1.1.1")
|
|
|
|
|
post '/api/sessions.json', { :description => "a session", :client_id => client.client_id, :genres => ["classical"], :musician_access => true, :tracks => [{"instrument_id" => "electric guitar", "sound" => "mono"}]}.to_json, "CONTENT_TYPE" => 'application/json'
|
|
|
|
|
post '/api/sessions.json', defopts.merge({:client_id => client.client_id}).to_json, "CONTENT_TYPE" => 'application/json'
|
|
|
|
|
last_response.status.should eql(201)
|
|
|
|
|
|
|
|
|
|
# now fetch it's data
|
|
|
|
|
@ -82,7 +89,7 @@ describe "Music Session API ", :type => :api do
|
|
|
|
|
it "should add/remove member from session" do
|
|
|
|
|
# create the session
|
|
|
|
|
client = FactoryGirl.create(:connection, :user => user, :ip_address => "1.1.1.1")
|
|
|
|
|
post '/api/sessions.json', { :description => "a session", :client_id => client.client_id, :genres => ["classical"], :musician_access => true, :tracks => [{"instrument_id" => "electric guitar", "sound" => "mono"}]}.to_json, "CONTENT_TYPE" => 'application/json'
|
|
|
|
|
post '/api/sessions.json', defopts.merge({:client_id => client.client_id}).to_json, "CONTENT_TYPE" => 'application/json'
|
|
|
|
|
last_response.status.should eql(201)
|
|
|
|
|
|
|
|
|
|
# now fetch it's data
|
|
|
|
|
@ -112,11 +119,11 @@ describe "Music Session API ", :type => :api do
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
it "should add a second member to the second" do
|
|
|
|
|
|
|
|
|
|
user2 = FactoryGirl.create(:user)
|
|
|
|
|
|
|
|
|
|
user2 = FactoryGirl.create(:user)
|
|
|
|
|
client = FactoryGirl.create(:connection, :user => user, :ip_address => "1.1.1.1")
|
|
|
|
|
client2 = FactoryGirl.create(:connection, :user => user2, :ip_address => "2.2.2.2")
|
|
|
|
|
post '/api/sessions.json', { :description => "a session", :client_id => client.client_id, :genres => ["classical"], :musician_access => true, :tracks => [{"instrument_id" => "electric guitar", "sound" => "mono"}]}.to_json, "CONTENT_TYPE" => 'application/json'
|
|
|
|
|
post '/api/sessions.json', defopts.merge({:client_id => client.client_id}).to_json, "CONTENT_TYPE" => 'application/json'
|
|
|
|
|
last_response.status.should eql(201)
|
|
|
|
|
|
|
|
|
|
# now fetch it's data
|
|
|
|
|
@ -177,14 +184,14 @@ describe "Music Session API ", :type => :api do
|
|
|
|
|
# create the session
|
|
|
|
|
original_count = MusicSession.all().length
|
|
|
|
|
client = FactoryGirl.create(:connection, :user => user, :ip_address => "1.1.1.1")
|
|
|
|
|
post '/api/sessions.json', { :description => "a session", :client_id => client.client_id, :musician_access => true, :tracks => [{"instrument_id" => "electric guitar", "sound" => "mono"}]}.to_json, "CONTENT_TYPE" => 'application/json'
|
|
|
|
|
post '/api/sessions.json', { :description => "a session", :client_id => client.client_id, :musician_access => true, :tracks => [{"instrument_id" => "electric guitar", "sound" => "mono"}], :fan_chat=>true, :fan_access=>true, :approval_required=>false}.to_json, "CONTENT_TYPE" => 'application/json'
|
|
|
|
|
last_response.status.should eql(422)
|
|
|
|
|
MusicSession.all().length.should == original_count
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
it "should error with invalid genre specified" do
|
|
|
|
|
client = FactoryGirl.create(:connection, :user => user, :ip_address => "1.1.1.1")
|
|
|
|
|
post '/api/sessions.json', { :description => "a session", :client_id => client.client_id, :genres => ["Junk"], :musician_access => true, :tracks => [{"instrument_id" => "electric guitar", "sound" => "mono"}]}.to_json, "CONTENT_TYPE" => 'application/json'
|
|
|
|
|
post '/api/sessions.json', { :description => "a session", :client_id => client.client_id, :genres => ["Junk"], :musician_access => true, :tracks => [{"instrument_id" => "electric guitar", "sound" => "mono"}], :fan_chat=>true, :fan_access=>true, :approval_required=>false}.to_json, "CONTENT_TYPE" => 'application/json'
|
|
|
|
|
last_response.status.should eql(404)
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
@ -192,7 +199,7 @@ describe "Music Session API ", :type => :api do
|
|
|
|
|
original_count = MusicSession.all().length
|
|
|
|
|
|
|
|
|
|
client = FactoryGirl.create(:connection, :user => user, :ip_address => "1.1.1.1")
|
|
|
|
|
post '/api/sessions.json', { :description => "a session", :client_id => client.client_id, :musician_access => true, :genres => ["classical"]}.to_json, "CONTENT_TYPE" => 'application/json'
|
|
|
|
|
post '/api/sessions.json', { :description => "a session", :client_id => client.client_id, :musician_access => true, :genres => ["classical"], :fan_chat=>true, :fan_access=>true, :approval_required=>false}.to_json, "CONTENT_TYPE" => 'application/json'
|
|
|
|
|
last_response.status.should eql(422)
|
|
|
|
|
JSON.parse(last_response.body)["errors"]["genres"][0].should == Connection::SELECT_AT_LEAST_ONE
|
|
|
|
|
|
|
|
|
|
@ -204,7 +211,7 @@ describe "Music Session API ", :type => :api do
|
|
|
|
|
original_count = MusicSession.all().length
|
|
|
|
|
|
|
|
|
|
client = FactoryGirl.create(:connection, :user => user, :ip_address => "1.1.1.1")
|
|
|
|
|
post '/api/sessions.json', { :description => "a session", :client_id => client.client_id, :genres => ["classical"], :musician_access => true, :tracks => [{"instrument_id" => "mom", "sound" => "mono"}]}.to_json, "CONTENT_TYPE" => 'application/json'
|
|
|
|
|
post '/api/sessions.json', { :description => "a session", :client_id => client.client_id, :genres => ["classical"], :musician_access => true, :tracks => [{"instrument_id" => "mom", "sound" => "mono"}], :fan_chat=>true, :fan_access=>true, :approval_required=>false}.to_json, "CONTENT_TYPE" => 'application/json'
|
|
|
|
|
last_response.status.should eql(404)
|
|
|
|
|
|
|
|
|
|
# check that the transaction was rolled back
|
|
|
|
|
@ -215,7 +222,7 @@ describe "Music Session API ", :type => :api do
|
|
|
|
|
original_count = MusicSession.all().length
|
|
|
|
|
|
|
|
|
|
client = FactoryGirl.create(:connection, :user => user, :ip_address => "1.1.1.1")
|
|
|
|
|
post '/api/sessions.json', { :description => "a session", :client_id => client.client_id, :genres => ["classical"], :musician_access => true, :tracks => [{"instrument_id" => "electric guitar", "sound" => "mom"}]}.to_json, "CONTENT_TYPE" => 'application/json'
|
|
|
|
|
post '/api/sessions.json', { :description => "a session", :client_id => client.client_id, :genres => ["classical"], :musician_access => true, :tracks => [{"instrument_id" => "electric guitar", "sound" => "mom"}], :fan_chat=>true, :fan_access=>true, :approval_required=>false}.to_json, "CONTENT_TYPE" => 'application/json'
|
|
|
|
|
|
|
|
|
|
last_response.status.should eql(422)
|
|
|
|
|
JSON.parse(last_response.body)["errors"]["connection_tracks"][0].should == "is invalid"
|
|
|
|
|
@ -233,7 +240,7 @@ describe "Music Session API ", :type => :api do
|
|
|
|
|
|
|
|
|
|
client = FactoryGirl.create(:connection, :user => user, :ip_address => "1.1.1.1")
|
|
|
|
|
|
|
|
|
|
post '/api/sessions.json', { :description => "a session", :client_id => client.client_id, :genres => ["classical"], :musician_access => false, :tracks => [{"instrument_id" => "electric guitar", "sound" => "mono"}]}.to_json, "CONTENT_TYPE" => 'application/json'
|
|
|
|
|
post '/api/sessions.json', defopts.merge({:client_id => client.client_id, :musician_access => false}).to_json, "CONTENT_TYPE" => 'application/json'
|
|
|
|
|
last_response.status.should eql(201)
|
|
|
|
|
session = JSON.parse(last_response.body)
|
|
|
|
|
|
|
|
|
|
@ -249,6 +256,7 @@ describe "Music Session API ", :type => :api do
|
|
|
|
|
music_session["id"].should == session["id"]
|
|
|
|
|
music_session["musician_access"].should == false
|
|
|
|
|
music_session["invitations"].should == []
|
|
|
|
|
music_session["fan_invitations"].should == []
|
|
|
|
|
music_session["participants"].length.should == 1
|
|
|
|
|
participant = music_session["participants"][0]
|
|
|
|
|
participant["ip_address"].should == client.ip_address
|
|
|
|
|
@ -262,7 +270,7 @@ describe "Music Session API ", :type => :api do
|
|
|
|
|
|
|
|
|
|
client = FactoryGirl.create(:connection, :user => user, :ip_address => "1.1.1.1")
|
|
|
|
|
|
|
|
|
|
post '/api/sessions.json', { :description => "a session", :client_id => client.client_id, :genres => ["classical"], :musician_access => false, :tracks => [{"instrument_id" => "electric guitar", "sound" => "mono"}]}.to_json, "CONTENT_TYPE" => 'application/json'
|
|
|
|
|
post '/api/sessions.json', defopts.merge({:client_id => client.client_id, :musician_access => false}).to_json, "CONTENT_TYPE" => 'application/json'
|
|
|
|
|
last_response.status.should eql(201)
|
|
|
|
|
session = JSON.parse(last_response.body)
|
|
|
|
|
|
|
|
|
|
@ -283,6 +291,8 @@ describe "Music Session API ", :type => :api do
|
|
|
|
|
invitation = music_session["invitations"][0]
|
|
|
|
|
invitation["id"].should == invitation_model.id
|
|
|
|
|
|
|
|
|
|
music_session["fan_invitations"].should == []
|
|
|
|
|
|
|
|
|
|
music_session["participants"].length.should == 1
|
|
|
|
|
participant = music_session["participants"][0]
|
|
|
|
|
participant["client_id"].should == client.client_id
|
|
|
|
|
@ -300,7 +310,7 @@ describe "Music Session API ", :type => :api do
|
|
|
|
|
client = FactoryGirl.create(:connection, :user => user, :ip_address => "1.1.1.1", :client_id => "3")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
post '/api/sessions.json', { :description => "a session", :client_id => client.client_id, :genres => ["classical"], :musician_access => false, :tracks => [{"instrument_id" => "electric guitar", "sound" => "mono"}]}.to_json, "CONTENT_TYPE" => 'application/json'
|
|
|
|
|
post '/api/sessions.json', defopts.merge({:client_id => client.client_id, :musician_access => false}).to_json, "CONTENT_TYPE" => 'application/json'
|
|
|
|
|
last_response.status.should eql(201)
|
|
|
|
|
session = JSON.parse(last_response.body)
|
|
|
|
|
|
|
|
|
|
|