0
0
Fork 1
Spiegel von https://github.com/paviliondev/discourse-custom-wizard.git synchronisiert 2024-09-19 23:31:11 +02:00
Dieser Commit ist enthalten in:
Angus McLeod 2022-03-25 17:08:24 +01:00
Ursprung 92219ace2f
Commit 04f0d34ef3
24 geänderte Dateien mit 379 neuen und 251 gelöschten Zeilen

Datei anzeigen

@ -44,7 +44,7 @@ class CustomWizard::WizardController < ::ActionController::Base
return render json: { error: I18n.t('wizard.no_skip') } return render json: { error: I18n.t('wizard.no_skip') }
end end
result = success_json result = { success: 'OK' }
if current_user && wizard.can_access? if current_user && wizard.can_access?
if redirect_to = wizard.current_submission&.redirect_to if redirect_to = wizard.current_submission&.redirect_to

Datei anzeigen

@ -53,6 +53,7 @@ en:
after_signup_after_time: "You can't use 'after time' and 'after signup' on the same wizard." after_signup_after_time: "You can't use 'after time' and 'after signup' on the same wizard."
after_time: "After time setting is invalid." after_time: "After time setting is invalid."
liquid_syntax_error: "Liquid syntax error in %{attribute}: %{message}" liquid_syntax_error: "Liquid syntax error in %{attribute}: %{message}"
subscription: "%{type} %{property} is subscription only"
site_settings: site_settings:
custom_wizard_enabled: "Enable custom wizards." custom_wizard_enabled: "Enable custom wizards."

Datei anzeigen

@ -84,7 +84,7 @@ class ::CustomWizard::CustomField
next next
end end
if attr == 'klass' && @subscription.includes?(:custom_field, :klass, value) if attr == 'klass' && !@subscription.includes?(:custom_field, :klass, value)
add_error(I18n.t("wizard.custom_field.error.subscription_type", type: value)) add_error(I18n.t("wizard.custom_field.error.subscription_type", type: value))
end end
@ -99,7 +99,7 @@ class ::CustomWizard::CustomField
add_error(I18n.t("#{i18n_key}.unsupported_type", type: value)) add_error(I18n.t("#{i18n_key}.unsupported_type", type: value))
end end
if attr == 'type' && @subscription.includes?(:custom_field, :type, value) if attr == 'type' && !@subscription.includes?(:custom_field, :type, value)
add_error(I18n.t("wizard.custom_field.error.subscription_type", type: value)) add_error(I18n.t("wizard.custom_field.error.subscription_type", type: value))
end end

Datei anzeigen

@ -51,16 +51,7 @@ class CustomWizard::Subscription
business: ['*'] business: ['*']
}, },
type: { type: {
none: ['label', 'description', 'image', 'required', 'placeholder', 'file'], none: ['text', 'textarea', 'text_only', 'date', 'time', 'date_time', 'number', 'checkbox', 'dropdown', 'upload'],
standard: ['*'],
business: ['*']
},
prefill: {
standard: ['*'],
business: ['*']
},
content: {
none: [],
standard: ['*'], standard: ['*'],
business: ['*'] business: ['*']
}, },
@ -72,8 +63,8 @@ class CustomWizard::Subscription
}, },
action: { action: {
type: { type: {
none: [], none: ['create_topic', 'update_profile', 'open_composer', 'route_to'],
standard: ['send_message', 'watch_categories', 'add_to_group'], standard: ['create_topic', 'update_profile', 'open_composer', 'route_to', 'send_message', 'watch_categories', 'add_to_group'],
business: ['*'] business: ['*']
} }
}, },
@ -108,7 +99,7 @@ class CustomWizard::Subscription
return false if values.blank? return false if values.blank?
## Subscription type supports all values of the attribute. ## Subscription type supports all values of the attribute.
return true if values === "*" return true if values.first === "*"
## Subscription type supports some values of the attributes. ## Subscription type supports some values of the attributes.
values.include?(value) values.include?(value)
@ -168,4 +159,12 @@ class CustomWizard::Subscription
def self.type def self.type
new.type new.type
end end
def self.client_installed?
new.client_installed?
end
def self.includes?(feature, attribute, value)
new.includes?(feature, attribute, value)
end
end end

Datei anzeigen

