diff --git a/Gemfile.lock b/Gemfile.lock index b62432f1..fff500bb 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -367,16 +367,16 @@ GEM puma (6.4.2) nio4r (~> 2.0) racc (1.7.3) - rack (2.2.9) + rack (3.0.11) rack-proxy (0.7.7) rack - rack-session (1.0.2) - rack (< 3) + rack-session (2.0.0) + rack (>= 3.0.0) rack-test (2.1.0) rack (>= 1.3) - rackup (1.0.0) - rack (< 3) - webrick + rackup (2.1.0) + rack (>= 3) + webrick (~> 1.8) rails (7.1.3.2) actioncable (= 7.1.3.2) actionmailbox (= 7.1.3.2) diff --git a/app/views/accounts/show.html.erb b/app/views/accounts/show.html.erb index 406cfb3e..69b44499 100644 --- a/app/views/accounts/show.html.erb +++ b/app/views/accounts/show.html.erb @@ -3,7 +3,7 @@

Account

<%= form_for '', url: settings_account_path, method: :patch, html: { autocomplete: 'off', class: 'space-y-4' } do |f| %> - <%= f.fields_for current_account do |ff| %> + <%= fields_for current_account do |ff| %>
<%= ff.label :name, 'Company Name', class: 'label' %> <%= ff.text_field :name, required: true, class: 'base-input', dir: 'auto' %> @@ -23,7 +23,7 @@ <% end %> <% encrypted_config = @encrypted_config || EncryptedConfig.find_or_initialize_by(account: current_account, key: EncryptedConfig::APP_URL_KEY) %> <% if !Docuseal.multitenant? && can?(:manage, encrypted_config) && !current_account.testing? %> - <%= f.fields_for encrypted_config do |ff| %> + <%= fields_for encrypted_config do |ff| %>
<%= ff.label :value, 'App URL', class: 'label' %> <%= ff.text_field :value, autocomplete: 'off', class: 'base-input' %> diff --git a/app/views/setup/index.html.erb b/app/views/setup/index.html.erb index 43d32b23..2daf7690 100644 --- a/app/views/setup/index.html.erb +++ b/app/views/setup/index.html.erb @@ -2,7 +2,7 @@

Initial Setup 👋

<%= form_for '', html: { class: 'space-y-6' }, url: setup_index_path do |f| %>
- <%= f.fields_for @user do |ff| %> + <%= fields_for @user do |ff| %>
<%= ff.label :first_name, class: 'label' %> @@ -14,30 +14,30 @@
<% end %> - <%= f.fields_for @user do |ff| %> + <%= fields_for @user do |ff| %>
<%= ff.label :email, class: 'label' %> <%= ff.email_field :email, required: true, class: 'base-input' %>
<% end %> - <%= f.fields_for @account do |ff| %> - + <%= fields_for @account do |ff| %> + <%= ff.hidden_field :timezone %>
<%= ff.label :name, 'Company name', class: 'label' %> <%= ff.text_field :name, required: true, class: 'base-input' %>
<% end %> - <%= f.fields_for @user do |ff| %> + <%= fields_for @user do |ff| %>
<%= ff.label :password, class: 'label' %> <%= ff.password_field :password, required: true, placeholder: '************', class: 'base-input' %>
<% end %> - <%= f.fields_for @encrypted_config do |ff| %> + <%= fields_for @encrypted_config do |ff| %>
<% if @encrypted_config.value.blank? %> - + <% end %> <%= ff.label :value, 'App URL', class: 'label' %> <%= ff.text_field :value, required: true, class: 'base-input' %> diff --git a/spec/factories/account_configs.rb b/spec/factories/account_configs.rb new file mode 100644 index 00000000..9579353c --- /dev/null +++ b/spec/factories/account_configs.rb @@ -0,0 +1,7 @@ +# frozen_string_literal: true + +FactoryBot.define do + factory :account_config do + account + end +end diff --git a/spec/factories/user_configs.rb b/spec/factories/user_configs.rb new file mode 100644 index 00000000..4366721b --- /dev/null +++ b/spec/factories/user_configs.rb @@ -0,0 +1,7 @@ +# frozen_string_literal: true + +FactoryBot.define do + factory :user_config do + user + end +end diff --git a/spec/system/notifications_settings_spec.rb b/spec/system/notifications_settings_spec.rb new file mode 100644 index 00000000..4f0d0f7c --- /dev/null +++ b/spec/system/notifications_settings_spec.rb @@ -0,0 +1,100 @@ +# frozen_string_literal: true + +require 'rails_helper' + +RSpec.describe 'Notifications Settings' do + let(:user) { create(:user, account: create(:account)) } + + before do + sign_in(user) + end + + it 'shows the notifications settings page' do + visit settings_notifications_path + + expect(page).to have_content('Email Notifications') + expect(page).to have_content('Receive notification emails on completed submission') + expect(page).to have_content('Sign Request Email Reminders') + + expect(page).to have_field('account_config[value]') + expect(page).to have_field('user_config[value]') + %w[first_duration second_duration third_duration].each do |duration| + expect(page).to have_field("account_config[value][#{duration}]") + end + end + + context 'when changes email notifications settings' do + it 'updates BCC email address' do + visit settings_notifications_path + + fill_in 'account_config[value]', with: 'john.doe@example.com' + + all(:button, 'Save')[0].click + + expect(page).to have_content('Changes have been saved') + + account_config = AccountConfig.find_by(account: user.account, key: AccountConfig::BCC_EMAILS) + + expect(account_config.value).to eq('john.doe@example.com') + end + + it 'delete BCC email address' do + create(:account_config, account: user.account, key: AccountConfig::BCC_EMAILS, value: 'john.doe.bbc@example.com') + + visit settings_notifications_path + + expect(page).to have_field('account_config[value]', with: 'john.doe.bbc@example.com') + + fill_in 'account_config[value]', with: '' + + all(:button, 'Save')[0].click + + expect(page).to have_content('Changes have been saved') + end + + it 'disable receive notification emails on completed submission' do + visit settings_notifications_path + + uncheck 'user_config[value]' + + expect(UserConfig.find_by(user:, key: UserConfig::RECEIVE_COMPLETED_EMAIL).value).to be false + end + + it 'enable receive notification emails on completed submission' do + create(:user_config, user:, key: UserConfig::RECEIVE_COMPLETED_EMAIL, value: false) + + visit settings_notifications_path + + check 'user_config[value]' + + expect(UserConfig.find_by(user:, key: UserConfig::RECEIVE_COMPLETED_EMAIL).value).to be true + end + end + + context 'when changes sign request email reminders settings' do + it 'updates first reminder duration' do + visit settings_notifications_path + + selected_values = %w[first_duration second_duration third_duration].index_with do |_| + AccountConfigs::REMINDER_DURATIONS.keys.sample + end + + selected_values.each do |duration, value| + selected_duration_name = AccountConfigs::REMINDER_DURATIONS[value] + select selected_duration_name, from: "account_config[value][#{duration}]" + end + + expect do + all(:button, 'Save')[1].click + end.to change(AccountConfig, :count).by(1) + + account_config = AccountConfig.find_by(account: user.account, key: AccountConfig::SUBMITTER_REMINDERS) + + expect(page).to have_content('Changes have been saved') + + selected_values.each do |duration, value| + expect(account_config.value[duration]).to eq(value) + end + end + end +end diff --git a/spec/system/personalization_settings_spec.rb b/spec/system/personalization_settings_spec.rb new file mode 100644 index 00000000..9d16d0c0 --- /dev/null +++ b/spec/system/personalization_settings_spec.rb @@ -0,0 +1,19 @@ +# frozen_string_literal: true + +require 'rails_helper' + +RSpec.describe 'Personalization Settings', :js do + let!(:account) { create(:account) } + let!(:user) { create(:user, account:) } + + before do + sign_in(user) + visit settings_personalization_path + end + + it 'shows the notifications settings page' do + expect(page).to have_content('Email Templates') + expect(page).to have_content('Company Logo') + expect(page).to have_content('Submission Form') + end +end