Skip to content

Commit

Permalink
Merge pull request #1155 from eip-ewi/system-test-login
Browse files Browse the repository at this point in the history
  • Loading branch information
ArtOfCode- authored Aug 2, 2023
2 parents 2770b5f + 33efbff commit c45f201
Show file tree
Hide file tree
Showing 4 changed files with 71 additions and 39 deletions.
3 changes: 2 additions & 1 deletion test/application_system_test_case.rb
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,9 @@ def log_in(user_or_fixture, password = 'test123')
def log_out
within :css, '.header' do
find(:css, 'i.far.fa-caret-square-down').find(:xpath, '..').click
click_on 'Sign Out'
end

find_link('Sign Out').click
end

# Pretends the user has clicked the confirmation link in the email they received.
Expand Down
24 changes: 12 additions & 12 deletions test/fixtures/users.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
standard_user:
email: [email protected]
encrypted_password: abcdefghijklmnopqrstuvwxyz
encrypted_password: '$2a$11$roUHXKxecjyQ72Qn7DWs3.9eRCCoRn176kX/UNb/xiue3aGqf7xEW'
sign_in_count: 1337
username: standard_user
is_global_admin: false
Expand All @@ -9,7 +9,7 @@ standard_user:

closer:
email: [email protected]
encrypted_password: abcdefghijklmnopqrstuvwxyz
encrypted_password: '$2a$11$roUHXKxecjyQ72Qn7DWs3.9eRCCoRn176kX/UNb/xiue3aGqf7xEW'
sign_in_count: 1337
username: closer
website: https://example.com/closer
Expand All @@ -22,7 +22,7 @@ closer:

editor:
email: [email protected]
encrypted_password: abcdefghijklmnopqrstuvwxyz
encrypted_password: '$2a$11$roUHXKxecjyQ72Qn7DWs3.9eRCCoRn176kX/UNb/xiue3aGqf7xEW'
sign_in_count: 1337
username: editor
is_global_admin: false
Expand All @@ -33,7 +33,7 @@ editor:

deleter:
email: [email protected]
encrypted_password: abcdefghijklmnopqrstuvwxyz
encrypted_password: '$2a$11$roUHXKxecjyQ72Qn7DWs3.9eRCCoRn176kX/UNb/xiue3aGqf7xEW'
sign_in_count: 1337
username: deleter
is_global_admin: false
Expand All @@ -42,7 +42,7 @@ deleter:

moderator:
email: [email protected]
encrypted_password: abcdefghijklmnopqrstuvwxyz
encrypted_password: '$2a$11$roUHXKxecjyQ72Qn7DWs3.9eRCCoRn176kX/UNb/xiue3aGqf7xEW'
sign_in_count: 1337
username: moderator
is_global_admin: false
Expand All @@ -51,7 +51,7 @@ moderator:

admin:
email: [email protected]
encrypted_password: abcdefghijklmnopqrstuvwxyz
encrypted_password: '$2a$11$roUHXKxecjyQ72Qn7DWs3.9eRCCoRn176kX/UNb/xiue3aGqf7xEW'
sign_in_count: 1337
username: admin
is_global_admin: false
Expand All @@ -60,7 +60,7 @@ admin:

global_moderator:
email: [email protected]
encrypted_password: abcdefghijklmnopqrstuvwxyz
encrypted_password: '$2a$11$roUHXKxecjyQ72Qn7DWs3.9eRCCoRn176kX/UNb/xiue3aGqf7xEW'
sign_in_count: 1337
username: global-moderator
is_global_admin: false
Expand All @@ -69,7 +69,7 @@ global_moderator:

global_admin:
email: [email protected]
encrypted_password: abcdefghijklmnopqrstuvwxyz
encrypted_password: '$2a$11$roUHXKxecjyQ72Qn7DWs3.9eRCCoRn176kX/UNb/xiue3aGqf7xEW'
sign_in_count: 1337
username: global-admin
is_global_admin: true
Expand All @@ -78,7 +78,7 @@ global_admin:

no_community_user:
email: [email protected]
encrypted_password: abcdefghijklmnopqrstuvwxyz
encrypted_password: '$2a$11$roUHXKxecjyQ72Qn7DWs3.9eRCCoRn176kX/UNb/xiue3aGqf7xEW'
sign_in_count: 1337
username: no_community_user
is_global_admin: false
Expand All @@ -88,7 +88,7 @@ no_community_user:
system:
id: -99
email: [email protected]
encrypted_password: abcdefghijklmnopqrstuvwxyz
encrypted_password: '$2a$11$roUHXKxecjyQ72Qn7DWs3.9eRCCoRn176kX/UNb/xiue3aGqf7xEW'
sign_in_count: 1337
username: system
is_global_admin: true
Expand All @@ -97,7 +97,7 @@ system:

deleted_account:
email: [email protected]
encrypted_password: abcdefghijklmnopqrstuvwxyz
encrypted_password: '$2a$11$roUHXKxecjyQ72Qn7DWs3.9eRCCoRn176kX/UNb/xiue3aGqf7xEW'
sign_in_count: 1337
username: deleted_account
confirmed_at: 2020-01-01T00:00:00.000000Z
Expand All @@ -107,7 +107,7 @@ deleted_account:

deleted_profile:
email: [email protected]
encrypted_password: abcdefghijklmnopqrstuvwxyz
encrypted_password: '$2a$11$roUHXKxecjyQ72Qn7DWs3.9eRCCoRn176kX/UNb/xiue3aGqf7xEW'
sign_in_count: 1337
username: deleted_profile
confirmed_at: 2020-01-01T00:00:00.000000Z
26 changes: 0 additions & 26 deletions test/system/basic_test.rb

This file was deleted.

57 changes: 57 additions & 0 deletions test/system/login_test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
require 'application_system_test_case'

class LoginTest < ApplicationSystemTestCase
test 'User can register a new account and sign-in to it after confirming their email' do
email = '[email protected]'
username = 'Test User'
password = 'login_test_1'

# Sign up for an account
visit root_url
click_on 'Sign Up'
fill_in 'Email', with: email
fill_in 'Username', with: username
fill_in 'Password', with: password
fill_in 'Password confirmation', with: password

# Check that the user is created in the DB
assert_difference 'User.count' do
click_on 'Sign up'
end

user = User.last

# Try logging in directly, this should fail because not confirmed yet
log_in user, password
assert_selector '.notice', text: 'You have to confirm your email address before continuing.'

# Confirm email and sign in again, should succeed this time
confirm_email user
log_in user, password
assert_selector '.notice', text: 'Signed in successfully.'
end

test 'User can sign in and is redirected back to the page they were on' do
# Start on the users page
visit users_url

# Click the sign in button (top right)
# Don't go through log_in helper, since we want to test the sign-in fully here
click_on 'Sign In'
fill_in 'Email', with: users(:standard_user).email
fill_in 'Password', with: 'test123'
click_button 'Sign in'

# We should see a message that we have signed in, and we should be on the users page again.
assert_selector '.notice', text: 'Signed in successfully.'
assert_current_path users_url
end

test 'User can sign out' do
log_in :standard_user
assert_selector '.notice', text: 'Signed in successfully.'

log_out
assert_selector '.notice', text: 'Signed out successfully.'
end
end

0 comments on commit c45f201

Please sign in to comment.