@ -54,15 +54,6 @@ class CustomWizard::TemplateValidator
} }
end end
def self.subscription
{
wizard: ['save_submissions', 'restart_on_revisit'],
step: ['condition', 'index', 'required_data', 'permitted_params'],
field: ['condition', 'index'],
action: ['type']
}
end
private private
def check_required(object, type) def check_required(object, type)
@ -74,8 +65,10 @@ class CustomWizard::TemplateValidator
end end
def validate_subscription(object, type) def validate_subscription(object, type)
self.class.subscription[type].each do |property| object.keys.each do |property|
if !@subscription.includes?(type, property, object[property]) value = object[property]
if !@subscription.includes?(type, property.to_sym, value)
errors.add :base, I18n.t("wizard.validation.subscription", type: type.to_s, property: property) errors.add :base, I18n.t("wizard.validation.subscription", type: type.to_s, property: property)
end end
end end

Datei anzeigen

@ -8,6 +8,7 @@ describe CustomWizard::Action do
let(:wizard_template) { get_wizard_fixture("wizard") } let(:wizard_template) { get_wizard_fixture("wizard") }
let(:open_composer) { get_wizard_fixture("actions/open_composer") } let(:open_composer) { get_wizard_fixture("actions/open_composer") }
let(:create_category) { get_wizard_fixture("actions/create_category") } let(:create_category) { get_wizard_fixture("actions/create_category") }
let(:watch_categories) { get_wizard_fixture("actions/watch_categories") }
let(:create_group) { get_wizard_fixture("actions/create_group") } let(:create_group) { get_wizard_fixture("actions/create_group") }
let(:add_to_group) { get_wizard_fixture("actions/add_to_group") } let(:add_to_group) { get_wizard_fixture("actions/add_to_group") }
let(:send_message) { get_wizard_fixture("actions/send_message") } let(:send_message) { get_wizard_fixture("actions/send_message") }
@ -158,17 +159,6 @@ describe CustomWizard::Action do
end end
end end
it 'watches categories' do
wizard = CustomWizard::Builder.new(@template[:id], user).build
wizard.create_updater(wizard.steps[0].id, step_1_field_1: "Text input").update
wizard.create_updater(wizard.steps[1].id, {}).update
expect(CategoryUser.where(
category_id: category.id,
user_id: user.id
).first.notification_level).to eq(0)
end
it 're-routes a user' do it 're-routes a user' do
wizard = CustomWizard::Builder.new(@template[:id], user).build wizard = CustomWizard::Builder.new(@template[:id], user).build
updater = wizard.create_updater(wizard.steps.last.id, {}) updater = wizard.create_updater(wizard.steps.last.id, {})
@ -176,11 +166,25 @@ describe CustomWizard::Action do
expect(updater.result[:redirect_on_next]).to eq("https://google.com") expect(updater.result[:redirect_on_next]).to eq("https://google.com")
end end
context "subscription actions" do context "standard subscription actions" do
before do before do
enable_subscription("standard") enable_subscription("standard")
end end
it 'watches categories' do
watch_categories[:categories][0][:output] = category.id
wizard_template[:actions] << watch_categories
update_template(wizard_template)
wizard = CustomWizard::Builder.new(@template[:id], user).build
wizard.create_updater(wizard.steps[0].id, step_1_field_1: "Text input").update
expect(CategoryUser.where(
category_id: category.id,
user_id: user.id
).first.notification_level).to eq(2)
end
it '#send_message' do it '#send_message' do
wizard_template['actions'] << send_message wizard_template['actions'] << send_message
update_template(wizard_template) update_template(wizard_template)
@ -233,9 +237,16 @@ describe CustomWizard::Action do
expect(topic.first.allowed_groups.map(&:name)).to include('cool_group', 'cool_group_1') expect(topic.first.allowed_groups.map(&:name)).to include('cool_group', 'cool_group_1')
expect(post.exists?).to eq(true) expect(post.exists?).to eq(true)
end end
end
context "business subscription actions" do
before do
enable_subscription("business")
end
it '#create_category' do it '#create_category' do
wizard_template['actions'] << create_category wizard_template['actions'] << create_category
wizard_template['actions'] << create_group
update_template(wizard_template) update_template(wizard_template)
wizard = CustomWizard::Builder.new(@template[:id], user).build wizard = CustomWizard::Builder.new(@template[:id], user).build

