Save Confirmation - Admin (Part 1 of 2) (#14418)
This commit is contained in:
parent
eec0793c06
commit
877cb5c322
36 changed files with 404 additions and 475 deletions
|
|
@ -1,37 +1,21 @@
|
|||
module Admin
|
||||
module Settings
|
||||
class BaseController < Admin::ApplicationController
|
||||
MISMATCH_ERROR = "The confirmation key does not match".freeze
|
||||
|
||||
before_action :extra_authorization_and_confirmation, only: [:create]
|
||||
before_action :authorize_super_admin
|
||||
|
||||
def create
|
||||
result = upsert_config(settings_params)
|
||||
|
||||
if result.success?
|
||||
Audit::Logger.log(:internal, current_user, params.dup)
|
||||
redirect_to admin_config_path, notice: "Successfully updated settings."
|
||||
render json: { message: "Successfully updated settings." }, status: :ok
|
||||
else
|
||||
redirect_to admin_config_path, alert: "😭 #{result.errors.to_sentence}"
|
||||
render json: { error: result.errors.to_sentence }, status: :unprocessable_entity
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def extra_authorization_and_confirmation
|
||||
not_authorized unless current_user.has_role?(:super_admin)
|
||||
raise_confirmation_mismatch_error unless confirmation_text_valid?
|
||||
end
|
||||
|
||||
def confirmation_text_valid?
|
||||
params.require(:confirmation) ==
|
||||
"My username is @#{current_user.username} and this action is 100% safe and appropriate."
|
||||
end
|
||||
|
||||
def raise_confirmation_mismatch_error
|
||||
raise ActionController::BadRequest.new, MISMATCH_ERROR
|
||||
end
|
||||
|
||||
# Override this method if you need to call a custom class for upserting.
|
||||
# Ideally such a class eventually calls out to Settings::Upsert and returns
|
||||
# the result of that service.
|
||||
|
|
@ -46,6 +30,10 @@ module Admin
|
|||
.require(:"settings_#{authorization_resource.name.demodulize.underscore}")
|
||||
.permit(*authorization_resource.keys)
|
||||
end
|
||||
|
||||
def authorize_super_admin
|
||||
raise Pundit::NotAuthorizedError unless current_user.has_role?(:super_admin)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -12,9 +12,9 @@ module Admin
|
|||
result = ::Settings::General::Upsert.call(settings_params)
|
||||
if result.success?
|
||||
Audit::Logger.log(:internal, current_user, params.dup)
|
||||
redirect_to admin_config_path, notice: "Successfully updated settings."
|
||||
render json: { message: "Successfully updated settings." }, status: :ok
|
||||
else
|
||||
redirect_to admin_config_path, alert: "😭 #{result.errors.to_sentence}"
|
||||
render json: { error: result.errors.to_sentence }, status: :unprocessable_entity
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
|||
|
|
@ -1,6 +1,8 @@
|
|||
module Admin
|
||||
module Settings
|
||||
class SMTPSettingsController < Admin::Settings::BaseController
|
||||
private
|
||||
|
||||
def authorization_resource
|
||||
::Settings::SMTP
|
||||
end
|
||||
|
|
|
|||
|
|
@ -93,6 +93,37 @@ export default class ConfigController extends Controller {
|
|||
}
|
||||
}
|
||||
|
||||
displaySnackbar(message) {
|
||||
return document.dispatchEvent(
|
||||
new CustomEvent('snackbar:add', {
|
||||
detail: { message },
|
||||
}),
|
||||
);
|
||||
}
|
||||
|
||||
async updateConfigurationSettings(event) {
|
||||
event.preventDefault();
|
||||
try {
|
||||
const body = new FormData(event.target);
|
||||
const response = await fetch(event.target.action, {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
Accept: 'application/json',
|
||||
'X-CSRF-Token': document.querySelector("meta[name='csrf-token']")
|
||||
?.content,
|
||||
},
|
||||
body,
|
||||
credentials: 'same-origin',
|
||||
});
|
||||
|
||||
const outcome = await response.json();
|
||||
|
||||
this.displaySnackbar(outcome.message ?? outcome.error);
|
||||
} catch (err) {
|
||||
this.displaySnackbar(err.message);
|
||||
}
|
||||
}
|
||||
|
||||
// GENERAL FUNCTIONS END
|
||||
|
||||
// EMAIL AUTH FUNCTIONS START
|
||||
|
|
@ -158,7 +189,7 @@ export default class ConfigController extends Controller {
|
|||
|
||||
enableOrEditAuthProvider(event) {
|
||||
event.preventDefault();
|
||||
const {providerName} = event.target.dataset;
|
||||
const { providerName } = event.target.dataset;
|
||||
const enabledIndicator = document.getElementById(
|
||||
`${providerName}-enabled-indicator`,
|
||||
);
|
||||
|
|
@ -177,7 +208,7 @@ export default class ConfigController extends Controller {
|
|||
|
||||
disableAuthProvider(event) {
|
||||
event.preventDefault();
|
||||
const {providerName} = event.target.dataset;
|
||||
const { providerName } = event.target.dataset;
|
||||
const enabledIndicator = document.getElementById(
|
||||
`${providerName}-enabled-indicator`,
|
||||
);
|
||||
|
|
@ -200,8 +231,8 @@ export default class ConfigController extends Controller {
|
|||
|
||||
activateAuthProviderModal(event) {
|
||||
event.preventDefault();
|
||||
const {providerName} = event.target.dataset;
|
||||
const {providerOfficialName} = event.target.dataset;
|
||||
const { providerName } = event.target.dataset;
|
||||
const { providerOfficialName } = event.target.dataset;
|
||||
this.configModalAnchorTarget.innerHTML = adminModal({
|
||||
title: this.authProviderModalTitle(providerOfficialName),
|
||||
body: this.authProviderModalBody(providerOfficialName),
|
||||
|
|
@ -218,7 +249,7 @@ export default class ConfigController extends Controller {
|
|||
|
||||
disableAuthProviderFromModal(event) {
|
||||
event.preventDefault();
|
||||
const {providerName} = event.target.dataset;
|
||||
const { providerName } = event.target.dataset;
|
||||
const authEnableButton = document.getElementById(
|
||||
`${providerName}-auth-btn`,
|
||||
);
|
||||
|
|
@ -254,7 +285,7 @@ export default class ConfigController extends Controller {
|
|||
|
||||
hideAuthProviderSettings(event) {
|
||||
event.preventDefault();
|
||||
const {providerName} = event.target.dataset;
|
||||
const { providerName } = event.target.dataset;
|
||||
document
|
||||
.getElementById(`${providerName}-auth-settings`)
|
||||
.classList.add('hidden');
|
||||
|
|
@ -342,7 +373,7 @@ export default class ConfigController extends Controller {
|
|||
event.preventDefault();
|
||||
this.activateMissingKeysModal(this.enabledProvidersWithMissingKeys());
|
||||
} else {
|
||||
event.target.submit();
|
||||
this.updateConfigurationSettings(event);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,12 +0,0 @@
|
|||
<% if current_user.has_role?(:super_admin) %>
|
||||
<div class="crayons-notice p-4 mt-4">
|
||||
<div class="crayons-field">
|
||||
<%= label_tag :confirmation_update, "Confirmation update", class: "crayons-field__label" %>
|
||||
<p class="crayons-field__description">Type the sentence: <strong><%= @confirmation_text %></strong></p>
|
||||
<div class="flex">
|
||||
<%= text_field_tag :confirmation, nil, class: "crayons-textfield flex-1 mr-2", placeholder: "Confirmation text", autocomplete: "off", required: true, pattern: @confirmation_text %>
|
||||
<%= f.submit "Update Settings", class: "crayons-btn align-self-start" %>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<% end %>
|
||||
3
app/views/admin/settings/_update_setting_button.html.erb
Normal file
3
app/views/admin/settings/_update_setting_button.html.erb
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
<% if current_user.has_role?(:super_admin) %>
|
||||
<%= f.submit "Update Settings", class: "crayons-btn mt-4", data: { disable_with: false } %>
|
||||
<% end %>
|
||||
|
|
@ -1,4 +1,6 @@
|
|||
<%= form_for(Settings::General.new, url: admin_settings_general_settings_path) do |f| %>
|
||||
<%= form_for(Settings::General.new,
|
||||
url: admin_settings_general_settings_path,
|
||||
html: { data: { action: "submit->config#updateConfigurationSettings" } }) do |f| %>
|
||||
<div class="card mt-3">
|
||||
<%= render partial: "admin/shared/card_header",
|
||||
locals: {
|
||||
|
|
@ -25,8 +27,8 @@
|
|||
value: Settings::General.video_encoder_key,
|
||||
placeholder: Constants::Settings::General::DETAILS[:video_encoder_key][:placeholder] %>
|
||||
</div>
|
||||
<%= render "form_submission", f: f %>
|
||||
</fieldset>
|
||||
<%= render "update_setting_button", f: f %>
|
||||
</div>
|
||||
</div>
|
||||
<% end %>
|
||||
|
|
|
|||
|
|
@ -1,4 +1,6 @@
|
|||
<%= form_for(Settings::Authentication.new, url: admin_settings_authentications_path, html: { data: { action: "submit->config#configUpdatePrecheck", "config-target": "authSectionForm", testid: "authSectionForm" } }) do |f| %>
|
||||
<%= form_for(Settings::Authentication.new,
|
||||
url: admin_settings_authentications_path,
|
||||
html: { data: { action: "submit->config#configUpdatePrecheck", "config-target": "authSectionForm", testid: "authSectionForm" } }) do |f| %>
|
||||
<div class="card mt-3">
|
||||
<%= render partial: "admin/shared/card_header",
|
||||
locals: {
|
||||
|
|
@ -208,7 +210,7 @@
|
|||
Changing authentication keys will not take effect until this Forem instance is restarted.
|
||||
</div>
|
||||
|
||||
<%= render "form_submission", f: f %>
|
||||
<%= render "update_setting_button", f: f %>
|
||||
</div>
|
||||
</div>
|
||||
<% end %>
|
||||
|
|
|
|||
|
|
@ -1,4 +1,6 @@
|
|||
<%= form_for(Settings::Campaign.new, url: admin_settings_campaigns_path) do |f| %>
|
||||
<%= form_for(Settings::Campaign.new,
|
||||
url: admin_settings_campaigns_path,
|
||||
html: { data: { action: "submit->config#updateConfigurationSettings" } }) do |f| %>
|
||||
<div class="card mt-3">
|
||||
<%= render partial: "admin/shared/card_header",
|
||||
locals: {
|
||||
|
|
@ -81,9 +83,8 @@
|
|||
value: Settings::Campaign.articles_expiry_time,
|
||||
placeholder: Constants::Settings::Campaign::DETAILS[:articles_expiry_time][:placeholder] %>
|
||||
</div>
|
||||
|
||||
<%= render "form_submission", f: f %>
|
||||
</fieldset>
|
||||
<%= render "update_setting_button", f: f %>
|
||||
</div>
|
||||
</div>
|
||||
<% end %>
|
||||
|
|
|
|||
|
|
@ -1,4 +1,6 @@
|
|||
<%= form_for(Settings::Community.new, url: admin_settings_communities_path) do |f| %>
|
||||
<%= form_for(Settings::Community.new,
|
||||
url: admin_settings_communities_path,
|
||||
html: { data: { action: "submit->config#updateConfigurationSettings" } }) do |f| %>
|
||||
<div class="card mt-3">
|
||||
<%= render partial: "admin/shared/card_header",
|
||||
locals: {
|
||||
|
|
@ -71,8 +73,8 @@
|
|||
value: Settings::Community.staff_user_id,
|
||||
placeholder: Constants::Settings::Community::DETAILS[:staff_user_id][:placeholder] %>
|
||||
</div>
|
||||
<%= render "form_submission", f: f %>
|
||||
</fieldset>
|
||||
<%= render "update_setting_button", f: f %>
|
||||
</div>
|
||||
</div>
|
||||
<% end %>
|
||||
|
|
|
|||
|
|
@ -1,4 +1,6 @@
|
|||
<%= form_for(Settings::General.new, url: admin_settings_general_settings_path) do |f| %>
|
||||
<%= form_for(Settings::General.new,
|
||||
url: admin_settings_general_settings_path,
|
||||
html: { data: { action: "submit->config#updateConfigurationSettings" } }) do |f| %>
|
||||
<div class="card mt-3">
|
||||
<%= render partial: "admin/shared/card_header",
|
||||
locals: {
|
||||
|
|
@ -42,9 +44,8 @@
|
|||
value: Settings::General.credit_prices_in_cents[:xlarge] %>
|
||||
</div>
|
||||
<% end %>
|
||||
|
||||
<%= render "form_submission", f: f %>
|
||||
</fieldset>
|
||||
<%= render "update_setting_button", f: f %>
|
||||
</div>
|
||||
</div>
|
||||
<% end %>
|
||||
|
|
|
|||
|
|
@ -1,4 +1,9 @@
|
|||
<%= form_for(Settings::General.new, url: admin_settings_general_settings_path, html: { data: { testid: "emailDigestSectionForm" } }) do |f| %>
|
||||
<%= form_for(Settings::General.new,
|
||||
url: admin_settings_general_settings_path,
|
||||
html: { data: {
|
||||
action: "submit->config#updateConfigurationSettings",
|
||||
testid: "emailDigestSectionForm"
|
||||
} }) do |f| %>
|
||||
<div class="card mt-3">
|
||||
<%= render partial: "admin/shared/card_header",
|
||||
locals: {
|
||||
|
|
@ -17,9 +22,8 @@
|
|||
value: Settings::General.periodic_email_digest,
|
||||
placeholder: Constants::Settings::General::DETAILS[:periodic_email_digest][:placeholder] %>
|
||||
</div>
|
||||
|
||||
<%= render "form_submission", f: f %>
|
||||
</fieldset>
|
||||
<%= render "update_setting_button", f: f %>
|
||||
</div>
|
||||
</div>
|
||||
<% end %>
|
||||
|
|
|
|||
|
|
@ -1,4 +1,6 @@
|
|||
<%= form_for(Settings::General.new, url: admin_settings_general_settings_path) do |f| %>
|
||||
<%= form_for(Settings::General.new,
|
||||
url: admin_settings_general_settings_path,
|
||||
html: { data: { action: "submit->config#updateConfigurationSettings" } }) do |f| %>
|
||||
<div class="card mt-3">
|
||||
<%= render partial: "admin/shared/card_header",
|
||||
locals: {
|
||||
|
|
@ -16,9 +18,8 @@
|
|||
class: "crayons-textfield",
|
||||
value: Settings::General.ga_tracking_id %>
|
||||
</div>
|
||||
|
||||
<%= render "form_submission", f: f %>
|
||||
</fieldset>
|
||||
<%= render "update_setting_button", f: f %>
|
||||
</div>
|
||||
</div>
|
||||
<% end %>
|
||||
|
|
|
|||
|
|
@ -1,4 +1,6 @@
|
|||
<%= form_for(Settings::General.new, url: admin_settings_general_settings_path) do |f| %>
|
||||
<%= form_for(Settings::General.new,
|
||||
url: admin_settings_general_settings_path,
|
||||
html: { data: { action: "submit->config#updateConfigurationSettings" } }) do |f| %>
|
||||
<div class="card mt-3">
|
||||
<%= render partial: "admin/shared/card_header",
|
||||
locals: {
|
||||
|
|
@ -57,9 +59,8 @@
|
|||
</div>
|
||||
<% end %>
|
||||
</div>
|
||||
|
||||
<%= render "form_submission", f: f %>
|
||||
</fieldset>
|
||||
<%= render "update_setting_button", f: f %>
|
||||
</div>
|
||||
</div>
|
||||
<% end %>
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
<%= form_with(url: admin_settings_mandatory_settings_path, local: true, data: { testid: "getStartedSectionForm" }) do |f| %>
|
||||
<%= form_with(url: admin_settings_mandatory_settings_path, data: { action: "submit->config#updateConfigurationSettings", testid: "getStartedSectionForm" }) do |f| %>
|
||||
<fieldset class="grid gap-4">
|
||||
|
||||
<% Settings::Mandatory::MAPPINGS.each do |config_key, settings_model| %>
|
||||
|
|
@ -40,18 +40,6 @@
|
|||
</div>
|
||||
<% end %>
|
||||
<% end %>
|
||||
|
||||
<% if current_user.has_role?(:super_admin) %>
|
||||
<div class="crayons-notice p-4 mt-4">
|
||||
<div class="crayons-field">
|
||||
<%= label_tag :confirmation_update, "Confirmation update", class: "crayons-field__label" %>
|
||||
<p class="crayons-field__description">Type the sentence: <strong><%= @confirmation_text %></strong></p>
|
||||
<div class="flex">
|
||||
<%= text_field_tag :confirmation, nil, class: "crayons-textfield flex-1 mr-2", placeholder: "Confirmation text", autocomplete: "off", required: true, pattern: @confirmation_text %>
|
||||
<%= f.submit "Update Settings", class: "crayons-btn align-self-start" %>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<% end %>
|
||||
</fieldset>
|
||||
<%= render "update_setting_button", f: f %>
|
||||
<% end %>
|
||||
|
|
|
|||
|
|
@ -1,4 +1,9 @@
|
|||
<%= form_for(Settings::General.new, url: admin_settings_general_settings_path, html: { data: { testid: "mascotSectionForm" } }) do |f| %>
|
||||
<%= form_for(Settings::General.new,
|
||||
url: admin_settings_general_settings_path,
|
||||
html: { data: {
|
||||
action: "submit->config#updateConfigurationSettings",
|
||||
testid: "mascotSectionForm"
|
||||
} }) do |f| %>
|
||||
<div class="card mt-3">
|
||||
<%= render partial: "admin/shared/card_header",
|
||||
locals: {
|
||||
|
|
@ -32,8 +37,8 @@
|
|||
</div>
|
||||
|
||||
</div>
|
||||
<%= render "form_submission", f: f %>
|
||||
</fieldset>
|
||||
<%= render "update_setting_button", f: f %>
|
||||
</div>
|
||||
</div>
|
||||
<% end %>
|
||||
|
|
|
|||
|
|
@ -1,4 +1,6 @@
|
|||
<%= form_for(Settings::General.new, url: admin_settings_general_settings_path) do |f| %>
|
||||
<%= form_for(Settings::General.new,
|
||||
url: admin_settings_general_settings_path,
|
||||
html: { data: { action: "submit->config#updateConfigurationSettings" } }) do |f| %>
|
||||
<div class="card mt-3">
|
||||
<%= render partial: "admin/shared/card_header",
|
||||
locals: {
|
||||
|
|
@ -23,9 +25,8 @@
|
|||
</div>
|
||||
<% end %>
|
||||
<% end %>
|
||||
|
||||
<%= render "form_submission", f: f %>
|
||||
</fieldset>
|
||||
<%= render "update_setting_button", f: f %>
|
||||
</div>
|
||||
</div>
|
||||
<% end %>
|
||||
|
|
|
|||
|
|
@ -1,4 +1,6 @@
|
|||
<%= form_for(Settings::General.new, url: admin_settings_general_settings_path) do |f| %>
|
||||
<%= form_for(Settings::General.new,
|
||||
url: admin_settings_general_settings_path,
|
||||
html: { data: { action: "submit->config#updateConfigurationSettings" } }) do |f| %>
|
||||
<div class="card mt-3">
|
||||
<%= render partial: "admin/shared/card_header",
|
||||
locals: {
|
||||
|
|
@ -36,9 +38,8 @@
|
|||
value: Settings::General.payment_pointer,
|
||||
placeholder: Constants::Settings::General::DETAILS[:payment_pointer][:placeholder] %>
|
||||
</div>
|
||||
|
||||
<%= render "form_submission", f: f %>
|
||||
</fieldset>
|
||||
<%= render "update_setting_button", f: f %>
|
||||
</div>
|
||||
</div>
|
||||
<% end %>
|
||||
|
|
|
|||
|
|
@ -1,4 +1,6 @@
|
|||
<%= form_for(Settings::General.new, url: admin_settings_general_settings_path) do |f| %>
|
||||
<%= form_for(Settings::General.new,
|
||||
url: admin_settings_general_settings_path,
|
||||
html: { data: { action: "submit->config#updateConfigurationSettings" } }) do |f| %>
|
||||
<div class="card mt-3">
|
||||
<%= render partial: "admin/shared/card_header",
|
||||
locals: {
|
||||
|
|
@ -48,9 +50,8 @@
|
|||
class: "crayons-textfield",
|
||||
value: Settings::General.mailchimp_community_moderators_id %>
|
||||
</div>
|
||||
|
||||
<%= render "form_submission", f: f %>
|
||||
</fieldset>
|
||||
<%= render "update_setting_button", f: f %>
|
||||
</div>
|
||||
</div>
|
||||
<% end %>
|
||||
|
|
|
|||
|
|
@ -1,4 +1,6 @@
|
|||
<%= form_for(Settings::General.new, url: admin_settings_general_settings_path) do |f| %>
|
||||
<%= form_for(Settings::General.new,
|
||||
url: admin_settings_general_settings_path,
|
||||
html: { data: { action: "submit->config#updateConfigurationSettings" } }) do |f| %>
|
||||
<div class="card mt-3">
|
||||
<%= render partial: "admin/shared/card_header",
|
||||
locals: {
|
||||
|
|
@ -41,9 +43,8 @@
|
|||
</p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<%= render "form_submission", f: f %>
|
||||
</fieldset>
|
||||
<%= render "update_setting_button", f: f %>
|
||||
</div>
|
||||
</div>
|
||||
<% end %>
|
||||
|
|
|
|||
|
|
@ -1,4 +1,6 @@
|
|||
<%= form_for(Settings::RateLimit.new, url: admin_settings_rate_limits_path) do |f| %>
|
||||
<%= form_for(Settings::RateLimit.new,
|
||||
url: admin_settings_rate_limits_path,
|
||||
html: { data: { action: "submit->config#updateConfigurationSettings" } }) do |f| %>
|
||||
<div class="card mt-3">
|
||||
<%= render partial: "admin/shared/card_header",
|
||||
locals: {
|
||||
|
|
@ -40,13 +42,15 @@
|
|||
value: Settings::RateLimit.spam_trigger_terms.join(","),
|
||||
placeholder: Constants::Settings::RateLimit::DETAILS[:spam_trigger_terms][:placeholder] %>
|
||||
</div>
|
||||
<%= render "form_submission", f: f %>
|
||||
</fieldset>
|
||||
<%= render "update_setting_button", f: f %>
|
||||
</div>
|
||||
</div>
|
||||
<% end %>
|
||||
|
||||
<%= form_for(Settings::General.new, url: admin_settings_general_settings_path) do |f| %>
|
||||
<%= form_for(Settings::General.new,
|
||||
url: admin_settings_general_settings_path,
|
||||
html: { data: { action: "submit->config#updateConfigurationSettings" } }) do |f| %>
|
||||
<div class="card mt-3">
|
||||
<%= render partial: "admin/shared/card_header",
|
||||
locals: {
|
||||
|
|
@ -79,9 +83,8 @@
|
|||
</div>
|
||||
<% end %>
|
||||
<% end %>
|
||||
|
||||
<%= render "form_submission", f: f %>
|
||||
</fieldset>
|
||||
<%= render "update_setting_button", f: f %>
|
||||
</div>
|
||||
</div>
|
||||
<% end %>
|
||||
|
|
|
|||
|
|
@ -1,4 +1,6 @@
|
|||
<%= form_for(Settings::SMTP.new, url: admin_settings_smtp_settings_path) do |f| %>
|
||||
<%= form_for(Settings::SMTP.new,
|
||||
url: admin_settings_smtp_settings_path,
|
||||
html: { data: { action: "submit->config#updateConfigurationSettings" } }) do |f| %>
|
||||
<div class="card mt-3">
|
||||
<%= render partial: "admin/shared/card_header",
|
||||
locals: { header: "SMTP Settings", state: "collapse", target: "smtpSettingsBodyContainer", expanded: false } %>
|
||||
|
|
@ -15,8 +17,8 @@
|
|||
|
||||
</div>
|
||||
<% end %>
|
||||
<%= render "form_submission", f: f %>
|
||||
</fieldset>
|
||||
<%= render "update_setting_button", f: f %>
|
||||
</div>
|
||||
</div>
|
||||
<% end %>
|
||||
|
|
|
|||
|
|
@ -1,4 +1,6 @@
|
|||
<%= form_for(Settings::General.new, url: admin_settings_general_settings_path) do |f| %>
|
||||
<%= form_for(Settings::General.new,
|
||||
url: admin_settings_general_settings_path,
|
||||
html: { data: { action: "submit->config#updateConfigurationSettings" } }) do |f| %>
|
||||
<div class="card mt-3">
|
||||
<%= render partial: "admin/shared/card_header",
|
||||
locals: {
|
||||
|
|
@ -17,9 +19,8 @@
|
|||
value: Settings::General.sponsor_headline,
|
||||
placeholder: Constants::Settings::General::DETAILS[:sponsor_headline][:placeholder] %>
|
||||
</div>
|
||||
|
||||
<%= render "form_submission", f: f %>
|
||||
</fieldset>
|
||||
<%= render "update_setting_button", f: f %>
|
||||
</div>
|
||||
</div>
|
||||
<% end %>
|
||||
|
|
|
|||
|
|
@ -1,4 +1,6 @@
|
|||
<%= form_for(Settings::General.new, url: admin_settings_general_settings_path) do |f| %>
|
||||
<%= form_for(Settings::General.new,
|
||||
url: admin_settings_general_settings_path,
|
||||
html: { data: { action: "submit->config#updateConfigurationSettings" } }) do |f| %>
|
||||
<div class="card mt-3">
|
||||
<%= render partial: "admin/shared/card_header",
|
||||
locals: {
|
||||
|
|
@ -18,9 +20,8 @@
|
|||
placeholder: Constants::Settings::General::DETAILS[:sidebar_tags][:placeholder],
|
||||
pattern: "[a-z0-9,]+" %>
|
||||
</div>
|
||||
|
||||
<%= render "form_submission", f: f %>
|
||||
</fieldset>
|
||||
<%= render "update_setting_button", f: f %>
|
||||
</div>
|
||||
</div>
|
||||
<% end %>
|
||||
|
|
|
|||
|
|
@ -1,4 +1,6 @@
|
|||
<%= form_for(Settings::UserExperience.new, url: admin_settings_user_experiences_path) do |f| %>
|
||||
<%= form_for(Settings::UserExperience.new,
|
||||
url: admin_settings_user_experiences_path,
|
||||
html: { data: { action: "submit->config#updateConfigurationSettings" } }) do |f| %>
|
||||
<div class=" card mt-3">
|
||||
<%= render partial: "admin/shared/card_header",
|
||||
locals: {
|
||||
|
|
@ -70,9 +72,8 @@
|
|||
</p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<%= render "form_submission", f: f %>
|
||||
</fieldset>
|
||||
<%= render "update_setting_button", f: f %>
|
||||
</div>
|
||||
</div>
|
||||
<% end %>
|
||||
|
|
|
|||
|
|
@ -31,22 +31,22 @@ describe('Authentication Section', () => {
|
|||
.should('not.be.checked')
|
||||
.check();
|
||||
|
||||
cy.get('@authSectionForm')
|
||||
.findByPlaceholderText('Confirmation text')
|
||||
.type(
|
||||
`My username is @${username} and this action is 100% safe and appropriate.`,
|
||||
);
|
||||
cy.get('@authSectionForm')
|
||||
.findByRole('button', { name: 'Update Settings' })
|
||||
.click();
|
||||
|
||||
cy.findByTestId('snackbar').within(() => {
|
||||
cy.findByRole('alert').should(
|
||||
'have.text',
|
||||
'Successfully updated settings.',
|
||||
);
|
||||
});
|
||||
|
||||
cy.url().should('contains', '/admin/customization/config');
|
||||
|
||||
// Page reloaded so need to get a new reference to the form.
|
||||
cy.findByTestId('authSectionForm').as('authSectionForm');
|
||||
|
||||
cy.findByText('Successfully updated settings.').should('be.visible');
|
||||
|
||||
cy.get('@authSectionForm')
|
||||
.findByRole('heading', { name: 'Authentication' })
|
||||
.click();
|
||||
|
|
@ -81,13 +81,7 @@ describe('Authentication Section', () => {
|
|||
|
||||
cy.get('@authSectionForm').findByText('Authentication').click();
|
||||
cy.get('#facebook-auth-btn').click();
|
||||
cy.get('@user').then(({ username }) => {
|
||||
cy.get('@authSectionForm')
|
||||
.findByPlaceholderText('Confirmation text')
|
||||
.type(
|
||||
`My username is @${username} and this action is 100% safe and appropriate.`,
|
||||
);
|
||||
});
|
||||
|
||||
cy.get('@authSectionForm').findByText('Update Settings').click();
|
||||
|
||||
cy.get('.crayons-modal__box__body > ul > li')
|
||||
|
|
@ -107,13 +101,7 @@ describe('Authentication Section', () => {
|
|||
cy.get('#facebook-auth-btn').click();
|
||||
cy.get('#settings_authentication_facebook_key').type('randomkey');
|
||||
cy.get('#settings_authentication_facebook_secret').type('randomsecret');
|
||||
cy.get('@user').then(({ username }) => {
|
||||
cy.get('@authSectionForm')
|
||||
.findByPlaceholderText('Confirmation text')
|
||||
.type(
|
||||
`My username is @${username} and this action is 100% safe and appropriate.`,
|
||||
);
|
||||
});
|
||||
|
||||
cy.get('@authSectionForm').findByText('Update Settings').click();
|
||||
|
||||
cy.url().should('contains', '/admin/customization/config');
|
||||
|
|
@ -127,5 +115,28 @@ describe('Authentication Section', () => {
|
|||
cy.findByLabelText('Facebook enabled').should('be.visible');
|
||||
});
|
||||
});
|
||||
|
||||
it('generates error message when update fails', () => {
|
||||
cy.intercept('POST', 'admin/settings/authentications', {
|
||||
error: 'some error msg',
|
||||
});
|
||||
cy.get('@user').then(() => {
|
||||
cy.visit('/admin/customization/config');
|
||||
cy.findByTestId('authSectionForm').as('authSectionForm');
|
||||
|
||||
cy.get('@authSectionForm').findByText('Authentication').click();
|
||||
cy.get('#facebook-auth-btn').click();
|
||||
cy.get('#settings_authentication_facebook_key').type('randomkey');
|
||||
cy.get('#settings_authentication_facebook_secret').type('randomsecret');
|
||||
|
||||
cy.get('@authSectionForm').findByText('Update Settings').click();
|
||||
|
||||
cy.url().should('contains', '/admin/customization/config');
|
||||
|
||||
cy.findByTestId('snackbar').within(() => {
|
||||
cy.findByRole('alert').should('have.text', 'some error msg');
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
|
|||
|
|
@ -10,7 +10,7 @@ describe('Campaign Section', () => {
|
|||
|
||||
describe('sidebar image setting', () => {
|
||||
it('rejects an invalid image URL', () => {
|
||||
cy.get('@user').then(({ username }) => {
|
||||
cy.get('@user').then(() => {
|
||||
cy.visit('/admin/customization/config');
|
||||
cy.get('#new_settings_campaign').as('campaignSectionForm');
|
||||
|
||||
|
|
@ -19,24 +19,21 @@ describe('Campaign Section', () => {
|
|||
.findByPlaceholderText('Used at the top of the campaign sidebar')
|
||||
.type('example.com/image.png');
|
||||
|
||||
cy.get('@campaignSectionForm')
|
||||
.findByPlaceholderText('Confirmation text')
|
||||
.type(
|
||||
`My username is @${username} and this action is 100% safe and appropriate.`,
|
||||
);
|
||||
|
||||
cy.get('@campaignSectionForm').findByText('Update Settings').click();
|
||||
|
||||
cy.url().should('contains', '/admin/customization/config');
|
||||
|
||||
cy.findByText(
|
||||
'😭 Validation failed: Sidebar image is not a valid URL',
|
||||
).should('be.visible');
|
||||
cy.findByTestId('snackbar').within(() => {
|
||||
cy.findByRole('alert').should(
|
||||
'have.text',
|
||||
'Validation failed: Sidebar image is not a valid URL',
|
||||
);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
it('accepts a valid image URL', () => {
|
||||
cy.get('@user').then(({ username }) => {
|
||||
cy.get('@user').then(() => {
|
||||
cy.visit('/admin/customization/config');
|
||||
cy.get('#new_settings_campaign').as('campaignSectionForm');
|
||||
|
||||
|
|
@ -45,17 +42,16 @@ describe('Campaign Section', () => {
|
|||
.findByPlaceholderText('Used at the top of the campaign sidebar')
|
||||
.type('https://example.com/image.png');
|
||||
|
||||
cy.get('@campaignSectionForm')
|
||||
.findByPlaceholderText('Confirmation text')
|
||||
.type(
|
||||
`My username is @${username} and this action is 100% safe and appropriate.`,
|
||||
);
|
||||
|
||||
cy.get('@campaignSectionForm').findByText('Update Settings').click();
|
||||
|
||||
cy.url().should('contains', '/admin/customization/config');
|
||||
|
||||
cy.findByText('Successfully updated settings.').should('be.visible');
|
||||
cy.findByTestId('snackbar').within(() => {
|
||||
cy.findByRole('alert').should(
|
||||
'have.text',
|
||||
'Successfully updated settings.',
|
||||
);
|
||||
});
|
||||
|
||||
// Page reloaded so need to get a new reference to the form.
|
||||
cy.get('#new_settings_campaign').as('campaignSectionForm');
|
||||
|
|
|
|||
|
|
@ -10,7 +10,7 @@ describe('Community Content Section', () => {
|
|||
|
||||
describe('community emoji setting', () => {
|
||||
it('rejects invalid input (no emoji)', () => {
|
||||
cy.get('@user').then(({ username }) => {
|
||||
cy.get('@user').then(() => {
|
||||
cy.visit('/admin/customization/config');
|
||||
cy.get('#new_settings_community').as('communitySectionForm');
|
||||
|
||||
|
|
@ -20,24 +20,21 @@ describe('Community Content Section', () => {
|
|||
.clear()
|
||||
.type('X');
|
||||
|
||||
cy.get('@communitySectionForm')
|
||||
.findByPlaceholderText('Confirmation text')
|
||||
.type(
|
||||
`My username is @${username} and this action is 100% safe and appropriate.`,
|
||||
);
|
||||
|
||||
cy.get('@communitySectionForm').findByText('Update Settings').click();
|
||||
|
||||
cy.url().should('contains', '/admin/customization/config');
|
||||
cy.findByTestId('snackbar').within(() => {
|
||||
cy.findByRole('alert').should(
|
||||
'have.text',
|
||||
'Validation failed: Community emoji contains non-emoji characters or invalid emoji',
|
||||
);
|
||||
});
|
||||
|
||||
cy.findByText(
|
||||
'😭 Validation failed: Community emoji contains non-emoji characters or invalid emoji',
|
||||
).should('be.visible');
|
||||
cy.url().should('contains', '/admin/customization/config');
|
||||
});
|
||||
});
|
||||
|
||||
it('accepts a valid emoji', () => {
|
||||
cy.get('@user').then(({ username }) => {
|
||||
cy.get('@user').then(() => {
|
||||
cy.visit('/admin/customization/config');
|
||||
cy.get('#new_settings_community').as('communitySectionForm');
|
||||
|
||||
|
|
@ -47,17 +44,16 @@ describe('Community Content Section', () => {
|
|||
.clear()
|
||||
.type('🌱');
|
||||
|
||||
cy.get('@communitySectionForm')
|
||||
.findByPlaceholderText('Confirmation text')
|
||||
.type(
|
||||
`My username is @${username} and this action is 100% safe and appropriate.`,
|
||||
);
|
||||
|
||||
cy.get('@communitySectionForm').findByText('Update Settings').click();
|
||||
|
||||
cy.url().should('contains', '/admin/customization/config');
|
||||
|
||||
cy.findByText('Successfully updated settings.').should('be.visible');
|
||||
cy.findByTestId('snackbar').within(() => {
|
||||
cy.findByRole('alert').should(
|
||||
'have.text',
|
||||
'Successfully updated settings.',
|
||||
);
|
||||
});
|
||||
|
||||
// Page reloaded so need to get a new reference to the form.
|
||||
cy.get('#new_settings_community').as('communitySectionForm');
|
||||
|
|
|
|||
|
|
@ -10,7 +10,7 @@ describe('Email digest frequency Section', () => {
|
|||
|
||||
describe('email digest frequency settings', () => {
|
||||
it('can change the frequency', () => {
|
||||
cy.get('@user').then(({ username }) => {
|
||||
cy.get('@user').then(() => {
|
||||
cy.visit('/admin/customization/config');
|
||||
cy.findByTestId('emailDigestSectionForm').as('emailDigestSectionForm');
|
||||
|
||||
|
|
@ -23,12 +23,6 @@ describe('Email digest frequency Section', () => {
|
|||
.clear()
|
||||
.type('42');
|
||||
|
||||
cy.get('@emailDigestSectionForm')
|
||||
.findByPlaceholderText('Confirmation text')
|
||||
.type(
|
||||
`My username is @${username} and this action is 100% safe and appropriate.`,
|
||||
);
|
||||
|
||||
cy.get('@emailDigestSectionForm').findByText('Update Settings').click();
|
||||
|
||||
cy.url().should('contains', '/admin/customization/config');
|
||||
|
|
|
|||
|
|
@ -10,7 +10,7 @@ describe('Get Started Section', () => {
|
|||
|
||||
describe('Community name setting', () => {
|
||||
it('updates the community name', () => {
|
||||
cy.get('@user').then(({ username }) => {
|
||||
cy.get('@user').then(() => {
|
||||
cy.visit('/admin/customization/config');
|
||||
|
||||
cy.findByTestId('getStartedSectionForm').as('getStartedSectionForm');
|
||||
|
|
@ -20,17 +20,16 @@ describe('Get Started Section', () => {
|
|||
.clear()
|
||||
.type('Awesome community');
|
||||
|
||||
cy.get('@getStartedSectionForm')
|
||||
.findByPlaceholderText('Confirmation text')
|
||||
.type(
|
||||
`My username is @${username} and this action is 100% safe and appropriate.`,
|
||||
);
|
||||
|
||||
cy.get('@getStartedSectionForm').findByText('Update Settings').click();
|
||||
|
||||
cy.url().should('contains', '/admin/customization/config');
|
||||
|
||||
cy.findByText('Successfully updated settings.').should('be.visible');
|
||||
cy.findByTestId('snackbar').within(() => {
|
||||
cy.findByRole('alert').should(
|
||||
'have.text',
|
||||
'Successfully updated settings.',
|
||||
);
|
||||
});
|
||||
|
||||
// Page reloaded so need to get a new reference to the form.
|
||||
cy.findByTestId('getStartedSectionForm').as('getStartedSectionForm');
|
||||
|
|
@ -39,7 +38,7 @@ describe('Get Started Section', () => {
|
|||
});
|
||||
|
||||
it('updates the suggested tags', () => {
|
||||
cy.get('@user').then(({ username }) => {
|
||||
cy.get('@user').then(() => {
|
||||
cy.visit('/admin/customization/config');
|
||||
|
||||
cy.findByTestId('getStartedSectionForm').as('getStartedSectionForm');
|
||||
|
|
@ -49,21 +48,44 @@ describe('Get Started Section', () => {
|
|||
.clear()
|
||||
.type('much tag, so wow');
|
||||
|
||||
cy.get('@getStartedSectionForm')
|
||||
.findByPlaceholderText('Confirmation text')
|
||||
.type(
|
||||
`My username is @${username} and this action is 100% safe and appropriate.`,
|
||||
cy.get('@getStartedSectionForm').findByText('Update Settings').click();
|
||||
|
||||
cy.url().should('contains', '/admin/customization/config');
|
||||
|
||||
cy.findByTestId('snackbar').within(() => {
|
||||
cy.findByRole('alert').should(
|
||||
'have.text',
|
||||
'Successfully updated settings.',
|
||||
);
|
||||
});
|
||||
|
||||
// Page reloaded so need to get a new reference to the form.
|
||||
cy.findByTestId('getStartedSectionForm').as('getStartedSectionForm');
|
||||
cy.get('#suggested_tags').should('have.value', 'much tag, so wow');
|
||||
});
|
||||
});
|
||||
|
||||
it('generates error message when update fails', () => {
|
||||
cy.intercept('POST', '/admin/settings/mandatory_settings', {
|
||||
error: 'some error msg',
|
||||
});
|
||||
cy.get('@user').then(() => {
|
||||
cy.visit('/admin/customization/config');
|
||||
|
||||
cy.findByTestId('getStartedSectionForm').as('getStartedSectionForm');
|
||||
|
||||
cy.get('@getStartedSectionForm')
|
||||
.get('#suggested_tags')
|
||||
.clear()
|
||||
.type('much tag, so wow');
|
||||
|
||||
cy.get('@getStartedSectionForm').findByText('Update Settings').click();
|
||||
|
||||
cy.url().should('contains', '/admin/customization/config');
|
||||
|
||||
cy.findByText('Successfully updated settings.').should('be.visible');
|
||||
|
||||
// Page reloaded so need to get a new reference to the form.
|
||||
cy.findByTestId('getStartedSectionForm').as('getStartedSectionForm');
|
||||
cy.get('#suggested_tags').should('have.value', 'much tag,so wow');
|
||||
cy.findByTestId('snackbar').within(() => {
|
||||
cy.findByRole('alert').should('have.text', 'some error msg');
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
|
|||
|
|
@ -10,7 +10,7 @@ describe('Mascot Section', () => {
|
|||
|
||||
describe('mascot image setting', () => {
|
||||
it('rejects an invalid image URL', () => {
|
||||
cy.get('@user').then(({ username }) => {
|
||||
cy.get('@user').then(() => {
|
||||
cy.visit('/admin/customization/config');
|
||||
cy.findByTestId('mascotSectionForm').as('mascotSectionForm');
|
||||
|
||||
|
|
@ -20,24 +20,21 @@ describe('Mascot Section', () => {
|
|||
.clear()
|
||||
.type('notanimage');
|
||||
|
||||
cy.get('@mascotSectionForm')
|
||||
.findByPlaceholderText('Confirmation text')
|
||||
.type(
|
||||
`My username is @${username} and this action is 100% safe and appropriate.`,
|
||||
);
|
||||
|
||||
cy.get('@mascotSectionForm').findByText('Update Settings').click();
|
||||
|
||||
cy.url().should('contains', '/admin/customization/config');
|
||||
|
||||
cy.findByText(
|
||||
'😭 Validation failed: Mascot image url is not a valid URL',
|
||||
).should('be.visible');
|
||||
cy.findByTestId('snackbar').within(() => {
|
||||
cy.findByRole('alert').should(
|
||||
'have.text',
|
||||
'Validation failed: Mascot image url is not a valid URL',
|
||||
);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
it('accepts a valid image URL', () => {
|
||||
cy.get('@user').then(({ username }) => {
|
||||
cy.get('@user').then(() => {
|
||||
cy.visit('/admin/customization/config');
|
||||
cy.findByTestId('mascotSectionForm').as('mascotSectionForm');
|
||||
|
||||
|
|
@ -47,17 +44,16 @@ describe('Mascot Section', () => {
|
|||
.clear()
|
||||
.type('https://example.com/image.png');
|
||||
|
||||
cy.get('@mascotSectionForm')
|
||||
.findByPlaceholderText('Confirmation text')
|
||||
.type(
|
||||
`My username is @${username} and this action is 100% safe and appropriate.`,
|
||||
);
|
||||
|
||||
cy.get('@mascotSectionForm').findByText('Update Settings').click();
|
||||
|
||||
cy.url().should('contains', '/admin/customization/config');
|
||||
|
||||
cy.findByText('Successfully updated settings.').should('be.visible');
|
||||
cy.findByTestId('snackbar').within(() => {
|
||||
cy.findByRole('alert').should(
|
||||
'have.text',
|
||||
'Successfully updated settings.',
|
||||
);
|
||||
});
|
||||
|
||||
// Page reloaded so need to get a new reference to the form.
|
||||
cy.findByTestId('mascotSectionForm').as('mascotSectionForm');
|
||||
|
|
|
|||
|
|
@ -10,7 +10,7 @@ describe('Campaign Section', () => {
|
|||
|
||||
describe('rate limit settings', () => {
|
||||
it('can change for how many days a user is considered new', () => {
|
||||
cy.get('@user').then(({ username }) => {
|
||||
cy.get('@user').then(() => {
|
||||
cy.visit('/admin/customization/config');
|
||||
cy.get('#new_settings_rate_limit').as('rateLimitSectionForm');
|
||||
|
||||
|
|
@ -23,17 +23,16 @@ describe('Campaign Section', () => {
|
|||
.clear()
|
||||
.type('42');
|
||||
|
||||
cy.get('@rateLimitSectionForm')
|
||||
.findByPlaceholderText('Confirmation text')
|
||||
.type(
|
||||
`My username is @${username} and this action is 100% safe and appropriate.`,
|
||||
);
|
||||
|
||||
cy.get('@rateLimitSectionForm').findByText('Update Settings').click();
|
||||
|
||||
cy.url().should('contains', '/admin/customization/config');
|
||||
|
||||
cy.findByText('Successfully updated settings.').should('be.visible');
|
||||
cy.findByTestId('snackbar').within(() => {
|
||||
cy.findByRole('alert').should(
|
||||
'have.text',
|
||||
'Successfully updated settings.',
|
||||
);
|
||||
});
|
||||
|
||||
cy.get('#settings_rate_limit_user_considered_new_days').should(
|
||||
'have.value',
|
||||
|
|
@ -41,5 +40,32 @@ describe('Campaign Section', () => {
|
|||
);
|
||||
});
|
||||
});
|
||||
|
||||
it('generates error message when update fails', () => {
|
||||
cy.intercept('POST', '/admin/settings/rate_limits', {
|
||||
error: 'some error msg',
|
||||
});
|
||||
cy.get('@user').then(() => {
|
||||
cy.visit('/admin/customization/config');
|
||||
cy.get('#new_settings_rate_limit').as('rateLimitSectionForm');
|
||||
|
||||
cy.get('@rateLimitSectionForm')
|
||||
.findByText('Rate limits and anti-spam')
|
||||
.click();
|
||||
|
||||
cy.get('@rateLimitSectionForm')
|
||||
.get('#settings_rate_limit_user_considered_new_days')
|
||||
.clear()
|
||||
.type('42');
|
||||
|
||||
cy.get('@rateLimitSectionForm').findByText('Update Settings').click();
|
||||
|
||||
cy.url().should('contains', '/admin/customization/config');
|
||||
|
||||
cy.findByTestId('snackbar').within(() => {
|
||||
cy.findByRole('alert').should('have.text', 'some error msg');
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
|
|||
|
|
@ -10,7 +10,7 @@ describe('User experience Section', () => {
|
|||
|
||||
describe('default font', () => {
|
||||
it('can change the default font', () => {
|
||||
cy.get('@user').then(({ username }) => {
|
||||
cy.get('@user').then(() => {
|
||||
cy.visit('/admin/customization/config');
|
||||
cy.get('#new_settings_user_experience').as('userExperienceSectionForm');
|
||||
|
||||
|
|
@ -22,19 +22,18 @@ describe('User experience Section', () => {
|
|||
// We need to use force here because the select is covered by another element.
|
||||
.select('open-dyslexic', { force: true });
|
||||
|
||||
cy.get('@userExperienceSectionForm')
|
||||
.findByPlaceholderText('Confirmation text')
|
||||
.type(
|
||||
`My username is @${username} and this action is 100% safe and appropriate.`,
|
||||
);
|
||||
|
||||
cy.get('@userExperienceSectionForm')
|
||||
.findByText('Update Settings')
|
||||
.click();
|
||||
|
||||
cy.url().should('contains', '/admin/customization/config');
|
||||
|
||||
cy.findByText('Successfully updated settings.').should('be.visible');
|
||||
cy.findByTestId('snackbar').within(() => {
|
||||
cy.findByRole('alert').should(
|
||||
'have.text',
|
||||
'Successfully updated settings.',
|
||||
);
|
||||
});
|
||||
|
||||
// Page reloaded so need to get a new reference to the form.
|
||||
cy.get('#new_settings_user_experience').as('userExperienceSectionForm');
|
||||
|
|
|
|||
|
|
@ -17,11 +17,6 @@ describe('Set a landing page from the admin portal', () => {
|
|||
.should('be.checked')
|
||||
.uncheck();
|
||||
|
||||
cy.get('@userExperienceSectionForm')
|
||||
.findByPlaceholderText('Confirmation text')
|
||||
.type(
|
||||
`My username is @${user.username} and this action is 100% safe and appropriate.`,
|
||||
);
|
||||
cy.get('@userExperienceSectionForm')
|
||||
.findByRole('button', { name: 'Update Settings' })
|
||||
.click();
|
||||
|
|
|
|||
|
|
@ -178,25 +178,22 @@ const DEFAULT_AUTH_CONFIG = {
|
|||
*/
|
||||
Cypress.Commands.add(
|
||||
'updateAdminAuthConfig',
|
||||
(
|
||||
username = 'admin_mcadmin',
|
||||
{
|
||||
inviteOnlyMode = false,
|
||||
emailRegistration = true,
|
||||
allowedEmailDomains,
|
||||
publicEmailDomainList = false,
|
||||
requireRecaptcha = false,
|
||||
recaptchaSiteKey,
|
||||
recaptchaSecretKey,
|
||||
authProvidersToEnable,
|
||||
facebookKey,
|
||||
facebookSecret,
|
||||
githubKey,
|
||||
githubSecret,
|
||||
twitterKey,
|
||||
twitterSecret,
|
||||
} = DEFAULT_AUTH_CONFIG,
|
||||
) => {
|
||||
({
|
||||
inviteOnlyMode = false,
|
||||
emailRegistration = true,
|
||||
allowedEmailDomains = '',
|
||||
publicEmailDomainList = false,
|
||||
requireRecaptcha = false,
|
||||
recaptchaSiteKey = '',
|
||||
recaptchaSecretKey = '',
|
||||
authProvidersToEnable,
|
||||
facebookKey = '',
|
||||
facebookSecret = '',
|
||||
githubKey = '',
|
||||
githubSecret = '',
|
||||
twitterKey = '',
|
||||
twitterSecret = '',
|
||||
} = DEFAULT_AUTH_CONFIG) => {
|
||||
return cy.request(
|
||||
'POST',
|
||||
'/admin/settings/authentications',
|
||||
|
|
@ -208,7 +205,7 @@ Cypress.Commands.add(
|
|||
publicEmailDomainList,
|
||||
)}&settings_authentication%5Brequire_captcha_for_email_password_registration%5D=${toPayload(
|
||||
requireRecaptcha,
|
||||
)}&settings_authentication%5Brecaptcha_site_key%5D=${recaptchaSiteKey}&settings_authentication%5Brecaptcha_secret_key%5D=${recaptchaSecretKey}&settings_authentication%5Bauth_providers_to_enable%5D=${authProvidersToEnable}&settings_authentication%5Bfacebook_key%5D=${facebookKey}&settings_authentication%5Bfacebook_secret%5D=${facebookSecret}&settings_authentication%5Bgithub_key%5D=${githubKey}&settings_authentication%5Bgithub_secret%5D=${githubSecret}&settings_authentication%5Btwitter_key%5D=${twitterKey}&settings_authentication%5Btwitter_secret%5D=${twitterSecret}&confirmation=My+username+is+%40${username}+and+this+action+is+100%25+safe+and+appropriate.&commit=Update+Settings`,
|
||||
)}&settings_authentication%5Brecaptcha_site_key%5D=${recaptchaSiteKey}&settings_authentication%5Brecaptcha_secret_key%5D=${recaptchaSecretKey}&settings_authentication%5Bauth_providers_to_enable%5D=${authProvidersToEnable}&settings_authentication%5Bfacebook_key%5D=${facebookKey}&settings_authentication%5Bfacebook_secret%5D=${facebookSecret}&settings_authentication%5Bgithub_key%5D=${githubKey}&settings_authentication%5Bgithub_secret%5D=${githubSecret}&settings_authentication%5Btwitter_key%5D=${twitterKey}&settings_authentication%5Btwitter_secret%5D=${twitterSecret}&commit=Update+Settings`,
|
||||
);
|
||||
},
|
||||
);
|
||||
|
|
|
|||
|
|
@ -4,9 +4,6 @@ RSpec.describe "/admin/customization/config", type: :request do
|
|||
let(:user) { create(:user) }
|
||||
let(:admin) { create(:user, :admin) }
|
||||
let(:super_admin) { create(:user, :super_admin) }
|
||||
let(:confirmation_message) do
|
||||
"My username is @#{super_admin.username} and this action is 100% safe and appropriate."
|
||||
end
|
||||
|
||||
describe "POST /admin/customization/config as a user" do
|
||||
before do
|
||||
|
|
@ -25,22 +22,11 @@ RSpec.describe "/admin/customization/config", type: :request do
|
|||
sign_in(admin)
|
||||
end
|
||||
|
||||
it "does not allow user to update config if they have proper confirmation" do
|
||||
it "does not allow user to update config" do
|
||||
expected_image_url = "https://dummyimage.com/300x300.png"
|
||||
expect do
|
||||
post admin_settings_general_settings_path, params: {
|
||||
settings_general: { favicon_url: expected_image_url },
|
||||
confirmation: confirmation_message
|
||||
}
|
||||
end.to raise_error Pundit::NotAuthorizedError
|
||||
end
|
||||
|
||||
it "does not allow user to update config if they do not have proper confirmation" do
|
||||
expected_image_url = "https://dummyimage.com/300x300.png"
|
||||
expect do
|
||||
post admin_settings_general_settings_path, params: {
|
||||
settings_general: { favicon_url: expected_image_url },
|
||||
confirmation: "Not proper"
|
||||
settings_general: { favicon_url: expected_image_url }
|
||||
}
|
||||
end.to raise_error Pundit::NotAuthorizedError
|
||||
end
|
||||
|
|
@ -54,8 +40,7 @@ RSpec.describe "/admin/customization/config", type: :request do
|
|||
it "updates settings admin action taken" do
|
||||
expect do
|
||||
post admin_settings_general_settings_path, params: {
|
||||
settings_general: { health_check_token: "token" },
|
||||
confirmation: confirmation_message
|
||||
settings_general: { health_check_token: "token" }
|
||||
}
|
||||
end.to change(Settings::General, :admin_action_taken_at)
|
||||
end
|
||||
|
|
@ -64,16 +49,14 @@ RSpec.describe "/admin/customization/config", type: :request do
|
|||
it "updates the health_check_token" do
|
||||
token = rand(20).to_s
|
||||
post admin_settings_general_settings_path, params: {
|
||||
settings_general: { health_check_token: token },
|
||||
confirmation: confirmation_message
|
||||
settings_general: { health_check_token: token }
|
||||
}
|
||||
expect(Settings::General.health_check_token).to eq token
|
||||
end
|
||||
|
||||
it "sets video_encoder_key" do
|
||||
post admin_settings_general_settings_path, params: {
|
||||
settings_general: { video_encoder_key: "123abc" },
|
||||
confirmation: confirmation_message
|
||||
settings_general: { video_encoder_key: "123abc" }
|
||||
}
|
||||
expect(Settings::General.video_encoder_key).to eq("123abc")
|
||||
end
|
||||
|
|
@ -92,8 +75,7 @@ RSpec.describe "/admin/customization/config", type: :request do
|
|||
"#{provider}_key": "someKey",
|
||||
"#{provider}_secret": "someSecret",
|
||||
auth_providers_to_enable: provider
|
||||
},
|
||||
confirmation: confirmation_message
|
||||
}
|
||||
}
|
||||
expect(Settings::Authentication.providers).to eq([provider])
|
||||
end
|
||||
|
|
@ -105,8 +87,7 @@ RSpec.describe "/admin/customization/config", type: :request do
|
|||
"#{provider}_key": "someKey",
|
||||
"#{provider}_secret": "someSecret",
|
||||
auth_providers_to_enable: enabled
|
||||
},
|
||||
confirmation: confirmation_message
|
||||
}
|
||||
}
|
||||
expect(Settings::Authentication.providers).to eq([provider])
|
||||
end
|
||||
|
|
@ -119,8 +100,7 @@ RSpec.describe "/admin/customization/config", type: :request do
|
|||
"#{provider}_key": "someKey",
|
||||
"#{provider}_secret": "",
|
||||
auth_providers_to_enable: provider
|
||||
},
|
||||
confirmation: confirmation_message
|
||||
}
|
||||
}
|
||||
expect(Settings::Authentication.providers).to eq([])
|
||||
end
|
||||
|
|
@ -128,8 +108,7 @@ RSpec.describe "/admin/customization/config", type: :request do
|
|||
it "enables proper domains to allow list" do
|
||||
proper_list = "dev.to, forem.com, forem.dev"
|
||||
post admin_settings_authentications_path, params: {
|
||||
settings_authentication: { allowed_registration_email_domains: proper_list },
|
||||
confirmation: confirmation_message
|
||||
settings_authentication: { allowed_registration_email_domains: proper_list }
|
||||
}
|
||||
expect(Settings::Authentication.allowed_registration_email_domains).to eq(%w[dev.to forem.com forem.dev])
|
||||
end
|
||||
|
|
@ -137,8 +116,7 @@ RSpec.describe "/admin/customization/config", type: :request do
|
|||
it "allows 2-character domains" do
|
||||
proper_list = "dev.to, forem.com, 2u.com"
|
||||
post admin_settings_authentications_path, params: {
|
||||
settings_authentication: { allowed_registration_email_domains: proper_list },
|
||||
confirmation: confirmation_message
|
||||
settings_authentication: { allowed_registration_email_domains: proper_list }
|
||||
}
|
||||
expect(Settings::Authentication.allowed_registration_email_domains).to eq(%w[dev.to forem.com 2u.com])
|
||||
end
|
||||
|
|
@ -146,24 +124,21 @@ RSpec.describe "/admin/customization/config", type: :request do
|
|||
it "does not allow improper domain list" do
|
||||
impproper_list = "dev.to, foremcom, forem.dev"
|
||||
post admin_settings_authentications_path, params: {
|
||||
settings_authentication: { allowed_registration_email_domains: impproper_list },
|
||||
confirmation: confirmation_message
|
||||
settings_authentication: { allowed_registration_email_domains: impproper_list }
|
||||
}
|
||||
expect(Settings::Authentication.allowed_registration_email_domains).not_to eq(%w[dev.to foremcom forem.dev])
|
||||
end
|
||||
|
||||
it "enables display_email_domain_allow_list_publicly" do
|
||||
post admin_settings_authentications_path, params: {
|
||||
settings_authentication: { display_email_domain_allow_list_publicly: true },
|
||||
confirmation: confirmation_message
|
||||
settings_authentication: { display_email_domain_allow_list_publicly: true }
|
||||
}
|
||||
expect(Settings::Authentication.display_email_domain_allow_list_publicly).to be(true)
|
||||
end
|
||||
|
||||
it "enables email authentication" do
|
||||
post admin_settings_authentications_path, params: {
|
||||
settings_authentication: { allow_email_password_registration: true },
|
||||
confirmation: confirmation_message
|
||||
settings_authentication: { allow_email_password_registration: true }
|
||||
}
|
||||
expect(Settings::Authentication.allow_email_password_registration).to be(true)
|
||||
expect(Settings::Authentication.allow_email_password_login).to be(true)
|
||||
|
|
@ -171,8 +146,7 @@ RSpec.describe "/admin/customization/config", type: :request do
|
|||
|
||||
it "disables email authentication" do
|
||||
post admin_settings_authentications_path, params: {
|
||||
settings_authentication: { allow_email_password_registration: false },
|
||||
confirmation: confirmation_message
|
||||
settings_authentication: { allow_email_password_registration: false }
|
||||
}
|
||||
expect(Settings::Authentication.allow_email_password_registration).to be(false)
|
||||
expect(Settings::Authentication.allow_email_password_login).to be(true)
|
||||
|
|
@ -180,16 +154,14 @@ RSpec.describe "/admin/customization/config", type: :request do
|
|||
|
||||
it "enables invite-only-mode" do
|
||||
post admin_settings_authentications_path, params: {
|
||||
settings_authentication: { invite_only_mode: true },
|
||||
confirmation: confirmation_message
|
||||
settings_authentication: { invite_only_mode: true }
|
||||
}
|
||||
expect(Settings::Authentication.invite_only_mode).to be(true)
|
||||
end
|
||||
|
||||
it "disables invite-only-mode & enables just email registration" do
|
||||
post admin_settings_authentications_path, params: {
|
||||
settings_authentication: { invite_only_mode: false },
|
||||
confirmation: confirmation_message
|
||||
settings_authentication: { invite_only_mode: false }
|
||||
}
|
||||
expect(Settings::Authentication.invite_only_mode).to be(false)
|
||||
end
|
||||
|
|
@ -198,8 +170,7 @@ RSpec.describe "/admin/customization/config", type: :request do
|
|||
describe "Campaigns" do
|
||||
it "sets articles_expiry_time" do
|
||||
post admin_settings_campaigns_path, params: {
|
||||
settings_campaign: { articles_expiry_time: 4 },
|
||||
confirmation: confirmation_message
|
||||
settings_campaign: { articles_expiry_time: 4 }
|
||||
}
|
||||
expect(Settings::Campaign.articles_expiry_time).to eq(4)
|
||||
end
|
||||
|
|
@ -210,8 +181,7 @@ RSpec.describe "/admin/customization/config", type: :request do
|
|||
allow(Settings::Community).to receive(:community_description).and_call_original
|
||||
description = "Hey hey #{rand(100)}"
|
||||
post admin_settings_communities_path, params: {
|
||||
settings_community: { community_description: description },
|
||||
confirmation: confirmation_message
|
||||
settings_community: { community_description: description }
|
||||
}
|
||||
expect(Settings::Community.community_description).to eq(description)
|
||||
end
|
||||
|
|
@ -220,8 +190,7 @@ RSpec.describe "/admin/customization/config", type: :request do
|
|||
allow(Settings::Community).to receive(:community_emoji).and_call_original
|
||||
emoji = "🥐"
|
||||
post admin_settings_communities_path, params: {
|
||||
settings_community: { community_emoji: emoji },
|
||||
confirmation: confirmation_message
|
||||
settings_community: { community_emoji: emoji }
|
||||
}
|
||||
expect(Settings::Community.community_emoji).to eq(emoji)
|
||||
end
|
||||
|
|
@ -231,8 +200,7 @@ RSpec.describe "/admin/customization/config", type: :request do
|
|||
not_an_emoji = "i love croissants"
|
||||
expect do
|
||||
post admin_settings_communities_path, params: {
|
||||
settings_community: { community_emoji: not_an_emoji },
|
||||
confirmation: confirmation_message
|
||||
settings_community: { community_emoji: not_an_emoji }
|
||||
}
|
||||
end.not_to change(Settings::Community, :community_emoji)
|
||||
end
|
||||
|
|
@ -240,8 +208,7 @@ RSpec.describe "/admin/customization/config", type: :request do
|
|||
it "updates the community_name" do
|
||||
name_magoo = "Hey hey #{rand(100)}"
|
||||
post admin_settings_communities_path, params: {
|
||||
settings_community: { community_name: name_magoo },
|
||||
confirmation: confirmation_message
|
||||
settings_community: { community_name: name_magoo }
|
||||
}
|
||||
expect(Settings::Community.community_name).to eq(name_magoo)
|
||||
end
|
||||
|
|
@ -249,8 +216,7 @@ RSpec.describe "/admin/customization/config", type: :request do
|
|||
it "updates the community_member_label" do
|
||||
name = "developer"
|
||||
post admin_settings_communities_path, params: {
|
||||
settings_community: { member_label: name },
|
||||
confirmation: confirmation_message
|
||||
settings_community: { member_label: name }
|
||||
}
|
||||
expect(Settings::Community.member_label).to eq(name)
|
||||
end
|
||||
|
|
@ -258,8 +224,7 @@ RSpec.describe "/admin/customization/config", type: :request do
|
|||
it "updates the copyright_start_year" do
|
||||
year = "2018"
|
||||
post admin_settings_communities_path, params: {
|
||||
settings_community: { copyright_start_year: year },
|
||||
confirmation: confirmation_message
|
||||
settings_community: { copyright_start_year: year }
|
||||
}
|
||||
expect(Settings::Community.copyright_start_year).to eq(2018)
|
||||
end
|
||||
|
|
@ -267,16 +232,14 @@ RSpec.describe "/admin/customization/config", type: :request do
|
|||
it "updates the tagline" do
|
||||
description = "Hey hey #{rand(100)}"
|
||||
post admin_settings_communities_path, params: {
|
||||
settings_community: { tagline: description },
|
||||
confirmation: confirmation_message
|
||||
settings_community: { tagline: description }
|
||||
}
|
||||
expect(Settings::Community.tagline).to eq(description)
|
||||
end
|
||||
|
||||
it "updates the staff_user_id" do
|
||||
post admin_settings_communities_path, params: {
|
||||
settings_community: { staff_user_id: 22 },
|
||||
confirmation: confirmation_message
|
||||
settings_community: { staff_user_id: 22 }
|
||||
}
|
||||
expect(Settings::Community.staff_user_id).to eq(22)
|
||||
end
|
||||
|
|
@ -285,8 +248,7 @@ RSpec.describe "/admin/customization/config", type: :request do
|
|||
describe "Emails" do
|
||||
it "does not update the default email address" do
|
||||
post admin_settings_general_settings_path, params: {
|
||||
settings_general: { email_addresses: { default: "random@example.com" } },
|
||||
confirmation: confirmation_message
|
||||
settings_general: { email_addresses: { default: "random@example.com" } }
|
||||
}
|
||||
|
||||
expect(ForemInstance.email).not_to eq("random@example.com")
|
||||
|
|
@ -296,28 +258,16 @@ RSpec.describe "/admin/customization/config", type: :request do
|
|||
describe "Email digest frequency" do
|
||||
it "updates periodic_email_digest" do
|
||||
post admin_settings_general_settings_path, params: {
|
||||
settings_general: { periodic_email_digest: 1 },
|
||||
confirmation: confirmation_message
|
||||
settings_general: { periodic_email_digest: 1 }
|
||||
}
|
||||
expect(Settings::General.periodic_email_digest).to eq(1)
|
||||
end
|
||||
|
||||
it "rejects update without proper confirmation" do
|
||||
expect do
|
||||
post admin_settings_general_settings_path, params: {
|
||||
settings_general: { periodic_email_digest: 6 },
|
||||
confirmation: "Incorrect yo!"
|
||||
}
|
||||
end.to raise_error ActionController::BadRequest
|
||||
expect(Settings::General.periodic_email_digest).not_to eq(6)
|
||||
end
|
||||
end
|
||||
|
||||
describe "Google Analytics Reporting API v4" do
|
||||
it "updates ga_tracking_id" do
|
||||
post admin_settings_general_settings_path, params: {
|
||||
settings_general: { ga_tracking_id: "abc" },
|
||||
confirmation: confirmation_message
|
||||
settings_general: { ga_tracking_id: "abc" }
|
||||
}
|
||||
expect(Settings::General.ga_tracking_id).to eq("abc")
|
||||
end
|
||||
|
|
@ -330,8 +280,7 @@ RSpec.describe "/admin/customization/config", type: :request do
|
|||
|
||||
expected_image_url = "https://dummyimage.com/300x300.png"
|
||||
post admin_settings_general_settings_path, params: {
|
||||
settings_general: { main_social_image: expected_image_url },
|
||||
confirmation: confirmation_message
|
||||
settings_general: { main_social_image: expected_image_url }
|
||||
}
|
||||
expect(Settings::General.main_social_image).to eq(expected_image_url)
|
||||
end
|
||||
|
|
@ -340,8 +289,7 @@ RSpec.describe "/admin/customization/config", type: :request do
|
|||
expected_image = "https://dummyimage.com/300x300"
|
||||
|
||||
post admin_settings_general_settings_path, params: {
|
||||
settings_general: { main_social_image: expected_image },
|
||||
confirmation: confirmation_message
|
||||
settings_general: { main_social_image: expected_image }
|
||||
}
|
||||
expect(Settings::General.main_social_image).to eq(expected_image)
|
||||
end
|
||||
|
|
@ -350,8 +298,7 @@ RSpec.describe "/admin/customization/config", type: :request do
|
|||
invalid_image_url = "![logo_lowres]https://dummyimage.com/300x300"
|
||||
expect do
|
||||
post admin_settings_general_settings_path, params: {
|
||||
settings_general: { main_social_image: invalid_image_url },
|
||||
confirmation: confirmation_message
|
||||
settings_general: { main_social_image: invalid_image_url }
|
||||
}
|
||||
end.not_to change(Settings::General, :main_social_image)
|
||||
end
|
||||
|
|
@ -359,8 +306,7 @@ RSpec.describe "/admin/customization/config", type: :request do
|
|||
it "updates favicon_url" do
|
||||
expected_image_url = "https://dummyimage.com/300x300.png"
|
||||
post admin_settings_general_settings_path, params: {
|
||||
settings_general: { favicon_url: expected_image_url },
|
||||
confirmation: confirmation_message
|
||||
settings_general: { favicon_url: expected_image_url }
|
||||
}
|
||||
expect(Settings::General.favicon_url).to eq(expected_image_url)
|
||||
end
|
||||
|
|
@ -370,8 +316,7 @@ RSpec.describe "/admin/customization/config", type: :request do
|
|||
expected_image_url = "https://dummyimage.com/300x300.png"
|
||||
expect do
|
||||
post admin_settings_general_settings_path, params: {
|
||||
settings_general: { logo_png: expected_image_url },
|
||||
confirmation: confirmation_message
|
||||
settings_general: { logo_png: expected_image_url }
|
||||
}
|
||||
end.to change(Settings::General, :logo_png).from(expected_default_image_url).to(expected_image_url)
|
||||
end
|
||||
|
|
@ -380,8 +325,7 @@ RSpec.describe "/admin/customization/config", type: :request do
|
|||
expected_image = "https://dummyimage.com/300x300"
|
||||
|
||||
post admin_settings_general_settings_path, params: {
|
||||
settings_general: { logo_png: expected_image },
|
||||
confirmation: confirmation_message
|
||||
settings_general: { logo_png: expected_image }
|
||||
}
|
||||
expect(Settings::General.logo_png).to eq(expected_image)
|
||||
end
|
||||
|
|
@ -390,8 +334,7 @@ RSpec.describe "/admin/customization/config", type: :request do
|
|||
invalid_image_url = "![logo_lowres]https://dummyimage.com/300x300.png"
|
||||
expect do
|
||||
post admin_settings_general_settings_path, params: {
|
||||
settings_general: { logo_png: invalid_image_url },
|
||||
confirmation: confirmation_message
|
||||
settings_general: { logo_png: invalid_image_url }
|
||||
}
|
||||
end.not_to change(Settings::General, :logo_png)
|
||||
end
|
||||
|
|
@ -399,39 +342,17 @@ RSpec.describe "/admin/customization/config", type: :request do
|
|||
it "updates logo_svg" do
|
||||
expected_image_url = "https://dummyimage.com/300x300.png"
|
||||
post admin_settings_general_settings_path, params: {
|
||||
settings_general: { logo_svg: expected_image_url },
|
||||
confirmation: confirmation_message
|
||||
settings_general: { logo_svg: expected_image_url }
|
||||
}
|
||||
expect(Settings::General.logo_svg).to eq(expected_image_url)
|
||||
end
|
||||
|
||||
it "rejects update without proper confirmation" do
|
||||
expected_image_url = "https://dummyimage.com/300x300.png"
|
||||
expect do
|
||||
post admin_settings_general_settings_path, params: {
|
||||
settings_general: { logo_svg: expected_image_url },
|
||||
confirmation: "Incorrect yo!"
|
||||
}
|
||||
end.to raise_error ActionController::BadRequest
|
||||
end
|
||||
|
||||
it "rejects update without any confirmation" do
|
||||
expected_image_url = "https://dummyimage.com/300x300.png"
|
||||
expect do
|
||||
post admin_settings_general_settings_path, params: {
|
||||
settings_general: { logo_svg: expected_image_url },
|
||||
confirmation: ""
|
||||
}
|
||||
end.to raise_error ActionController::ParameterMissing
|
||||
end
|
||||
end
|
||||
|
||||
describe "Mascot" do
|
||||
it "updates the mascot_user_id" do
|
||||
expected_mascot_user_id = 2
|
||||
post admin_settings_general_settings_path, params: {
|
||||
settings_general: { mascot_user_id: expected_mascot_user_id },
|
||||
confirmation: confirmation_message
|
||||
settings_general: { mascot_user_id: expected_mascot_user_id }
|
||||
}
|
||||
expect(Settings::General.mascot_user_id).to eq(expected_mascot_user_id)
|
||||
end
|
||||
|
|
@ -441,8 +362,7 @@ RSpec.describe "/admin/customization/config", type: :request do
|
|||
expected_image_url = "https://dummyimage.com/300x300.png"
|
||||
expect do
|
||||
post admin_settings_general_settings_path, params: {
|
||||
settings_general: { mascot_image_url: expected_image_url },
|
||||
confirmation: confirmation_message
|
||||
settings_general: { mascot_image_url: expected_image_url }
|
||||
}
|
||||
end.to change(Settings::General, :mascot_image_url).from(expected_default_image_url).to(expected_image_url)
|
||||
end
|
||||
|
|
@ -452,8 +372,7 @@ RSpec.describe "/admin/customization/config", type: :request do
|
|||
it "updates meta keywords" do
|
||||
expected_keywords = { "default" => "software, people", "article" => "user, experience", "tag" => "bye" }
|
||||
post admin_settings_general_settings_path, params: {
|
||||
settings_general: { meta_keywords: expected_keywords },
|
||||
confirmation: confirmation_message
|
||||
settings_general: { meta_keywords: expected_keywords }
|
||||
}
|
||||
expect(Settings::General.meta_keywords[:default]).to eq("software, people")
|
||||
expect(Settings::General.meta_keywords[:article]).to eq("user, experience")
|
||||
|
|
@ -464,8 +383,7 @@ RSpec.describe "/admin/customization/config", type: :request do
|
|||
describe "Monetization" do
|
||||
it "updates payment pointer" do
|
||||
post admin_settings_general_settings_path, params: {
|
||||
settings_general: { payment_pointer: "$pay.yo" },
|
||||
confirmation: confirmation_message
|
||||
settings_general: { payment_pointer: "$pay.yo" }
|
||||
}
|
||||
expect(Settings::General.payment_pointer).to eq("$pay.yo")
|
||||
end
|
||||
|
|
@ -475,8 +393,7 @@ RSpec.describe "/admin/customization/config", type: :request do
|
|||
settings_general: {
|
||||
stripe_api_key: "sk_live_yo",
|
||||
stripe_publishable_key: "pk_live_haha"
|
||||
},
|
||||
confirmation: confirmation_message
|
||||
}
|
||||
}
|
||||
expect(Settings::General.stripe_api_key).to eq("sk_live_yo")
|
||||
expect(Settings::General.stripe_publishable_key).to eq("pk_live_haha")
|
||||
|
|
@ -486,40 +403,35 @@ RSpec.describe "/admin/customization/config", type: :request do
|
|||
describe "Newsletter" do
|
||||
it "updates mailchimp_api_key" do
|
||||
post admin_settings_general_settings_path, params: {
|
||||
settings_general: { mailchimp_api_key: "abc" },
|
||||
confirmation: confirmation_message
|
||||
settings_general: { mailchimp_api_key: "abc" }
|
||||
}
|
||||
expect(Settings::General.mailchimp_api_key).to eq("abc")
|
||||
end
|
||||
|
||||
it "updates mailchimp_newsletter_id" do
|
||||
post admin_settings_general_settings_path, params: {
|
||||
settings_general: { mailchimp_newsletter_id: "abc" },
|
||||
confirmation: confirmation_message
|
||||
settings_general: { mailchimp_newsletter_id: "abc" }
|
||||
}
|
||||
expect(Settings::General.mailchimp_newsletter_id).to eq("abc")
|
||||
end
|
||||
|
||||
it "updates mailchimp_sustaining_members_id" do
|
||||
post admin_settings_general_settings_path, params: {
|
||||
settings_general: { mailchimp_sustaining_members_id: "abc" },
|
||||
confirmation: confirmation_message
|
||||
settings_general: { mailchimp_sustaining_members_id: "abc" }
|
||||
}
|
||||
expect(Settings::General.mailchimp_sustaining_members_id).to eq("abc")
|
||||
end
|
||||
|
||||
it "updates mailchimp_tag_moderators_id" do
|
||||
post admin_settings_general_settings_path, params: {
|
||||
settings_general: { mailchimp_tag_moderators_id: "abc" },
|
||||
confirmation: confirmation_message
|
||||
settings_general: { mailchimp_tag_moderators_id: "abc" }
|
||||
}
|
||||
expect(Settings::General.mailchimp_tag_moderators_id).to eq("abc")
|
||||
end
|
||||
|
||||
it "updates mailchimp_community_moderators_id" do
|
||||
post admin_settings_general_settings_path, params: {
|
||||
settings_general: { mailchimp_community_moderators_id: "abc" },
|
||||
confirmation: confirmation_message
|
||||
settings_general: { mailchimp_community_moderators_id: "abc" }
|
||||
}
|
||||
expect(Settings::General.mailchimp_community_moderators_id).to eq("abc")
|
||||
end
|
||||
|
|
@ -530,24 +442,21 @@ RSpec.describe "/admin/customization/config", type: :request do
|
|||
expected_image_url = "https://dummyimage.com/300x300.png"
|
||||
post admin_settings_general_settings_path, params: {
|
||||
settings_general:
|
||||
{ onboarding_background_image: expected_image_url },
|
||||
confirmation: confirmation_message
|
||||
{ onboarding_background_image: expected_image_url }
|
||||
}
|
||||
expect(Settings::General.onboarding_background_image).to eq(expected_image_url)
|
||||
end
|
||||
|
||||
it "removes space suggested_tags" do
|
||||
post admin_settings_general_settings_path, params: {
|
||||
settings_general: { suggested_tags: "hey, haha,hoho, bobo fofo" },
|
||||
confirmation: confirmation_message
|
||||
settings_general: { suggested_tags: "hey, haha,hoho, bobo fofo" }
|
||||
}
|
||||
expect(Settings::General.suggested_tags).to eq(%w[hey haha hoho bobofofo])
|
||||
end
|
||||
|
||||
it "downcases suggested_tags" do
|
||||
post admin_settings_general_settings_path, params: {
|
||||
settings_general: { suggested_tags: "hey, haha,hoHo, Bobo Fofo" },
|
||||
confirmation: confirmation_message
|
||||
settings_general: { suggested_tags: "hey, haha,hoHo, Bobo Fofo" }
|
||||
}
|
||||
expect(Settings::General.suggested_tags).to eq(%w[hey haha hoho bobofofo])
|
||||
end
|
||||
|
|
@ -556,8 +465,7 @@ RSpec.describe "/admin/customization/config", type: :request do
|
|||
post admin_settings_general_settings_path, params: {
|
||||
settings_general: {
|
||||
suggested_users: "piglet, tigger,eeyore, Christopher Robin, kanga,roo"
|
||||
},
|
||||
confirmation: confirmation_message
|
||||
}
|
||||
}
|
||||
expect(Settings::General.suggested_users).to eq(%w[piglet tigger eeyore christopherrobin kanga roo])
|
||||
end
|
||||
|
|
@ -566,8 +474,7 @@ RSpec.describe "/admin/customization/config", type: :request do
|
|||
post admin_settings_general_settings_path, params: {
|
||||
settings_general: {
|
||||
suggested_users: "piglet, tigger,EEYORE, Christopher Robin, KANGA,RoO"
|
||||
},
|
||||
confirmation: confirmation_message
|
||||
}
|
||||
}
|
||||
expect(Settings::General.suggested_users).to eq(%w[piglet tigger eeyore christopherrobin kanga roo])
|
||||
end
|
||||
|
|
@ -575,8 +482,7 @@ RSpec.describe "/admin/customization/config", type: :request do
|
|||
it "updates prefer_manual_suggested_users to true" do
|
||||
prefer_manual = true
|
||||
post admin_settings_general_settings_path, params: {
|
||||
settings_general: { prefer_manual_suggested_users: prefer_manual },
|
||||
confirmation: confirmation_message
|
||||
settings_general: { prefer_manual_suggested_users: prefer_manual }
|
||||
}
|
||||
expect(Settings::General.prefer_manual_suggested_users).to eq(prefer_manual)
|
||||
end
|
||||
|
|
@ -584,8 +490,7 @@ RSpec.describe "/admin/customization/config", type: :request do
|
|||
it "updates prefer_manual_suggested_users to false" do
|
||||
prefer_manual = false
|
||||
post admin_settings_general_settings_path, params: {
|
||||
settings_general: { prefer_manual_suggested_users: prefer_manual },
|
||||
confirmation: confirmation_message
|
||||
settings_general: { prefer_manual_suggested_users: prefer_manual }
|
||||
}
|
||||
expect(Settings::General.prefer_manual_suggested_users).to eq(prefer_manual)
|
||||
end
|
||||
|
|
@ -596,8 +501,7 @@ RSpec.describe "/admin/customization/config", type: :request do
|
|||
default_value = Settings::RateLimit.get_default(:follow_count_daily)
|
||||
expect do
|
||||
post admin_settings_rate_limits_path, params: {
|
||||
settings_rate_limit: { follow_count_daily: 3 },
|
||||
confirmation: confirmation_message
|
||||
settings_rate_limit: { follow_count_daily: 3 }
|
||||
}
|
||||
end.to change(Settings::RateLimit, :follow_count_daily).from(default_value).to(3)
|
||||
end
|
||||
|
|
@ -606,8 +510,7 @@ RSpec.describe "/admin/customization/config", type: :request do
|
|||
default_value = Settings::RateLimit.get_default(:comment_creation)
|
||||
expect do
|
||||
post admin_settings_rate_limits_path, params: {
|
||||
settings_rate_limit: { comment_creation: 3 },
|
||||
confirmation: confirmation_message
|
||||
settings_rate_limit: { comment_creation: 3 }
|
||||
}
|
||||
end.to change(Settings::RateLimit, :comment_creation).from(default_value).to(3)
|
||||
end
|
||||
|
|
@ -616,8 +519,7 @@ RSpec.describe "/admin/customization/config", type: :request do
|
|||
default_value = Settings::RateLimit.get_default(:mention_creation)
|
||||
expect do
|
||||
post admin_settings_rate_limits_path, params: {
|
||||
settings_rate_limit: { mention_creation: 10 },
|
||||
confirmation: confirmation_message
|
||||
settings_rate_limit: { mention_creation: 10 }
|
||||
}
|
||||
end.to change(Settings::RateLimit, :mention_creation).from(default_value).to(10)
|
||||
end
|
||||
|
|
@ -626,8 +528,7 @@ RSpec.describe "/admin/customization/config", type: :request do
|
|||
default_value = Settings::RateLimit.get_default(:published_article_creation)
|
||||
expect do
|
||||
post admin_settings_rate_limits_path, params: {
|
||||
settings_rate_limit: { published_article_creation: 3 },
|
||||
confirmation: confirmation_message
|
||||
settings_rate_limit: { published_article_creation: 3 }
|
||||
}
|
||||
end.to change(Settings::RateLimit, :published_article_creation).from(default_value).to(3)
|
||||
end
|
||||
|
|
@ -636,8 +537,7 @@ RSpec.describe "/admin/customization/config", type: :request do
|
|||
default_value = Settings::RateLimit.get_default(:published_article_antispam_creation)
|
||||
expect do
|
||||
post admin_settings_rate_limits_path, params: {
|
||||
settings_rate_limit: { published_article_antispam_creation: 3 },
|
||||
confirmation: confirmation_message
|
||||
settings_rate_limit: { published_article_antispam_creation: 3 }
|
||||
}
|
||||
end.to change(Settings::RateLimit, :published_article_antispam_creation).from(default_value).to(3)
|
||||
end
|
||||
|
|
@ -646,8 +546,7 @@ RSpec.describe "/admin/customization/config", type: :request do
|
|||
default_value = Settings::RateLimit.get_default(:organization_creation)
|
||||
expect do
|
||||
post admin_settings_rate_limits_path, params: {
|
||||
settings_rate_limit: { organization_creation: 3 },
|
||||
confirmation: confirmation_message
|
||||
settings_rate_limit: { organization_creation: 3 }
|
||||
}
|
||||
end.to change(Settings::RateLimit, :organization_creation).from(default_value).to(3)
|
||||
end
|
||||
|
|
@ -656,8 +555,7 @@ RSpec.describe "/admin/customization/config", type: :request do
|
|||
default_value = Settings::RateLimit.get_default(:image_upload)
|
||||
expect do
|
||||
post admin_settings_rate_limits_path, params: {
|
||||
settings_rate_limit: { image_upload: 3 },
|
||||
confirmation: confirmation_message
|
||||
settings_rate_limit: { image_upload: 3 }
|
||||
}
|
||||
end.to change(Settings::RateLimit, :image_upload).from(default_value).to(3)
|
||||
end
|
||||
|
|
@ -666,8 +564,7 @@ RSpec.describe "/admin/customization/config", type: :request do
|
|||
default_value = Settings::RateLimit.get_default(:email_recipient)
|
||||
expect do
|
||||
post admin_settings_rate_limits_path, params: {
|
||||
settings_rate_limit: { email_recipient: 3 },
|
||||
confirmation: confirmation_message
|
||||
settings_rate_limit: { email_recipient: 3 }
|
||||
}
|
||||
end.to change(Settings::RateLimit, :email_recipient).from(default_value).to(3)
|
||||
end
|
||||
|
|
@ -676,8 +573,7 @@ RSpec.describe "/admin/customization/config", type: :request do
|
|||
default_value = Settings::RateLimit.get_default(:user_subscription_creation)
|
||||
expect do
|
||||
post admin_settings_rate_limits_path, params: {
|
||||
settings_rate_limit: { user_subscription_creation: 1 },
|
||||
confirmation: confirmation_message
|
||||
settings_rate_limit: { user_subscription_creation: 1 }
|
||||
}
|
||||
end.to change(Settings::RateLimit, :user_subscription_creation).from(default_value).to(1)
|
||||
end
|
||||
|
|
@ -686,8 +582,7 @@ RSpec.describe "/admin/customization/config", type: :request do
|
|||
default_value = Settings::RateLimit.get_default(:article_update)
|
||||
expect do
|
||||
post admin_settings_rate_limits_path, params: {
|
||||
settings_rate_limit: { article_update: 3 },
|
||||
confirmation: confirmation_message
|
||||
settings_rate_limit: { article_update: 3 }
|
||||
}
|
||||
end.to change(Settings::RateLimit, :article_update).from(default_value).to(3)
|
||||
end
|
||||
|
|
@ -695,8 +590,7 @@ RSpec.describe "/admin/customization/config", type: :request do
|
|||
it "updates user_update" do
|
||||
expect do
|
||||
post admin_settings_rate_limits_path, params: {
|
||||
settings_rate_limit: { user_update: 3 },
|
||||
confirmation: confirmation_message
|
||||
settings_rate_limit: { user_update: 3 }
|
||||
}
|
||||
end.to change(Settings::RateLimit, :user_update).to(3)
|
||||
end
|
||||
|
|
@ -705,8 +599,7 @@ RSpec.describe "/admin/customization/config", type: :request do
|
|||
default_value = Settings::RateLimit.get_default(:feedback_message_creation)
|
||||
expect do
|
||||
post admin_settings_rate_limits_path, params: {
|
||||
settings_rate_limit: { feedback_message_creation: 3 },
|
||||
confirmation: confirmation_message
|
||||
settings_rate_limit: { feedback_message_creation: 3 }
|
||||
}
|
||||
end.to change(Settings::RateLimit, :feedback_message_creation).from(default_value).to(3)
|
||||
end
|
||||
|
|
@ -715,8 +608,7 @@ RSpec.describe "/admin/customization/config", type: :request do
|
|||
default_value = Settings::RateLimit.get_default(:listing_creation)
|
||||
expect do
|
||||
post admin_settings_rate_limits_path, params: {
|
||||
settings_rate_limit: { listing_creation: 3 },
|
||||
confirmation: confirmation_message
|
||||
settings_rate_limit: { listing_creation: 3 }
|
||||
}
|
||||
end.to change(Settings::RateLimit, :listing_creation).from(default_value).to(3)
|
||||
end
|
||||
|
|
@ -725,8 +617,7 @@ RSpec.describe "/admin/customization/config", type: :request do
|
|||
default_value = Settings::RateLimit.get_default(:reaction_creation)
|
||||
expect do
|
||||
post admin_settings_rate_limits_path, params: {
|
||||
settings_rate_limit: { reaction_creation: 3 },
|
||||
confirmation: confirmation_message
|
||||
settings_rate_limit: { reaction_creation: 3 }
|
||||
}
|
||||
end.to change(Settings::RateLimit, :reaction_creation).from(default_value).to(3)
|
||||
end
|
||||
|
|
@ -735,8 +626,7 @@ RSpec.describe "/admin/customization/config", type: :request do
|
|||
default_value = Settings::RateLimit.get_default(:send_email_confirmation)
|
||||
expect do
|
||||
post admin_settings_rate_limits_path, params: {
|
||||
settings_rate_limit: { send_email_confirmation: 3 },
|
||||
confirmation: confirmation_message
|
||||
settings_rate_limit: { send_email_confirmation: 3 }
|
||||
}
|
||||
end.to change(Settings::RateLimit, :send_email_confirmation).from(default_value).to(3)
|
||||
end
|
||||
|
|
@ -744,8 +634,7 @@ RSpec.describe "/admin/customization/config", type: :request do
|
|||
it "updates spam_trigger_terms" do
|
||||
spam_trigger_terms = "hey, pokemon go hack"
|
||||
post admin_settings_rate_limits_path, params: {
|
||||
settings_rate_limit: { spam_trigger_terms: spam_trigger_terms },
|
||||
confirmation: confirmation_message
|
||||
settings_rate_limit: { spam_trigger_terms: spam_trigger_terms }
|
||||
}
|
||||
expect(Settings::RateLimit.spam_trigger_terms).to eq(["hey", "pokemon go hack"])
|
||||
end
|
||||
|
|
@ -754,8 +643,7 @@ RSpec.describe "/admin/customization/config", type: :request do
|
|||
site_key = "hi-ho"
|
||||
secret_key = "lets-go"
|
||||
post admin_settings_authentications_path, params: {
|
||||
settings_authentication: { recaptcha_site_key: site_key, recaptcha_secret_key: secret_key },
|
||||
confirmation: confirmation_message
|
||||
settings_authentication: { recaptcha_site_key: site_key, recaptcha_secret_key: secret_key }
|
||||
}
|
||||
expect(Settings::Authentication.recaptcha_site_key).to eq site_key
|
||||
expect(Settings::Authentication.recaptcha_secret_key).to eq secret_key
|
||||
|
|
@ -766,8 +654,7 @@ RSpec.describe "/admin/customization/config", type: :request do
|
|||
it "updates social_media_handles" do
|
||||
expected_handle = { "facebook" => "tpd", "github" => "", "instagram" => "", "twitch" => "", "twitter" => "" }
|
||||
post admin_settings_general_settings_path, params: {
|
||||
settings_general: { social_media_handles: expected_handle },
|
||||
confirmation: confirmation_message
|
||||
settings_general: { social_media_handles: expected_handle }
|
||||
}
|
||||
expect(Settings::General.social_media_handles[:facebook]).to eq("tpd")
|
||||
expect(Settings::General.social_media_handles[:github]).to eq("")
|
||||
|
|
@ -776,17 +663,10 @@ RSpec.describe "/admin/customization/config", type: :request do
|
|||
describe "twitter_hashtag" do
|
||||
twitter_hashtag = "#DEVCommunity"
|
||||
params = {
|
||||
settings_general: { twitter_hashtag: twitter_hashtag }, confirmation: "Incorrect confirmation"
|
||||
settings_general: { twitter_hashtag: twitter_hashtag }
|
||||
}
|
||||
|
||||
it "does not update the twitter hashtag without the correct confirmation text" do
|
||||
expect do
|
||||
post admin_settings_general_settings_path, params: params
|
||||
end.to raise_error ActionController::BadRequest
|
||||
end
|
||||
|
||||
it "updates the twitter hashtag" do
|
||||
params["confirmation"] = confirmation_message
|
||||
post admin_settings_general_settings_path, params: params
|
||||
expect(Settings::General.twitter_hashtag.to_s).to eq twitter_hashtag
|
||||
end
|
||||
|
|
@ -799,23 +679,23 @@ RSpec.describe "/admin/customization/config", type: :request do
|
|||
it "updates appropriate SMTP configs" do
|
||||
expected_handle = { "address" => "smtp.example.com", "port" => "1234" }
|
||||
post admin_settings_smtp_settings_path, params: {
|
||||
settings_smtp: expected_handle,
|
||||
confirmation: confirmation_message
|
||||
settings_smtp: expected_handle
|
||||
}
|
||||
expect(Settings::SMTP.address).to eq("smtp.example.com")
|
||||
expect(Settings::SMTP.port).to eq(1234)
|
||||
end
|
||||
|
||||
it "unsets appropriate SMTP config, and apply default value if applicable" do
|
||||
Settings::SMTP.address = "smtp.example.com"
|
||||
Settings::SMTP.port = 12_345
|
||||
default_address = ApplicationConfig["SMTP_ADDRESS"].presence
|
||||
default_port = (ApplicationConfig["SMTP_PORT"].presence || 25).to_i
|
||||
expected_handle = { "address" => "", "port" => "" }
|
||||
|
||||
post admin_settings_smtp_settings_path, params: {
|
||||
settings_smtp: expected_handle,
|
||||
confirmation: confirmation_message
|
||||
settings_smtp: expected_handle
|
||||
}
|
||||
expect(Settings::SMTP.address).to eq(nil)
|
||||
expect(Settings::SMTP.port).to eq(25)
|
||||
|
||||
expect(Settings::SMTP.address).to eq(default_address)
|
||||
expect(Settings::SMTP.port).to eq(default_port)
|
||||
end
|
||||
end
|
||||
|
||||
|
|
@ -823,8 +703,7 @@ RSpec.describe "/admin/customization/config", type: :request do
|
|||
it "updates the sponsor_headline" do
|
||||
headline = "basic"
|
||||
post admin_settings_general_settings_path, params: {
|
||||
settings_general: { sponsor_headline: headline },
|
||||
confirmation: confirmation_message
|
||||
settings_general: { sponsor_headline: headline }
|
||||
}
|
||||
expect(Settings::General.sponsor_headline).to eq(headline)
|
||||
end
|
||||
|
|
@ -833,24 +712,21 @@ RSpec.describe "/admin/customization/config", type: :request do
|
|||
describe "Tags" do
|
||||
it "removes space sidebar_tags" do
|
||||
post admin_settings_general_settings_path, params: {
|
||||
settings_general: { sidebar_tags: "hey, haha,hoho, bobo fofo" },
|
||||
confirmation: confirmation_message
|
||||
settings_general: { sidebar_tags: "hey, haha,hoho, bobo fofo" }
|
||||
}
|
||||
expect(Settings::General.sidebar_tags).to eq(%w[hey haha hoho bobofofo])
|
||||
end
|
||||
|
||||
it "downcases sidebar_tags" do
|
||||
post admin_settings_general_settings_path, params: {
|
||||
settings_general: { sidebar_tags: "hey, haha,hoHo, Bobo Fofo" },
|
||||
confirmation: confirmation_message
|
||||
settings_general: { sidebar_tags: "hey, haha,hoHo, Bobo Fofo" }
|
||||
}
|
||||
expect(Settings::General.sidebar_tags).to eq(%w[hey haha hoho bobofofo])
|
||||
end
|
||||
|
||||
it "creates tags if they do not exist" do
|
||||
post admin_settings_general_settings_path, params: {
|
||||
settings_general: { sidebar_tags: "bobofogololo, spla, bla" },
|
||||
confirmation: confirmation_message
|
||||
settings_general: { sidebar_tags: "bobofogololo, spla, bla" }
|
||||
}
|
||||
expect(Tag.find_by(name: "bobofogololo")).to be_valid
|
||||
end
|
||||
|
|
@ -860,8 +736,7 @@ RSpec.describe "/admin/customization/config", type: :request do
|
|||
it "updates the feed_style" do
|
||||
feed_style = "basic"
|
||||
post admin_settings_user_experiences_path, params: {
|
||||
settings_user_experience: { feed_style: feed_style },
|
||||
confirmation: confirmation_message
|
||||
settings_user_experience: { feed_style: feed_style }
|
||||
}
|
||||
expect(Settings::UserExperience.feed_style).to eq(feed_style)
|
||||
end
|
||||
|
|
@ -869,8 +744,7 @@ RSpec.describe "/admin/customization/config", type: :request do
|
|||
it "updates the feed_strategy" do
|
||||
feed_strategy = "optimized"
|
||||
post admin_settings_user_experiences_path, params: {
|
||||
settings_user_experience: { feed_strategy: feed_strategy },
|
||||
confirmation: confirmation_message
|
||||
settings_user_experience: { feed_strategy: feed_strategy }
|
||||
}
|
||||
expect(Settings::UserExperience.feed_strategy).to eq(feed_strategy)
|
||||
end
|
||||
|
|
@ -878,8 +752,7 @@ RSpec.describe "/admin/customization/config", type: :request do
|
|||
it "updates the tag_feed_minimum_score" do
|
||||
tag_feed_minimum_score = 3
|
||||
post admin_settings_user_experiences_path, params: {
|
||||
settings_user_experience: { tag_feed_minimum_score: tag_feed_minimum_score },
|
||||
confirmation: confirmation_message
|
||||
settings_user_experience: { tag_feed_minimum_score: tag_feed_minimum_score }
|
||||
}
|
||||
expect(Settings::UserExperience.tag_feed_minimum_score).to eq(tag_feed_minimum_score)
|
||||
end
|
||||
|
|
@ -887,8 +760,7 @@ RSpec.describe "/admin/customization/config", type: :request do
|
|||
it "updates the home_feed_minimum_score" do
|
||||
home_feed_minimum_score = 5
|
||||
post admin_settings_user_experiences_path, params: {
|
||||
settings_user_experience: { home_feed_minimum_score: home_feed_minimum_score },
|
||||
confirmation: confirmation_message
|
||||
settings_user_experience: { home_feed_minimum_score: home_feed_minimum_score }
|
||||
}
|
||||
expect(Settings::UserExperience.home_feed_minimum_score).to eq(home_feed_minimum_score)
|
||||
end
|
||||
|
|
@ -896,8 +768,7 @@ RSpec.describe "/admin/customization/config", type: :request do
|
|||
it "updates the brand color if proper hex" do
|
||||
hex = "#0a0a0a" # dark enough
|
||||
post admin_settings_user_experiences_path, params: {
|
||||
settings_user_experience: { primary_brand_color_hex: hex },
|
||||
confirmation: confirmation_message
|
||||
settings_user_experience: { primary_brand_color_hex: hex }
|
||||
}
|
||||
expect(Settings::UserExperience.primary_brand_color_hex).to eq(hex)
|
||||
end
|
||||
|
|
@ -905,8 +776,7 @@ RSpec.describe "/admin/customization/config", type: :request do
|
|||
it "does not update brand color if hex not contrasting enough" do
|
||||
hex = "#bd746f" # not dark enough
|
||||
post admin_settings_user_experiences_path, params: {
|
||||
settings_user_experience: { primary_brand_color_hex: hex },
|
||||
confirmation: confirmation_message
|
||||
settings_user_experience: { primary_brand_color_hex: hex }
|
||||
}
|
||||
expect(Settings::UserExperience.primary_brand_color_hex).not_to eq(hex)
|
||||
end
|
||||
|
|
@ -914,8 +784,7 @@ RSpec.describe "/admin/customization/config", type: :request do
|
|||
it "does not update brand color if hex not a hex with proper format" do
|
||||
hex = "0a0a0a" # dark enough, but not proper format
|
||||
post admin_settings_user_experiences_path, params: {
|
||||
settings_user_experience: { primary_brand_color_hex: hex },
|
||||
confirmation: confirmation_message
|
||||
settings_user_experience: { primary_brand_color_hex: hex }
|
||||
}
|
||||
expect(Settings::UserExperience.primary_brand_color_hex).not_to eq(hex)
|
||||
end
|
||||
|
|
@ -923,8 +792,7 @@ RSpec.describe "/admin/customization/config", type: :request do
|
|||
it "updates public to true" do
|
||||
is_public = true
|
||||
post admin_settings_user_experiences_path, params: {
|
||||
settings_user_experience: { public: is_public },
|
||||
confirmation: confirmation_message
|
||||
settings_user_experience: { public: is_public }
|
||||
}
|
||||
expect(Settings::UserExperience.public).to eq(is_public)
|
||||
end
|
||||
|
|
@ -933,8 +801,7 @@ RSpec.describe "/admin/customization/config", type: :request do
|
|||
allow(Settings::UserExperience).to receive(:public).and_return(false)
|
||||
is_public = false
|
||||
post admin_settings_user_experiences_path, params: {
|
||||
settings_user_experience: { public: is_public },
|
||||
confirmation: confirmation_message
|
||||
settings_user_experience: { public: is_public }
|
||||
}
|
||||
expect(Settings::UserExperience.public).to eq(is_public)
|
||||
end
|
||||
|
|
@ -949,8 +816,7 @@ RSpec.describe "/admin/customization/config", type: :request do
|
|||
new_prices = original_prices.merge(size => 123)
|
||||
expect do
|
||||
post admin_settings_general_settings_path, params: {
|
||||
settings_general: { credit_prices_in_cents: new_prices },
|
||||
confirmation: confirmation_message
|
||||
settings_general: { credit_prices_in_cents: new_prices }
|
||||
}
|
||||
end.to change { Settings::General.credit_prices_in_cents[size] }.from(original_prices[size.to_sym]).to(123)
|
||||
end
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue