2020-01-03 12:44:06 +11:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
require 'rails_helper'
|
|
|
|
|
2023-02-19 08:59:00 +11:00
|
|
|
describe 'Log in' do
|
2020-01-03 12:44:06 +11:00
|
|
|
include ProfileStories
|
2017-04-15 09:21:02 +10:00
|
|
|
|
2023-02-19 08:59:00 +11:00
|
|
|
subject { page }
|
|
|
|
|
2023-02-19 09:38:14 +11:00
|
|
|
let(:email) { 'test@example.com' }
|
|
|
|
let(:password) { 'password' }
|
2023-02-19 08:59:00 +11:00
|
|
|
let(:confirmed_at) { Time.zone.now }
|
2017-06-01 01:09:17 +10:00
|
|
|
|
2023-02-19 08:59:00 +11:00
|
|
|
before do
|
2020-01-03 12:44:06 +11:00
|
|
|
as_a_registered_user
|
2017-06-02 01:25:59 +10:00
|
|
|
visit new_user_session_path
|
2017-06-01 01:09:17 +10:00
|
|
|
end
|
2017-04-15 09:21:02 +10:00
|
|
|
|
2023-02-19 08:59:00 +11:00
|
|
|
it 'A valid email and password user is able to log in' do
|
2020-01-03 12:44:06 +11:00
|
|
|
fill_in 'user_email', with: email
|
|
|
|
fill_in 'user_password', with: password
|
2024-01-04 20:20:32 +11:00
|
|
|
click_on I18n.t('auth.login')
|
2017-06-02 01:25:59 +10:00
|
|
|
|
2023-02-20 15:00:48 +11:00
|
|
|
expect(subject).to have_css('div.app-holder')
|
2017-06-02 01:25:59 +10:00
|
|
|
end
|
|
|
|
|
2023-02-19 08:59:00 +11:00
|
|
|
it 'A invalid email and password user is not able to log in' do
|
2020-01-03 12:44:06 +11:00
|
|
|
fill_in 'user_email', with: 'invalid_email'
|
|
|
|
fill_in 'user_password', with: 'invalid_password'
|
2024-01-04 20:20:32 +11:00
|
|
|
click_on I18n.t('auth.login')
|
2017-06-02 01:25:59 +10:00
|
|
|
|
2023-02-20 15:00:48 +11:00
|
|
|
expect(subject).to have_css('.flash-message', text: failure_message('invalid'))
|
2017-06-02 01:25:59 +10:00
|
|
|
end
|
|
|
|
|
2023-06-06 23:51:42 +10:00
|
|
|
context 'when confirmed at is nil' do
|
2023-02-19 08:59:00 +11:00
|
|
|
let(:confirmed_at) { nil }
|
2017-06-02 01:25:59 +10:00
|
|
|
|
2023-02-19 08:59:00 +11:00
|
|
|
it 'A unconfirmed user is able to log in' do
|
2020-01-03 12:44:06 +11:00
|
|
|
fill_in 'user_email', with: email
|
|
|
|
fill_in 'user_password', with: password
|
2024-01-04 20:20:32 +11:00
|
|
|
click_on I18n.t('auth.login')
|
2017-06-02 01:25:59 +10:00
|
|
|
|
2023-02-20 15:00:48 +11:00
|
|
|
expect(subject).to have_css('div.admin-wrapper')
|
2017-06-02 01:25:59 +10:00
|
|
|
end
|
|
|
|
end
|
2017-04-15 09:21:02 +10:00
|
|
|
|
2017-06-02 01:25:59 +10:00
|
|
|
def failure_message(message)
|
|
|
|
keys = User.authentication_keys.map { |key| User.human_attribute_name(key) }
|
2020-01-03 12:44:06 +11:00
|
|
|
I18n.t("devise.failure.#{message}", authentication_keys: keys.join('support.array.words_connector'))
|
2017-04-15 09:21:02 +10:00
|
|
|
end
|
|
|
|
end
|