Datei anzeigen

@ -100,6 +100,7 @@ describe CustomWizard::Builder do
context "with restricted permissions" do context "with restricted permissions" do
before do before do
enable_subscription("standard")
@template[:permitted] = permitted_json["permitted"] @template[:permitted] = permitted_json["permitted"]
CustomWizard::Template.save(@template.as_json) CustomWizard::Template.save(@template.as_json)
end end
@ -304,7 +305,7 @@ describe CustomWizard::Builder do
before do before do
enable_subscription("standard") enable_subscription("standard")
@template[:steps][0][:fields][0][:condition] = user_condition_json['condition'] @template[:steps][0][:fields][0][:condition] = user_condition_json['condition']
@template[:steps][2][:fields][5][:condition] = boolean_field_condition_json['condition'] @template[:steps][2][:fields][0][:condition] = boolean_field_condition_json['condition']
CustomWizard::Template.save(@template.as_json) CustomWizard::Template.save(@template.as_json)
end end
@ -325,7 +326,7 @@ describe CustomWizard::Builder do
builder = CustomWizard::Builder.new(@template[:id], user) builder = CustomWizard::Builder.new(@template[:id], user)
wizard = builder.build wizard = builder.build
expect(wizard.steps.last.fields.last.id).to eq(@template[:steps][2][:fields][5]['id']) expect(wizard.steps.last.fields.last.id).to eq(@template[:steps][2][:fields][0]['id'])
end end
end end
end end

Datei anzeigen

@ -0,0 +1,104 @@
# frozen_string_literal: true
describe CustomWizard::Subscription do
def undefine_client_classes
Object.send(:remove_const, :SubscriptionClient) if Object.constants.include?(:SubscriptionClient)
Object.send(:remove_const, :SubscriptionClientSubscription) if Object.constants.include?(:SubscriptionClientSubscription)
end
def define_client_classes
load File.expand_path("#{Rails.root}/plugins/discourse-custom-wizard/spec/fixtures/subscription_client.rb", __FILE__)
end
def stub_client_methods
[:active, :where, :order, :first].each do |method|
SubscriptionClientSubscription.stubs(method)
.returns(SubscriptionClientSubscription)
end
SubscriptionClientSubscription.stubs(:product_id).returns(SecureRandom.hex(8))
end
after do
undefine_client_classes
end
it "detects the subscription client" do
expect(described_class.client_installed?).to eq(false)
end
context "without a subscription client" do
it "is not subscribed" do
expect(described_class.subscribed?).to eq(false)
end
it "has none type" do
subscription = described_class.new
expect(subscription.type).to eq(:none)
end
it "non subscriber features are included" do
expect(described_class.includes?(:wizard, :after_signup, true)).to eq(true)
end
it "ubscriber features are not included" do
expect(described_class.includes?(:wizard, :permitted, {})).to eq(false)
end
end
context "with subscription client" do
before do
define_client_classes
stub_client_methods
end
it "detects the subscription client" do
expect(described_class.client_installed?).to eq(true)
end
context "without a subscription" do
it "has none type" do
expect(described_class.type).to eq(:none)
end
it "non subscriber features are included" do
expect(described_class.includes?(:wizard, :after_signup, true)).to eq(true)
end
it "subscriber features are not included" do
expect(described_class.includes?(:wizard, :permitted, {})).to eq(false)
end
end
context "with standard subscription" do
before do
SubscriptionClientSubscription.stubs(:product_id).returns(CustomWizard::Subscription::STANDARD_PRODUCT_ID)
end
it "detects standard type" do
expect(described_class.type).to eq(:standard)
end
it "standard features are included" do
expect(described_class.includes?(:wizard, :type, 'send_message')).to eq(true)
end
it "business features are not included" do
expect(described_class.includes?(:action, :type, 'create_category')).to eq(false)
end
end
context "with business subscription" do
before do
SubscriptionClientSubscription.stubs(:product_id).returns(CustomWizard::Subscription::BUSINESS_PRODUCT_ID)
end
it "detects business type" do
expect(described_class.type).to eq(:business)
end
it "business are included" do
expect(described_class.includes?(:action, :type, 'create_category')).to eq(true)
end
end
end
end

Datei anzeigen

