ensl.org/spec/controllers/api/v1/users_controller_spec.rb

108 lines
3 KiB
Ruby
Raw Normal View History

2015-08-17 18:16:32 +00:00
require "spec_helper"
describe Api::V1::UsersController do
before do
2015-08-17 18:16:32 +00:00
request.accept = "application/json"
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
end
2015-08-17 18:16:32 +00:00
it "returns user data" do
get :show, id: @user.id
expect(response).to be_success
2015-08-17 18:16:32 +00:00
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).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
end
2015-07-22 16:22:38 +00:00
it "returns nulled steam data for users who had invalid steam ids" do
@user.steamid = nil
@user.save!
get :show, id: @user.id
expect(response).to be_success
expect(json["steam"]).to be_nil
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-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-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-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
end
2015-08-17 18:16:32 +00:00
describe "#index" do
before do
5.times { create(:user_with_team) }
end
2015-08-17 18:16:32 +00:00
it "returns all users and associated teams" do
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
get :index
user_json = json["users"].first
nested_team_json = user_json["team"]
expect(user_json).to have_key("username")
2015-08-17 17:55:03 +00:00
expect(user_json).to have_key("id")
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