2019-10-17 18:29:15 +00:00
|
|
|
require 'rails_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?)
|
2019-11-12 23:20:18 +00:00
|
|
|
expect(json["contributor"]).to eq(user.contributor?)
|
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
|
2020-03-23 02:22:12 +00:00
|
|
|
get :show, params: { id: @user.id }
|
2015-10-28 16:11:01 +00:00
|
|
|
|
2020-03-23 02:22:12 +00:00
|
|
|
expect(response).to have_http_status(:success)
|
2015-10-28 16:11:01 +00:00
|
|
|
user_expectation(json, @user)
|
|
|
|
end
|
|
|
|
|
|
|
|
it "returns user data for query with id specified as format" do
|
2020-03-23 02:22:12 +00:00
|
|
|
get :show, params: { id: @user.id, format: "id" }
|
2015-10-28 16:11:01 +00:00
|
|
|
|
2020-03-23 02:22:12 +00:00
|
|
|
expect(response).to have_http_status(:success)
|
2015-10-28 16:11:01 +00:00
|
|
|
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
|
|
|
|
|
2020-03-23 02:22:12 +00:00
|
|
|
get :show, params: { id: steamid, format: "steamid" }
|
2015-10-28 16:11:01 +00:00
|
|
|
|
2020-03-23 02:22:12 +00:00
|
|
|
expect(response).to have_http_status(:success)
|
2015-10-28 16:11:01 +00:00
|
|
|
user_expectation(json, @user)
|
|
|
|
end
|
|
|
|
|
|
|
|
it "returns user data for a string steamid query" do
|
2020-03-23 02:22:12 +00:00
|
|
|
get :show, params: { id: @user.steamid, format: "steamidstr" }
|
2015-10-28 16:11:01 +00:00
|
|
|
|
2020-03-23 02:22:12 +00:00
|
|
|
expect(response).to have_http_status(:success)
|
2015-10-28 16:11:01 +00:00
|
|
|
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!
|
|
|
|
|
2020-03-23 02:22:12 +00:00
|
|
|
get :show, params: { id: @user.id }
|
2015-08-17 18:06:47 +00:00
|
|
|
|
2020-03-23 02:22:12 +00:00
|
|
|
expect(response).to have_http_status(: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
|
2020-03-23 02:22:12 +00:00
|
|
|
get :show, params: { id: @user.id }
|
2015-10-20 17:11:46 +00:00
|
|
|
expect(json["moderator"]).to eq(true)
|
|
|
|
end
|
|
|
|
|
2015-08-17 18:16:32 +00:00
|
|
|
it "returns 404 if user does not exist" do
|
2020-03-23 02:22:12 +00:00
|
|
|
get :show, params: { id: -1 }
|
2017-09-30 02:07:40 +00:00
|
|
|
expect(response.status).to eq(404)
|
2017-09-30 12:35:27 +00:00
|
|
|
expect(json["error"]).to eq("User not found")
|
2015-11-03 07:50:14 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
it "returns 404 if user does not exist by steamid" do
|
2020-03-23 02:22:12 +00:00
|
|
|
get :show, params: { id: -1, format: "steamid" }
|
2017-09-30 02:07:40 +00:00
|
|
|
expect(response.status).to eq(404)
|
2017-09-30 12:35:27 +00:00
|
|
|
expect(json["error"]).to eq("User not found")
|
2015-11-03 07:50:14 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
it "queries the steam condenser for an invalid steamid" do
|
|
|
|
@user.update_attribute(:steamid, "0:0:0")
|
|
|
|
|
2020-03-23 02:22:12 +00:00
|
|
|
get :show, params: { id: @user.id }
|
2015-11-03 07:50:14 +00:00
|
|
|
|
2020-03-23 02:22:12 +00:00
|
|
|
expect(response).to have_http_status(:success)
|
2015-11-03 07:50:14 +00:00
|
|
|
expect(json["steam"]).to_not be_nil
|
|
|
|
expect(json["steam"]["id"]).to eq(@user.steamid)
|
|
|
|
expect(json["steam"]["url"]).to be_nil
|
|
|
|
expect(json["steam"]["nickname"]).to be_nil
|
2015-07-22 16:22:38 +00:00
|
|
|
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
|
2020-03-23 02:22:12 +00:00
|
|
|
get :show, params: { id: @user.id }
|
|
|
|
expect(response).to have_http_status(: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
|
|
|
|
2020-03-23 03:11:36 +00:00
|
|
|
# it "returns correct ban if user gather banned" do
|
|
|
|
# create :ban, :gather, user: @user
|
|
|
|
# get :show, params: { id: @user.id }
|
|
|
|
# expect(response).to have_http_status(:success)
|
|
|
|
# expect(json["bans"]["gather"]).to eq(true)
|
|
|
|
# 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
|
2020-03-23 02:22:12 +00:00
|
|
|
get :show, params: { id: @user.id }
|
|
|
|
expect(response).to have_http_status(: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
|
2020-03-23 02:22:12 +00:00
|
|
|
get :show, params: { id: @user_with_team.id }
|
|
|
|
expect(response).to have_http_status(: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
|
|
|
|
|
2020-03-23 02:22:12 +00:00
|
|
|
expect(response).to have_http_status(:success)
|
2014-03-29 00:59:26 +00:00
|
|
|
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
|