@ -47,6 +47,8 @@ describe CustomWizard::Template do
context "wizard template list" do context "wizard template list" do
before do before do
enable_subscription('standard')
template_json_2 = template_json.dup template_json_2 = template_json.dup
template_json_2["id"] = 'super_mega_fun_wizard_2' template_json_2["id"] = 'super_mega_fun_wizard_2'
template_json_2["permitted"] = permitted_json['permitted'] template_json_2["permitted"] = permitted_json['permitted']

Datei anzeigen

@ -5,6 +5,8 @@ describe CustomWizard::TemplateValidator do
let(:template) { get_wizard_fixture("wizard") } let(:template) { get_wizard_fixture("wizard") }
let(:create_category) { get_wizard_fixture("actions/create_category") } let(:create_category) { get_wizard_fixture("actions/create_category") }
let(:user_condition) { get_wizard_fixture("condition/user_condition") } let(:user_condition) { get_wizard_fixture("condition/user_condition") }
let(:permitted_json) { get_wizard_fixture("wizard/permitted") }
let(:composer_preview) { get_wizard_fixture("field/composer_preview") }
let(:valid_liquid_template) { let(:valid_liquid_template) {
<<-LIQUID.strip <<-LIQUID.strip
@ -104,7 +106,7 @@ describe CustomWizard::TemplateValidator do
context "without subscription" do context "without subscription" do
it "invalidates subscription wizard attributes" do it "invalidates subscription wizard attributes" do
template[:save_submissions] = false template[:permitted] = permitted_json['permitted']
expect( expect(
CustomWizard::TemplateValidator.new(template).perform CustomWizard::TemplateValidator.new(template).perform
).to eq(false) ).to eq(false)
@ -134,11 +136,11 @@ describe CustomWizard::TemplateValidator do
context "with subscription" do context "with subscription" do
before do before do
enable_subscription("standard") enable_subscription("business")
end end
it "validates wizard attributes" do it "validates wizard attributes" do
template[:save_submissions] = false template[:permitted] = permitted_json['permitted']
expect( expect(
CustomWizard::TemplateValidator.new(template).perform CustomWizard::TemplateValidator.new(template).perform
).to eq(true) ).to eq(true)
@ -227,7 +229,9 @@ describe CustomWizard::TemplateValidator do
end end
it "validates preview templates" do it "validates preview templates" do
template[:steps][0][:fields][4][:preview_template] = invalid_liquid_template enable_subscription("standard")
template[:steps][0][:fields] << composer_preview
template[:steps][0][:fields][3][:preview_template] = invalid_liquid_template
expect_validation_failure("step_1_field_5.preview_template", liquid_syntax_error) expect_validation_failure("step_1_field_5.preview_template", liquid_syntax_error)
end end
end end

Datei anzeigen

@ -3,6 +3,7 @@
describe CustomWizard::UpdateValidator do describe CustomWizard::UpdateValidator do
fab!(:user) { Fabricate(:user) } fab!(:user) { Fabricate(:user) }
let(:template) { get_wizard_fixture("wizard") } let(:template) { get_wizard_fixture("wizard") }
let(:url_field) { get_wizard_fixture("field/url") }
before do before do
CustomWizard::Template.save(template, skip_jobs: true) CustomWizard::Template.save(template, skip_jobs: true)
@ -21,7 +22,6 @@ describe CustomWizard::UpdateValidator do
@template[:steps][0][:fields][0][:min_length] = min_length @template[:steps][0][:fields][0][:min_length] = min_length
@template[:steps][0][:fields][1][:min_length] = min_length @template[:steps][0][:fields][1][:min_length] = min_length
@template[:steps][0][:fields][2][:min_length] = min_length
CustomWizard::Template.save(@template) CustomWizard::Template.save(@template)
@ -34,11 +34,6 @@ describe CustomWizard::UpdateValidator do
expect( expect(
updater.errors.messages[:step_1_field_2].first updater.errors.messages[:step_1_field_2].first
).to eq(I18n.t('wizard.field.too_short', label: 'Textarea', min: min_length)) ).to eq(I18n.t('wizard.field.too_short', label: 'Textarea', min: min_length))
updater = perform_validation('step_1', step_1_field_3: 'Te')
expect(
updater.errors.messages[:step_1_field_3].first
).to eq(I18n.t('wizard.field.too_short', label: 'Composer', min: min_length))
end end
it 'prevents submission if the length is over the max length' do it 'prevents submission if the length is over the max length' do
@ -46,7 +41,6 @@ describe CustomWizard::UpdateValidator do
@template[:steps][0][:fields][0][:max_length] = max_length @template[:steps][0][:fields][0][:max_length] = max_length
@template[:steps][0][:fields][1][:max_length] = max_length @template[:steps][0][:fields][1][:max_length] = max_length
@template[:steps][0][:fields][2][:max_length] = max_length
CustomWizard::Template.save(@template) CustomWizard::Template.save(@template)
long_string = "Our Competitive Capability solution offers platforms a suite of wholesale offerings. In the future, will you be able to effectively revolutionize synergies in your business? In the emerging market space, industry is ethically investing its mission critical executive searches. Key players will take ownership of their capabilities by iteratively right-sizing world-class visibilities. " long_string = "Our Competitive Capability solution offers platforms a suite of wholesale offerings. In the future, will you be able to effectively revolutionize synergies in your business? In the emerging market space, industry is ethically investing its mission critical executive searches. Key players will take ownership of their capabilities by iteratively right-sizing world-class visibilities. "
@ -59,11 +53,6 @@ describe CustomWizard::UpdateValidator do
expect( expect(
updater.errors.messages[:step_1_field_2].first updater.errors.messages[:step_1_field_2].first
).to eq(I18n.t('wizard.field.too_long', label: 'Textarea', max: max_length)) ).to eq(I18n.t('wizard.field.too_long', label: 'Textarea', max: max_length))
updater = perform_validation('step_1', step_1_field_3: long_string)
expect(
updater.errors.messages[:step_1_field_3].first
).to eq(I18n.t('wizard.field.too_long', label: 'Composer', max: max_length))
end end
it "allows submission if the length is under or equal to the max length" do it "allows submission if the length is under or equal to the max length" do
@ -71,7 +60,6 @@ describe CustomWizard::UpdateValidator do
@template[:steps][0][:fields][0][:max_length] = max_length @template[:steps][0][:fields][0][:max_length] = max_length
@template[:steps][0][:fields][1][:max_length] = max_length @template[:steps][0][:fields][1][:max_length] = max_length
@template[:steps][0][:fields][2][:max_length] = max_length
CustomWizard::Template.save(@template) CustomWizard::Template.save(@template)
hundred_chars_string = "This is a line, exactly hundred characters long and not more even a single character more than that." hundred_chars_string = "This is a line, exactly hundred characters long and not more even a single character more than that."
@ -84,11 +72,6 @@ describe CustomWizard::UpdateValidator do
expect( expect(
updater.errors.messages[:step_1_field_2].first updater.errors.messages[:step_1_field_2].first
).to eq(nil) ).to eq(nil)
updater = perform_validation('step_1', step_1_field_3: hundred_chars_string)
expect(
updater.errors.messages[:step_1_field_3].first
).to eq(nil)
end end
it "applies min length only if the input is non-empty" do it "applies min length only if the input is non-empty" do
@ -131,6 +114,11 @@ describe CustomWizard::UpdateValidator do
).to eq(I18n.t('wizard.field.required', label: 'Textarea')) ).to eq(I18n.t('wizard.field.required', label: 'Textarea'))
end end
context "subscription fields" do
before do
enable_subscription("standard")
end
it 'validates url fields' do it 'validates url fields' do
updater = perform_validation('step_2', step_2_field_6: 'https://discourse.com') updater = perform_validation('step_2', step_2_field_6: 'https://discourse.com')
expect( expect(
@ -139,7 +127,9 @@ describe CustomWizard::UpdateValidator do
end end
it 'does not validate url fields with non-url inputs' do it 'does not validate url fields with non-url inputs' do
updater = perform_validation('step_2', step_2_field_6: 'discourse') template[:steps][0][:fields] << url_field
CustomWizard::Template.save(template)
updater = perform_validation('step_1', step_2_field_6: 'discourse')
expect( expect(
updater.errors.messages[:step_2_field_6].first updater.errors.messages[:step_2_field_6].first
).to eq(I18n.t('wizard.field.not_url', label: 'Url')) ).to eq(I18n.t('wizard.field.not_url', label: 'Url'))
@ -151,6 +141,7 @@ describe CustomWizard::UpdateValidator do
updater.errors.messages[:step_2_field_6].first updater.errors.messages[:step_2_field_6].first
).to eq(nil) ).to eq(nil)
end end
end
it 'validates date fields' do it 'validates date fields' do
@template[:steps][1][:fields][0][:format] = "DD-MM-YYYY" @template[:steps][1][:fields][0][:format] = "DD-MM-YYYY"

Datei anzeigen

@ -113,6 +113,11 @@ describe CustomWizard::Wizard do
expect(wizard.completed?).to eq(false) expect(wizard.completed?).to eq(false)
end end
context "with subscription" do
before do
enable_subscription("standard")
end
it "permits admins" do it "permits admins" do
expect( expect(
CustomWizard::Wizard.new(@permitted_template, admin_user).permitted? CustomWizard::Wizard.new(@permitted_template, admin_user).permitted?
@ -178,6 +183,23 @@ describe CustomWizard::Wizard do
).to eq(false) ).to eq(false)
end end
it "sets wizard redirects if user is permitted" do
CustomWizard::Template.save(@permitted_template, skip_jobs: true)
CustomWizard::Wizard.set_user_redirect('super_mega_fun_wizard', trusted_user)
expect(
trusted_user.custom_fields['redirect_to_wizard']
).to eq("super_mega_fun_wizard")
end
it "does not set a wizard redirect if user is not permitted" do
CustomWizard::Template.save(@permitted_template, skip_jobs: true)
CustomWizard::Wizard.set_user_redirect('super_mega_fun_wizard', user)
expect(
trusted_user.custom_fields['redirect_to_wizard']
).to eq(nil)
end
end
it "lists the site groups" do it "lists the site groups" do
expect(@wizard.groups.length).to eq(8) expect(@wizard.groups.length).to eq(8)
end end
@ -203,6 +225,7 @@ describe CustomWizard::Wizard do
context "class methods" do context "class methods" do
before do before do
enable_subscription("standard")
CustomWizard::Template.save(@permitted_template, skip_jobs: true) CustomWizard::Template.save(@permitted_template, skip_jobs: true)
template_json_2 = template_json.dup template_json_2 = template_json.dup
@ -238,20 +261,4 @@ describe CustomWizard::Wizard do
expect(CustomWizard::Wizard.prompt_completion(user).length).to eq(1) expect(CustomWizard::Wizard.prompt_completion(user).length).to eq(1)
end end
end end
it "sets wizard redirects if user is permitted" do
CustomWizard::Template.save(@permitted_template, skip_jobs: true)
CustomWizard::Wizard.set_user_redirect('super_mega_fun_wizard', trusted_user)
expect(
trusted_user.custom_fields['redirect_to_wizard']
).to eq("super_mega_fun_wizard")
end
it "does not set a wizard redirect if user is not permitted" do
CustomWizard::Template.save(@permitted_template, skip_jobs: true)
CustomWizard::Wizard.set_user_redirect('super_mega_fun_wizard', user)
expect(
trusted_user.custom_fields['redirect_to_wizard']
).to eq(nil)
end
end end

