2015-08-17 18:16:32 +00:00
|
|
|
require "spec_helper"
|
2014-03-29 00:59:26 +00:00
|
|
|
|
|
|
|
describe Api::V1::UsersController do
|
|
|
|
before do
|
2015-08-17 18:16:32 +00:00
|
|
|
request.accept = "application/json"
|
2014-03-29 00:59:26 +00:00
|
|
|
end
|
|
|
|
|
2015-08-17 18:16:32 +00:00
|
|
|
describe "#show" do
|
2015-08-01 16:05:17 +00:00
|
|
|
before(:each) do
|
|
|
|
@user = create :user, :chris
|
2015-07-21 13:27:33 +00:00
|
|
|
end
|
|
|
|
|
2015-10-28 16:11:01 +00:00
|
|
|
def user_expectation(json, user)
|
|
|
|
expect(json["id"]).to eq(user.id)
|
|
|
|
expect(json["username"]).to eq(user.username)
|
|
|
|
expect(json["country"]).to eq(user.country)
|
|
|
|
expect(json["time_zone"]).to eq(user.time_zone)
|
|
|
|
expect(json["admin"]).to eq(user.admin?)
|
|
|
|
expect(json["referee"]).to eq(user.ref?)
|
|
|
|
expect(json["caster"]).to eq(user.caster?)
|
|
|
|
expect(json["moderator"]).to eq(user.gather_moderator?)
|
2015-07-21 13:27:33 +00:00
|
|
|
expect(json).to have_key("steam")
|
2015-08-30 14:58:06 +00:00
|
|
|
expect(json["steam"]).to have_key("id")
|
2015-08-17 18:16:32 +00:00
|
|
|
expect(json["steam"]).to have_key("url")
|
|
|
|
expect(json["steam"]).to have_key("nickname")
|
|
|
|
expect(json["bans"]["mute"]).to eq(false)
|
|
|
|
expect(json["bans"]["gather"]).to eq(false)
|
|
|
|
expect(json["bans"]["site"]).to eq(false)
|
|
|
|
expect(json["team"]).to be_nil
|
2015-07-21 13:27:33 +00:00
|
|
|
end
|
2015-07-22 16:22:38 +00:00
|
|
|
|
2015-10-28 16:11:01 +00:00
|
|
|
it "returns user data" do
|
|
|
|
get :show, id: @user.id
|
|
|
|
|
|
|
|
expect(response).to be_success
|
|
|
|
user_expectation(json, @user)
|
|
|
|
end
|
|
|
|
|
|
|
|
it "returns user data for query with id specified as format" do
|
|
|
|
get :show, id: @user.id, format: "id"
|
|
|
|
|
|
|
|
expect(response).to be_success
|
|
|
|
user_expectation(json, @user)
|
|
|
|
end
|
|
|
|
|
|
|
|
it "returns user data for a numeric steamid query" do
|
|
|
|
m = @user.steamid.match(/\A0:([01]):(\d{1,10})\Z/)
|
|
|
|
steamid = (m[2].to_i << 1) + m[1].to_i
|
|
|
|
|
|
|
|
get :show, id: steamid, format: "steamid"
|
|
|
|
|
|
|
|
expect(response).to be_success
|
|
|
|
user_expectation(json, @user)
|
|
|
|
end
|
|
|
|
|
|
|
|
it "returns user data for a string steamid query" do
|
|
|
|
get :show, id: @user.steamid, format: "steamidstr"
|
|
|
|
|
|
|
|
expect(response).to be_success
|
|
|
|
user_expectation(json, @user)
|
|
|
|
end
|
|
|
|
|
2015-09-24 02:16:35 +00:00
|
|
|
it "returns nulled steam data for users who had invalid steam ids" do
|
|
|
|
@user.steamid = nil
|
2015-08-17 18:06:47 +00:00
|
|
|
@user.save!
|
|
|
|
|
|
|
|
get :show, id: @user.id
|
|
|
|
|
|
|
|
expect(response).to be_success
|
2015-09-24 02:16:35 +00:00
|
|
|
expect(json["steam"]).to be_nil
|
2015-08-17 18:06:47 +00:00
|
|
|
end
|
|
|
|
|
2015-10-20 17:11:46 +00:00
|
|
|
it "returns gather moderator status" do
|
|
|
|
group = create :group, :gather_moderator
|
|
|
|
create :grouper, user: @user, group: group
|
|
|
|
get :show, id: @user.id
|
|
|
|
expect(json["moderator"]).to eq(true)
|
|
|
|
end
|
|
|
|
|
2015-08-17 18:16:32 +00:00
|
|
|
it "returns 404 if user does not exist" do
|
2015-07-22 16:22:38 +00:00
|
|
|
expect {
|
|
|
|
get :show, id: -1
|
|
|
|
}.to raise_error(ActionController::RoutingError)
|
|
|
|
end
|
2015-08-01 15:44:39 +00:00
|
|
|
|
2015-08-17 18:16:32 +00:00
|
|
|
it "returns correct ban if user muted" do
|
2015-08-01 15:44:39 +00:00
|
|
|
create :ban, :mute, user: @user
|
|
|
|
get :show, id: @user.id
|
|
|
|
expect(response).to be_success
|
2015-08-17 18:16:32 +00:00
|
|
|
expect(json["bans"]["mute"]).to eq(true)
|
2015-08-01 15:44:39 +00:00
|
|
|
end
|
2015-08-15 11:50:28 +00:00
|
|
|
|
2015-08-17 18:16:32 +00:00
|
|
|
it "returns correct ban if user gather banned" do
|
2015-08-01 15:44:39 +00:00
|
|
|
create :ban, :gather, user: @user
|
|
|
|
get :show, id: @user.id
|
|
|
|
expect(response).to be_success
|
2015-08-17 18:16:32 +00:00
|
|
|
expect(json["bans"]["gather"]).to eq(true)
|
2015-08-01 15:44:39 +00:00
|
|
|
end
|
2015-08-15 11:50:28 +00:00
|
|
|
|
2015-08-17 18:16:32 +00:00
|
|
|
it "returns correct ban if user site banned" do
|
2015-08-01 15:44:39 +00:00
|
|
|
create :ban, :site, user: @user
|
|
|
|
get :show, id: @user.id
|
|
|
|
expect(response).to be_success
|
2015-08-17 18:16:32 +00:00
|
|
|
expect(json["bans"]["site"]).to eq(true)
|
2015-08-01 15:44:39 +00:00
|
|
|
end
|
2015-08-15 11:50:28 +00:00
|
|
|
|
2015-08-17 18:16:32 +00:00
|
|
|
it "returns team information" do
|
2015-08-01 16:05:17 +00:00
|
|
|
@user.destroy
|
|
|
|
@user_with_team = create :user_with_team, :chris
|
|
|
|
get :show, id: @user_with_team.id
|
|
|
|
expect(response).to be_success
|
2015-08-17 18:16:32 +00:00
|
|
|
expect(json["team"]["id"]).to eq(@user_with_team.team.id)
|
|
|
|
expect(json["team"]["name"]).to eq(@user_with_team.team.name)
|
2015-08-01 16:05:17 +00:00
|
|
|
end
|
2015-07-21 13:27:33 +00:00
|
|
|
end
|
|
|
|
|
2015-08-17 18:16:32 +00:00
|
|
|
describe "#index" do
|
2014-03-29 00:59:26 +00:00
|
|
|
before do
|
2015-07-21 13:27:33 +00:00
|
|
|
5.times { create(:user_with_team) }
|
2014-03-29 00:59:26 +00:00
|
|
|
end
|
|
|
|
|
2015-08-17 18:16:32 +00:00
|
|
|
it "returns all users and associated teams" do
|
2014-03-29 00:59:26 +00:00
|
|
|
users = User.all
|
|
|
|
|
|
|
|
get :index
|
|
|
|
|
|
|
|
expect(response).to be_success
|
|
|
|
expect(json["users"].size).to eq(users.size)
|
|
|
|
end
|
|
|
|
|
2015-08-17 18:16:32 +00:00
|
|
|
it "returns the excpected JSON keys" do
|
2014-03-29 00:59:26 +00:00
|
|
|
get :index
|
|
|
|
user_json = json["users"].first
|
|
|
|
nested_team_json = user_json["team"]
|
2015-08-15 11:50:28 +00:00
|
|
|
|
2014-03-29 00:59:26 +00:00
|
|
|
expect(user_json).to have_key("username")
|
2015-08-17 17:55:03 +00:00
|
|
|
expect(user_json).to have_key("id")
|
2014-03-29 00:59:26 +00:00
|
|
|
expect(user_json).to have_key("steamid")
|
|
|
|
expect(user_json).to have_key("team")
|
|
|
|
expect(nested_team_json).to have_key("name")
|
|
|
|
expect(nested_team_json).to have_key("tag")
|
|
|
|
expect(nested_team_json).to have_key("logo")
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|