VRFS-159 fixed bugs / added unit tests
This commit is contained in:
parent
a4b8421609
commit
946cf7c8d0
|
|
@ -254,18 +254,14 @@ class ApiUsersController < ApiController
|
|||
end
|
||||
|
||||
def friend_request_create
|
||||
begin
|
||||
@friend_request = FriendRequest.save(nil,
|
||||
params[:id],
|
||||
params[:friend_id],
|
||||
nil,
|
||||
params[:message])
|
||||
@friend_request = FriendRequest.save(nil,
|
||||
params[:id],
|
||||
params[:friend_id],
|
||||
nil,
|
||||
params[:message])
|
||||
|
||||
@user = current_user
|
||||
respond_with @friend_request, responder: ApiResponder, :status => 201, :location => api_friend_request_detail_url(@user, @friend_request)
|
||||
rescue JamRuby::JamStateError
|
||||
render :json => { :message => "Invalid friend request" }, :status => 400
|
||||
end
|
||||
@user = current_user
|
||||
respond_with @friend_request, responder: ApiResponder, :status => 201, :location => api_friend_request_detail_url(@user, @friend_request)
|
||||
end
|
||||
|
||||
def friend_request_update
|
||||
|
|
|
|||
|
|
@ -311,15 +311,6 @@ describe "Band API", :type => :api do
|
|||
end
|
||||
end
|
||||
|
||||
context "when logged in as band invitation recipient" do
|
||||
it "should allow acceptance of invitation" do
|
||||
# ensure recipient is now member of band
|
||||
end
|
||||
|
||||
it "should allow declining of invitation" do
|
||||
end
|
||||
end
|
||||
|
||||
context "when logged in as fan" do
|
||||
it "should not allow band creation" do
|
||||
end
|
||||
|
|
|
|||
|
|
@ -464,6 +464,7 @@ describe "User API", :type => :api do
|
|||
followings.size.should == 1
|
||||
end
|
||||
|
||||
######################### RECORDINGS ########################
|
||||
it "should allow musician to create recordings" do
|
||||
# create public recording
|
||||
public_description = "My Public Recording"
|
||||
|
|
@ -636,6 +637,7 @@ describe "User API", :type => :api do
|
|||
last_response.status.should == 403
|
||||
end
|
||||
|
||||
######################### FRIENDS ########################
|
||||
it "should allow user to send friend request" do
|
||||
# create friend request
|
||||
last_response = create_friend_request(user, user, fan, "Please accept my friend request")
|
||||
|
|
@ -661,7 +663,7 @@ describe "User API", :type => :api do
|
|||
friend_requests[0]["message"].should == "Please accept my friend request"
|
||||
|
||||
# accept friend request
|
||||
last_response = update_friend_request(user, user, friend_request["id"], "accept")
|
||||
last_response = update_friend_request(fan, fan, friend_request["id"], "accept")
|
||||
last_response.status.should == 200
|
||||
|
||||
# get user's friends
|
||||
|
|
@ -701,30 +703,98 @@ describe "User API", :type => :api do
|
|||
last_response.status.should == 403
|
||||
end
|
||||
|
||||
it "should allow user to accept friend request" do
|
||||
end
|
||||
|
||||
it "should allow user to ignore friend request" do
|
||||
# create friend request
|
||||
last_response = create_friend_request(user, user, fan, "Please accept my friend request")
|
||||
last_response.status.should == 201
|
||||
friend_request = JSON.parse(last_response.body)
|
||||
|
||||
# ignore friend request
|
||||
last_response = update_friend_request(fan, fan, friend_request["id"], "ignore")
|
||||
last_response.status.should == 200
|
||||
end
|
||||
|
||||
it "should allow user to block friend request" do
|
||||
# create friend request
|
||||
last_response = create_friend_request(user, user, fan, "Please accept my friend request")
|
||||
last_response.status.should == 201
|
||||
friend_request = JSON.parse(last_response.body)
|
||||
|
||||
# block friend request
|
||||
last_response = update_friend_request(fan, fan, friend_request["id"], "block")
|
||||
last_response.status.should == 200
|
||||
|
||||
# create another friend request to same user after blocking
|
||||
last_response = create_friend_request(user, user, fan, "Please accept my friend request")
|
||||
last_response.status.should == 201
|
||||
friend_request = JSON.parse(last_response.body)
|
||||
|
||||
# target user's friend requests should be empty
|
||||
last_response = get_friend_requests(fan, fan)
|
||||
friend_requests = JSON.parse(last_response.body)
|
||||
friend_requests.size.should == 0
|
||||
end
|
||||
|
||||
it "should allow user to mark friend request as spam" do
|
||||
# create friend request
|
||||
last_response = create_friend_request(user, user, fan, "Please accept my friend request")
|
||||
last_response.status.should == 201
|
||||
friend_request = JSON.parse(last_response.body)
|
||||
|
||||
# mark friend request as spam
|
||||
last_response = update_friend_request(fan, fan, friend_request["id"], "spam")
|
||||
last_response.status.should == 200
|
||||
end
|
||||
|
||||
it "should not allow user to respond to another user's friend request" do
|
||||
end
|
||||
# create friend request
|
||||
last_response = create_friend_request(user, user, fan, "Please accept my friend request")
|
||||
last_response.status.should == 201
|
||||
friend_request = JSON.parse(last_response.body)
|
||||
|
||||
it "should not allow user to send friend request if " do
|
||||
# accept friend request as another user
|
||||
another_user = FactoryGirl.create(:user)
|
||||
last_response = update_friend_request(another_user, fan, friend_request["id"], "accept")
|
||||
last_response.status.should == 403
|
||||
end
|
||||
|
||||
it "should allow user to delete friend" do
|
||||
# create friend request
|
||||
last_response = create_friend_request(user, user, fan, "Please accept my friend request")
|
||||
last_response.status.should == 201
|
||||
friend_request = JSON.parse(last_response.body)
|
||||
|
||||
# accept friend request
|
||||
last_response = update_friend_request(fan, fan, friend_request["id"], "accept")
|
||||
last_response.status.should == 200
|
||||
|
||||
# delete the friend
|
||||
last_response = delete_friend(user, user, fan)
|
||||
last_response.status.should == 204
|
||||
|
||||
last_response = get_friends(user, user)
|
||||
last_response.status.should == 200
|
||||
friends = JSON.parse(last_response.body)
|
||||
friends.size.should == 0
|
||||
end
|
||||
|
||||
it "should not allow user to delete another user's friend" do
|
||||
# create friend request
|
||||
last_response = create_friend_request(user, user, fan, "Please accept my friend request")
|
||||
last_response.status.should == 201
|
||||
friend_request = JSON.parse(last_response.body)
|
||||
|
||||
# accept friend request
|
||||
last_response = update_friend_request(fan, fan, friend_request["id"], "accept")
|
||||
last_response.status.should == 200
|
||||
|
||||
# attempt to delete as another user
|
||||
another_user = FactoryGirl.create(:user)
|
||||
last_response = delete_friend(another_user, user, fan)
|
||||
last_response.status.should == 403
|
||||
end
|
||||
|
||||
######################### BAND INVITATIONS ########################
|
||||
it "should allow user to accept band invitation" do
|
||||
recipient = FactoryGirl.create(:user)
|
||||
|
||||
|
|
@ -767,6 +837,36 @@ describe "User API", :type => :api do
|
|||
band_list = JSON.parse(last_response.body)
|
||||
band_list.size.should == 1
|
||||
band_list[0]["id"].should == band.id
|
||||
|
||||
# ensure user has recipient as friend
|
||||
last_response = get_friends(user, user)
|
||||
last_response.status.should == 200
|
||||
friends = JSON.parse(last_response.body)
|
||||
friends.size.should == 1
|
||||
friends[0]["id"].should == recipient.id
|
||||
friends[0]["first_name"].should == recipient.first_name
|
||||
friends[0]["last_name"].should == recipient.last_name
|
||||
friends[0]["city"].should == recipient.city
|
||||
friends[0]["state"].should == recipient.state
|
||||
friends[0]["country"].should == recipient.country
|
||||
friends[0]["email"].should == recipient.email
|
||||
friends[0]["online"].should == recipient.online
|
||||
friends[0]["photo_url"].should == recipient.photo_url
|
||||
|
||||
# ensure recipient has user as friend
|
||||
last_response = get_friends(recipient, recipient)
|
||||
last_response.status.should == 200
|
||||
friends = JSON.parse(last_response.body)
|
||||
friends.size.should == 1
|
||||
friends[0]["id"].should == user.id
|
||||
friends[0]["first_name"].should == user.first_name
|
||||
friends[0]["last_name"].should == user.last_name
|
||||
friends[0]["city"].should == user.city
|
||||
friends[0]["state"].should == user.state
|
||||
friends[0]["country"].should == user.country
|
||||
friends[0]["email"].should == user.email
|
||||
friends[0]["online"].should == user.online
|
||||
friends[0]["photo_url"].should == user.photo_url
|
||||
end
|
||||
|
||||
it "should allow user to decline band invitation" do
|
||||
|
|
@ -776,7 +876,6 @@ describe "User API", :type => :api do
|
|||
last_response.status.should == 201
|
||||
|
||||
invitation = JSON.parse(last_response.body)
|
||||
|
||||
last_response = update_band_invitation(recipient, recipient, invitation["id"], false)
|
||||
end
|
||||
end
|
||||
|
|
|
|||
Loading…
Reference in New Issue