23
spec/fixtures/actions/watch_categories.json gevendort Normale Datei
Datei anzeigen

@ -0,0 +1,23 @@
{
"id": "action_5",
"run_after": "step_1",
"type": "watch_categories",
"notification_level": "tracking",
"wizard_user": true,
"categories": [
{
"type": "assignment",
"output": "",
"output_type": "text",
"output_connector": "set"
}
],
"mute_remainder": [
{
"type": "assignment",
"output": "true",
"output_type": "text",
"output_connector": "set"
}
]
}

27
spec/fixtures/field/advanced_types.json gevendort Normale Datei
Datei anzeigen

@ -0,0 +1,27 @@
{
"fields": [
{
"id": "step_3_field_2",
"label": "Tag",
"type": "tag"
},
{
"id": "step_3_field_3",
"label": "Category",
"type": "category",
"limit": 1,
"property": "id"
},
{
"id": "step_3_field_4",
"label": "Group",
"type": "group"
},
{
"id": "step_3_field_5",
"label": "User Selector",
"description": "",
"type": "user_selector"
}
]
}

7
spec/fixtures/field/composer_preview.json gevendort Normale Datei
Datei anzeigen

@ -0,0 +1,7 @@
{
"id": "step_1_field_5",
"label": "I'm a preview",
"description": "",
"type": "composer_preview",
"preview_template": "w{step_1_field_1}"
}

5
spec/fixtures/field/url.json gevendort Normale Datei
Datei anzeigen

@ -0,0 +1,5 @@
{
"id": "step_2_field_6",
"label": "Url",
"type": "url"
}

4
spec/fixtures/subscription_client.rb gevendort Normale Datei
Datei anzeigen

@ -0,0 +1,4 @@
# frozen_string_literal: true
module SubscriptionClient; end
class SubscriptionClientSubscription; end

Datei anzeigen

@ -33,23 +33,11 @@
"type": "textarea", "type": "textarea",
"min_length": "" "min_length": ""
}, },
{
"id": "step_1_field_3",
"label": "Composer",
"type": "composer"
},
{ {
"id": "step_1_field_4", "id": "step_1_field_4",
"label": "I'm only text", "label": "I'm only text",
"description": "", "description": "",
"type": "text_only" "type": "text_only"
},
{
"id": "step_1_field_5",
"label": "I'm a preview",
"description": "",
"type": "composer_preview",
"preview_template": "w{step_1_field_1}"
} }
], ],
"description": "Text inputs!" "description": "Text inputs!"
@ -87,11 +75,6 @@
"label": "Checkbox", "label": "Checkbox",
"type": "checkbox" "type": "checkbox"
}, },
{
"id": "step_2_field_6",
"label": "Url",
"type": "url"
},
{ {
"id": "step_2_field_7", "id": "step_2_field_7",
"label": "Upload", "label": "Upload",
@ -141,35 +124,6 @@
] ]
} }
] ]
},
{
"id": "step_3_field_2",
"label": "Tag",
"type": "tag"
},
{
"id": "step_3_field_3",
"label": "Category",
"type": "category",
"limit": 1,
"property": "id"
},
{
"id": "step_3_field_4",
"label": "Group",
"type": "group"
},
{
"id": "step_3_field_5",
"label": "User Selector",
"description": "",
"type": "user_selector"
},
{
"id": "step_3_field_6",
"label": "Conditional User Selector",
"description": "Shown when checkbox in step_2_field_5 is true",
"type": "user_selector"
} }
], ],
"description": "Unfortunately not the edible type :sushi: " "description": "Unfortunately not the edible type :sushi: "
@ -264,29 +218,6 @@
} }
] ]
}, },
{
"id": "action_5",
"run_after": "step_1",
"type": "watch_categories",
"notification_level": "tracking",
"wizard_user": true,
"categories": [
{
"type": "assignment",
"output": "action_8",
"output_type": "wizard_action",
"output_connector": "set"
}
],
"mute_remainder": [
{
"type": "assignment",
"output": "true",
"output_type": "text",
"output_connector": "set"
}
]
},
{ {
"id": "action_4", "id": "action_4",
"run_after": "step_2", "run_after": "step_2",

Datei anzeigen

@ -7,3 +7,9 @@ def get_wizard_fixture(path)
).read ).read
).with_indifferent_access ).with_indifferent_access
end end
def enable_subscription(type)
CustomWizard::Subscription.stubs(:client_installed?).returns(true)
CustomWizard::Subscription.stubs("#{type}?".to_sym).returns(true)
CustomWizard::Subscription.any_instance.stubs("#{type}?".to_sym).returns(true)
end

Datei anzeigen

@ -8,6 +8,7 @@ describe CustomWizard::AdminWizardController do
before do before do
CustomWizard::Template.save(template, skip_jobs: true) CustomWizard::Template.save(template, skip_jobs: true)
enable_subscription("standard")
template_2 = template.dup template_2 = template.dup
template_2["id"] = 'super_mega_fun_wizard_2' template_2["id"] = 'super_mega_fun_wizard_2'

Datei anzeigen

@ -34,6 +34,7 @@ describe CustomWizard::StepsController do
end end
it "when the user cant access the wizard" do it "when the user cant access the wizard" do
enable_subscription("standard")
new_template = wizard_template.dup new_template = wizard_template.dup
new_template["permitted"] = permitted_json["permitted"] new_template["permitted"] = permitted_json["permitted"]
CustomWizard::Template.save(new_template, skip_jobs: true) CustomWizard::Template.save(new_template, skip_jobs: true)

Datei anzeigen

@ -40,14 +40,15 @@ describe CustomWizard::WizardController do
end end
it 'lets user skip if user cant access wizard' do it 'lets user skip if user cant access wizard' do
enable_subscription("standard")
@template["permitted"] = permitted_json["permitted"] @template["permitted"] = permitted_json["permitted"]
CustomWizard::Template.save(@template, skip_jobs: true) CustomWizard::Template.save(@template, skip_jobs: true)
put '/w/super-mega-fun-wizard/skip.json' put '/w/super-mega-fun-wizard/skip.json'
expect(response.status).to eq(200) expect(response.status).to eq(200)
end end
it 'returns a no skip message if user is not allowed to skip' do it 'returns a no skip message if user is not allowed to skip' do
enable_subscription("standard")
@template['required'] = 'true' @template['required'] = 'true'
CustomWizard::Template.save(@template) CustomWizard::Template.save(@template)
put '/w/super-mega-fun-wizard/skip.json' put '/w/super-mega-fun-wizard/skip.json'

Datei anzeigen

@ -19,7 +19,7 @@ describe CustomWizard::FieldSerializer do
expect(json_array.size).to eq(@wizard.steps.first.fields.size) expect(json_array.size).to eq(@wizard.steps.first.fields.size)
expect(json_array[0][:label]).to eq("<p>Text</p>") expect(json_array[0][:label]).to eq("<p>Text</p>")
expect(json_array[0][:description]).to eq("Text field description.") expect(json_array[0][:description]).to eq("Text field description.")
expect(json_array[3][:index]).to eq(3) expect(json_array[2][:index]).to eq(2)
end end
it "should return optional field attributes" do it "should return optional field attributes" do
@ -29,6 +29,6 @@ describe CustomWizard::FieldSerializer do
scope: Guardian.new(user) scope: Guardian.new(user)
).as_json ).as_json
expect(json_array[0][:format]).to eq("YYYY-MM-DD") expect(json_array[0][:format]).to eq("YYYY-MM-DD")
expect(json_array[6][:file_types]).to eq(".jpg,.jpeg,.png") expect(json_array[5][:file_types]).to eq(".jpg,.jpeg,.png")
end end
end end

Datei anzeigen

@ -5,6 +5,7 @@ describe CustomWizard::WizardSerializer do
fab!(:category) { Fabricate(:category) } fab!(:category) { Fabricate(:category) }
let(:template) { get_wizard_fixture("wizard") } let(:template) { get_wizard_fixture("wizard") }
let(:similar_topics_validation) { get_wizard_fixture("field/validation/similar_topics") } let(:similar_topics_validation) { get_wizard_fixture("field/validation/similar_topics") }
let(:advanced_fields) { get_wizard_fixture("field/advanced_types") }
before do before do
CustomWizard::Template.save(template, skip_jobs: true) CustomWizard::Template.save(template, skip_jobs: true)
@ -52,6 +53,13 @@ describe CustomWizard::WizardSerializer do
expect(json[:wizard][:uncategorized_category_id].present?).to eq(false) expect(json[:wizard][:uncategorized_category_id].present?).to eq(false)
end end
context "advanced fields" do
before do
enable_subscription("standard")
@template[:steps][0][:fields].push(*advanced_fields['fields'])
CustomWizard::Template.save(@template, skip_jobs: true)
end
it "should return categories if there is a category selector field" do it "should return categories if there is a category selector field" do
json = CustomWizard::WizardSerializer.new( json = CustomWizard::WizardSerializer.new(
CustomWizard::Builder.new(@template[:id], user).build, CustomWizard::Builder.new(@template[:id], user).build,
@ -82,7 +90,7 @@ describe CustomWizard::WizardSerializer do
end end
it 'should not return groups if there is not a group selector field' do it 'should not return groups if there is not a group selector field' do
@template[:steps][2][:fields].delete_at(3) @template[:steps][0][:fields].reject! { |f| f["type"] === "group" }
CustomWizard::Template.save(@template) CustomWizard::Template.save(@template)
json = CustomWizard::WizardSerializer.new( json = CustomWizard::WizardSerializer.new(
@ -92,3 +100,4 @@ describe CustomWizard::WizardSerializer do
expect(json[:wizard][:groups].present?).to eq(false) expect(json[:wizard][:groups].present?).to eq(false)
end end
end end
end