tests: add user events controller tests.
This commit is contained in:
17
test/factories/ip_geolocation.rb
Normal file
17
test/factories/ip_geolocation.rb
Normal file
@@ -0,0 +1,17 @@
|
||||
FactoryBot.define do
|
||||
factory(:ip_geolocation) do
|
||||
ip_addr { FFaker::Internet.ip_v4_address }
|
||||
network { FFaker::Internet.ip_v4_address }
|
||||
asn { 42 }
|
||||
organization { "AT&T" }
|
||||
carrier { "AT&T" }
|
||||
is_proxy { false }
|
||||
latitude { 50.0 }
|
||||
longitude { 50.0 }
|
||||
time_zone { FFaker::Address.time_zone }
|
||||
continent { "NA" }
|
||||
country { "US" }
|
||||
region { FFaker::AddressUS.state_abbr }
|
||||
city { FFaker::AddressUS.city }
|
||||
end
|
||||
end
|
||||
@@ -1,5 +1,6 @@
|
||||
FactoryBot.define do
|
||||
factory(:user_event) do
|
||||
user
|
||||
user_session
|
||||
end
|
||||
end
|
||||
|
||||
7
test/factories/user_session.rb
Normal file
7
test/factories/user_session.rb
Normal file
@@ -0,0 +1,7 @@
|
||||
FactoryBot.define do
|
||||
factory(:user_session) do
|
||||
ip_addr { create(:ip_geolocation).ip_addr }
|
||||
session_id { SecureRandom.hex(32) }
|
||||
user_agent { "Mozilla/5.0" }
|
||||
end
|
||||
end
|
||||
17
test/functional/ip_geolocations_controller_test.rb
Normal file
17
test/functional/ip_geolocations_controller_test.rb
Normal file
@@ -0,0 +1,17 @@
|
||||
require 'test_helper'
|
||||
|
||||
class IpGeolocationsControllerTest < ActionDispatch::IntegrationTest
|
||||
context "The ip geolocations controller" do
|
||||
context "index action" do
|
||||
should "render for a moderator" do
|
||||
get_auth ip_geolocations_path, create(:moderator_user)
|
||||
assert_response :success
|
||||
end
|
||||
|
||||
should "fail for a normal user" do
|
||||
get_auth ip_geolocations_path, create(:user)
|
||||
assert_response 403
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
36
test/functional/user_events_controller_test.rb
Normal file
36
test/functional/user_events_controller_test.rb
Normal file
@@ -0,0 +1,36 @@
|
||||
require 'test_helper'
|
||||
|
||||
class UserEventsControllerTest < ActionDispatch::IntegrationTest
|
||||
context "The user events controller" do
|
||||
context "index action" do
|
||||
setup do
|
||||
@user = create(:user)
|
||||
create(:user_event, user: @user, category: :login)
|
||||
create(:user_event, user: @user, category: :password_change)
|
||||
create(:user_event, user: @user, category: :logout)
|
||||
end
|
||||
|
||||
should "render for an admin" do
|
||||
get_auth user_events_path, create(:admin_user)
|
||||
assert_response :success
|
||||
end
|
||||
|
||||
should "render for a mod" do
|
||||
get_auth user_events_path, create(:moderator_user)
|
||||
assert_response :success
|
||||
end
|
||||
|
||||
should "fail for a normal user" do
|
||||
get_auth user_events_path, @user
|
||||
assert_response 403
|
||||
end
|
||||
|
||||
should "only show mods authorized events" do
|
||||
get_auth user_events_path(search: { category: "password_change" }), create(:moderator_user)
|
||||
|
||||
assert_response :success
|
||||
assert_select "tbody tr", count: 0
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
17
test/functional/user_sessions_controller_test.rb
Normal file
17
test/functional/user_sessions_controller_test.rb
Normal file
@@ -0,0 +1,17 @@
|
||||
require 'test_helper'
|
||||
|
||||
class UserSessionsControllerTest < ActionDispatch::IntegrationTest
|
||||
context "The user sessions controller" do
|
||||
context "index action" do
|
||||
should "render for an admin" do
|
||||
get_auth user_sessions_path, create(:admin_user)
|
||||
assert_response :success
|
||||
end
|
||||
|
||||
should "fail for a normal user" do
|
||||
get_auth user_sessions_path, create(:user)
|
||||
assert_response 403
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user