Spiegel von
https://github.com/paviliondev/discourse-custom-wizard.git
synchronisiert 2024-11-09 20:02:54 +01:00
Commit
908bca742f
22 geänderte Dateien mit 279 neuen und 161 gelöschten Zeilen
2
.github/workflows/discourse-plugin.yml
gevendort
2
.github/workflows/discourse-plugin.yml
gevendort
|
@ -5,6 +5,8 @@ on:
|
||||||
branches:
|
branches:
|
||||||
- main
|
- main
|
||||||
pull_request:
|
pull_request:
|
||||||
|
schedule:
|
||||||
|
- cron: "0 0 * * *"
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
ci:
|
ci:
|
||||||
|
|
20
README.md
20
README.md
|
@ -4,22 +4,24 @@ The Custom Wizard Plugin lets you make forms for your Discourse forum. Better us
|
||||||
|
|
||||||
<img src="https://camo.githubusercontent.com/593432f1fc9658ffca104065668cc88fa21dffcd3002cb78ffd50c71f33a2523/68747470733a2f2f706176696c696f6e2d6173736574732e6e7963332e63646e2e6469676974616c6f6365616e7370616365732e636f6d2f706c7567696e732f77697a6172642d7265706f7369746f72792d62616e6e65722e706e67" alt="" data-canonical-src="https://pavilion-assets.nyc3.cdn.digitaloceanspaces.com/plugins/wizard-repository-banner.png" style="max-width: 100%;" width="400">
|
<img src="https://camo.githubusercontent.com/593432f1fc9658ffca104065668cc88fa21dffcd3002cb78ffd50c71f33a2523/68747470733a2f2f706176696c696f6e2d6173736574732e6e7963332e63646e2e6469676974616c6f6365616e7370616365732e636f6d2f706c7567696e732f77697a6172642d7265706f7369746f72792d62616e6e65722e706e67" alt="" data-canonical-src="https://pavilion-assets.nyc3.cdn.digitaloceanspaces.com/plugins/wizard-repository-banner.png" style="max-width: 100%;" width="400">
|
||||||
|
|
||||||
|
👋 Looking to report an issue? We're managing issues for this plugin using our [bug report wizard](https://coop.pavilion.tech/w/bug-report).
|
||||||
|
|
||||||
## Install
|
## Install
|
||||||
|
|
||||||
If you're not sure how to install a plugin in Discourse, please follow the [plugin installation guide](https://meta.discourse.org/t/install-a-plugin/19157) or contact your Discourse hosting provider.
|
If you're not sure how to install a plugin in Discourse, please follow the [plugin installation guide](https://meta.discourse.org/t/install-a-plugin/19157) or contact your Discourse hosting provider.
|
||||||
|
|
||||||
## Documentation
|
## Documentation
|
||||||
|
|
||||||
[Read the full documentation here](https://discourse.pluginmanager.org/c/discourse-custom-wizard/documentation), or go directly to the relevant section
|
[Read the full documentation here](https://coop.pavilion.tech/c/82), or go directly to the relevant section
|
||||||
|
|
||||||
- [Wizard Administration](https://discourse.pluginmanager.org/t/wizard-administration)
|
- [Wizard Administration](https://coop.pavilion.tech/t/1602)
|
||||||
- [Wizard Settings](https://discourse.pluginmanager.org/t/wizard-settings)
|
- [Wizard Settings](https://coop.pavilion.tech/t/1614)
|
||||||
- [Step Settings](https://discourse.pluginmanager.org/t/step-settings)
|
- [Step Settings](https://coop.pavilion.tech/t/1735)
|
||||||
- [Field Settings](https://discourse.pluginmanager.org/t/field-settings)
|
- [Field Settings](https://coop.pavilion.tech/t/1580)
|
||||||
- [Conditional Settings](https://discourse.pluginmanager.org/t/conditional-settings)
|
- [Conditional Settings](https://coop.pavilion.tech/t/1673)
|
||||||
- [Field Interpolation](https://discourse.pluginmanager.org/t/field-interpolation)
|
- [Field Interpolation](https://coop.pavilion.tech/t/1557)
|
||||||
- [Wizard Examples and Templates](https://discourse.pluginmanager.org/t/wizard-examples-and-templates)
|
- [Handling Dates and Times](https://coop.pavilion.tech/t/1708)
|
||||||
|
|
||||||
## Support
|
## Support
|
||||||
|
|
||||||
- [Report a bug](https://discourse.pluginmanager.org/w/bug-report)
|
- [Report an issue](https://coop.pavilion.tech/w/bug-report)
|
||||||
|
|
|
@ -8,7 +8,7 @@ class CustomWizard::AdminController < ::Admin::AdminController
|
||||||
subscribed: subcription.subscribed?,
|
subscribed: subcription.subscribed?,
|
||||||
subscription_type: subcription.type,
|
subscription_type: subcription.type,
|
||||||
subscription_attributes: CustomWizard::Subscription.attributes,
|
subscription_attributes: CustomWizard::Subscription.attributes,
|
||||||
subscription_client_installed: subcription.client_installed?
|
subscription_client_installed: CustomWizard::Subscription.client_installed?
|
||||||
)
|
)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -69,7 +69,10 @@ export default {
|
||||||
},
|
},
|
||||||
|
|
||||||
_wizardInsertText(text, options) {
|
_wizardInsertText(text, options) {
|
||||||
if (this.session.wizardEventFieldId === this.fieldId) {
|
if (
|
||||||
|
this.session.wizardEventFieldId === this.fieldId &&
|
||||||
|
this.element
|
||||||
|
) {
|
||||||
this.insertText(text, options);
|
this.insertText(text, options);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
|
@ -35,6 +35,7 @@ function inputTypesContent(options = {}) {
|
||||||
const connectors = {
|
const connectors = {
|
||||||
pair: [
|
pair: [
|
||||||
"equal",
|
"equal",
|
||||||
|
"not_equal",
|
||||||
"greater",
|
"greater",
|
||||||
"less",
|
"less",
|
||||||
"greater_or_equal",
|
"greater_or_equal",
|
||||||
|
|
|
@ -250,6 +250,7 @@ const custom_field = {
|
||||||
|
|
||||||
export function buildFieldTypes(types) {
|
export function buildFieldTypes(types) {
|
||||||
wizardSchema.field.types = types;
|
wizardSchema.field.types = types;
|
||||||
|
wizardSchema.field.type = Object.keys(types);
|
||||||
}
|
}
|
||||||
|
|
||||||
field.type = Object.keys(field.types);
|
field.type = Object.keys(field.types);
|
||||||
|
|
|
@ -65,13 +65,16 @@
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="setting-value">
|
<div class="setting-value">
|
||||||
{{combo-box
|
{{wizard-subscription-selector
|
||||||
value=field.type
|
value=field.type
|
||||||
content=fieldTypes
|
feature="field"
|
||||||
|
attribute="type"
|
||||||
onChange=(action "changeType")
|
onChange=(action "changeType")
|
||||||
|
wizard=wizard
|
||||||
options=(hash
|
options=(hash
|
||||||
none="admin.wizard.select_type"
|
none="admin.wizard.select_type"
|
||||||
)}}
|
)
|
||||||
|
}}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|
|
@ -117,6 +117,7 @@
|
||||||
{{wizard-custom-field
|
{{wizard-custom-field
|
||||||
field=field
|
field=field
|
||||||
step=step
|
step=step
|
||||||
|
wizard=wizard
|
||||||
currentFieldId=currentField.id
|
currentFieldId=currentField.id
|
||||||
fieldTypes=fieldTypes
|
fieldTypes=fieldTypes
|
||||||
removeField="removeField"
|
removeField="removeField"
|
||||||
|
|
|
@ -324,6 +324,7 @@ en:
|
||||||
then: "then"
|
then: "then"
|
||||||
set: "set"
|
set: "set"
|
||||||
equal: '='
|
equal: '='
|
||||||
|
not_equal: '!='
|
||||||
greater: '>'
|
greater: '>'
|
||||||
less: '<'
|
less: '<'
|
||||||
greater_or_equal: '>='
|
greater_or_equal: '>='
|
||||||
|
|
|
@ -65,18 +65,18 @@ class CustomWizard::Api::LogEntry
|
||||||
data = ::JSON.parse(record['value'])
|
data = ::JSON.parse(record['value'])
|
||||||
data[:log_id] = record['key'].split('_').last
|
data[:log_id] = record['key'].split('_').last
|
||||||
this_user = User.find_by(id: data['user_id'])
|
this_user = User.find_by(id: data['user_id'])
|
||||||
unless this_user.nil?
|
if this_user.nil?
|
||||||
data[:user_id] = this_user.id || nil
|
|
||||||
data[:username] = this_user.username || ""
|
|
||||||
data[:userpath] = "/u/#{this_user.username_lower}/activity"
|
|
||||||
data[:name] = this_user.name || ""
|
|
||||||
data[:avatar_template] = "/user_avatar/default/#{this_user.username_lower}/97/#{this_user.uploaded_avatar_id}.png"
|
|
||||||
else
|
|
||||||
data[:user_id] = nil
|
data[:user_id] = nil
|
||||||
data[:username] = ""
|
data[:username] = ""
|
||||||
data[:userpath] = ""
|
data[:userpath] = ""
|
||||||
data[:name] = ""
|
data[:name] = ""
|
||||||
data[:avatar_template] = ""
|
data[:avatar_template] = ""
|
||||||
|
else
|
||||||
|
data[:user_id] = this_user.id || nil
|
||||||
|
data[:username] = this_user.username || ""
|
||||||
|
data[:userpath] = "/u/#{this_user.username_lower}/activity"
|
||||||
|
data[:name] = this_user.name || ""
|
||||||
|
data[:avatar_template] = "/user_avatar/default/#{this_user.username_lower}/97/#{this_user.uploaded_avatar_id}.png"
|
||||||
end
|
end
|
||||||
self.new(api_name, data)
|
self.new(api_name, data)
|
||||||
end
|
end
|
||||||
|
|
|
@ -15,13 +15,13 @@ class CustomWizard::Log
|
||||||
@username = attrs['username']
|
@username = attrs['username']
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.create(wizard_id, action, username, message)
|
def self.create(wizard_id, action, username, message, date = Time.now)
|
||||||
log_id = SecureRandom.hex(12)
|
log_id = SecureRandom.hex(12)
|
||||||
|
|
||||||
PluginStore.set('custom_wizard_log',
|
PluginStore.set('custom_wizard_log',
|
||||||
log_id.to_s,
|
log_id.to_s,
|
||||||
{
|
{
|
||||||
date: Time.now,
|
date: date,
|
||||||
wizard_id: wizard_id,
|
wizard_id: wizard_id,
|
||||||
action: action,
|
action: action,
|
||||||
username: username,
|
username: username,
|
||||||
|
|
|
@ -30,6 +30,7 @@ class CustomWizard::Mapper
|
||||||
|
|
||||||
OPERATORS = {
|
OPERATORS = {
|
||||||
equal: '==',
|
equal: '==',
|
||||||
|
not_equal: "!=",
|
||||||
greater: '>',
|
greater: '>',
|
||||||
less: '<',
|
less: '<',
|
||||||
greater_or_equal: '>=',
|
greater_or_equal: '>=',
|
||||||
|
|
|
@ -1,8 +1,10 @@
|
||||||
# frozen_string_literal: true
|
# frozen_string_literal: true
|
||||||
class CustomWizard::Subscription
|
class CustomWizard::Subscription
|
||||||
STANDARD_PRODUCT_ID = 'prod_MH11woVoZU5AWb'
|
PRODUCT_HIERARCHY = %w[
|
||||||
BUSINESS_PRODUCT_ID = 'prod_MH0wT627okh3Ef'
|
community
|
||||||
COMMUNITY_PRODUCT_ID = 'prod_MU7l9EjxhaukZ7'
|
standard
|
||||||
|
business
|
||||||
|
]
|
||||||
|
|
||||||
def self.attributes
|
def self.attributes
|
||||||
{
|
{
|
||||||
|
@ -99,8 +101,29 @@ class CustomWizard::Subscription
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
|
||||||
|
attr_accessor :product_id,
|
||||||
|
:product_slug
|
||||||
|
|
||||||
def initialize
|
def initialize
|
||||||
@subscription = find_subscription
|
if CustomWizard::Subscription.client_installed?
|
||||||
|
result = SubscriptionClient.find_subscriptions("discourse-custom-wizard")
|
||||||
|
|
||||||
|
if result&.any?
|
||||||
|
ids_and_slugs = result.subscriptions.map do |subscription|
|
||||||
|
{
|
||||||
|
id: subscription.product_id,
|
||||||
|
slug: result.products[subscription.product_id]
|
||||||
|
}
|
||||||
|
end
|
||||||
|
|
||||||
|
id_and_slug = ids_and_slugs.sort do |a, b|
|
||||||
|
PRODUCT_HIERARCHY.index(b[:slug]) - PRODUCT_HIERARCHY.index(a[:slug])
|
||||||
|
end.first
|
||||||
|
|
||||||
|
@product_id = id_and_slug[:id]
|
||||||
|
@product_slug = id_and_slug[:slug]
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def includes?(feature, attribute, value = nil)
|
def includes?(feature, attribute, value = nil)
|
||||||
|
@ -140,38 +163,21 @@ class CustomWizard::Subscription
|
||||||
end
|
end
|
||||||
|
|
||||||
def standard?
|
def standard?
|
||||||
@subscription.product_id === STANDARD_PRODUCT_ID
|
product_slug === "standard"
|
||||||
end
|
end
|
||||||
|
|
||||||
def business?
|
def business?
|
||||||
@subscription.product_id === BUSINESS_PRODUCT_ID
|
product_slug === "business"
|
||||||
end
|
end
|
||||||
|
|
||||||
def community?
|
def community?
|
||||||
@subscription.product_id === COMMUNITY_PRODUCT_ID
|
product_slug === "community"
|
||||||
end
|
end
|
||||||
|
|
||||||
def client_installed?
|
def self.client_installed?
|
||||||
defined?(SubscriptionClient) == 'constant' && SubscriptionClient.class == Module
|
defined?(SubscriptionClient) == 'constant' && SubscriptionClient.class == Module
|
||||||
end
|
end
|
||||||
|
|
||||||
def find_subscription
|
|
||||||
subscription = nil
|
|
||||||
|
|
||||||
if client_installed?
|
|
||||||
subscription = SubscriptionClientSubscription.active
|
|
||||||
.where(product_id: [STANDARD_PRODUCT_ID, BUSINESS_PRODUCT_ID, COMMUNITY_PRODUCT_ID])
|
|
||||||
.order("product_id = '#{BUSINESS_PRODUCT_ID}' DESC")
|
|
||||||
.first
|
|
||||||
end
|
|
||||||
|
|
||||||
unless subscription
|
|
||||||
subscription = OpenStruct.new(product_id: nil)
|
|
||||||
end
|
|
||||||
|
|
||||||
subscription
|
|
||||||
end
|
|
||||||
|
|
||||||
def self.subscribed?
|
def self.subscribed?
|
||||||
new.subscribed?
|
new.subscribed?
|
||||||
end
|
end
|
||||||
|
@ -192,10 +198,6 @@ class CustomWizard::Subscription
|
||||||
new.type
|
new.type
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.client_installed?
|
|
||||||
new.client_installed?
|
|
||||||
end
|
|
||||||
|
|
||||||
def self.includes?(feature, attribute, value)
|
def self.includes?(feature, attribute, value)
|
||||||
new.includes?(feature, attribute, value)
|
new.includes?(feature, attribute, value)
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
# frozen_string_literal: true
|
# frozen_string_literal: true
|
||||||
# name: discourse-custom-wizard
|
# name: discourse-custom-wizard
|
||||||
# about: Forms for Discourse. Better onboarding, structured posting, data enrichment, automated actions and much more.
|
# about: Forms for Discourse. Better onboarding, structured posting, data enrichment, automated actions and much more.
|
||||||
# version: 2.3.1
|
# version: 2.4.2
|
||||||
# authors: Angus McLeod, Faizaan Gagan, Robert Barrow, Keegan George, Kaitlin Maddever
|
# authors: Angus McLeod, Faizaan Gagan, Robert Barrow, Keegan George, Kaitlin Maddever
|
||||||
# url: https://github.com/paviliondev/discourse-custom-wizard
|
# url: https://github.com/paviliondev/discourse-custom-wizard
|
||||||
# contact_emails: development@pavilion.tech
|
# contact_emails: development@pavilion.tech
|
||||||
|
|
|
@ -291,6 +291,19 @@ describe CustomWizard::Mapper do
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
it "handles not equal pairs" do
|
||||||
|
expect(CustomWizard::Mapper.new(
|
||||||
|
inputs: inputs['not_equals_pair'],
|
||||||
|
data: data,
|
||||||
|
user: user1
|
||||||
|
).perform).to eq(true)
|
||||||
|
expect(CustomWizard::Mapper.new(
|
||||||
|
inputs: inputs['not_equals_pair'],
|
||||||
|
data: data,
|
||||||
|
user: user2
|
||||||
|
).perform).to eq(false)
|
||||||
|
end
|
||||||
|
|
||||||
it "handles greater than pairs" do
|
it "handles greater than pairs" do
|
||||||
expect(CustomWizard::Mapper.new(
|
expect(CustomWizard::Mapper.new(
|
||||||
inputs: inputs['greater_than_pair'],
|
inputs: inputs['greater_than_pair'],
|
||||||
|
|
|
@ -2,29 +2,23 @@
|
||||||
|
|
||||||
describe CustomWizard::Subscription do
|
describe CustomWizard::Subscription do
|
||||||
let(:guests_permitted) { get_wizard_fixture("wizard/guests_permitted") }
|
let(:guests_permitted) { get_wizard_fixture("wizard/guests_permitted") }
|
||||||
|
let!(:business_product_id) { SecureRandom.hex(8) }
|
||||||
def undefine_client_classes
|
let!(:standard_product_id) { SecureRandom.hex(8) }
|
||||||
Object.send(:remove_const, :SubscriptionClient) if Object.constants.include?(:SubscriptionClient)
|
let!(:community_product_id) { SecureRandom.hex(8) }
|
||||||
Object.send(:remove_const, :SubscriptionClientSubscription) if Object.constants.include?(:SubscriptionClientSubscription)
|
let!(:product_slugs) {
|
||||||
end
|
{
|
||||||
|
"#{business_product_id}" => "business",
|
||||||
def define_client_classes
|
"#{standard_product_id}" => "standard",
|
||||||
load File.expand_path("#{Rails.root}/plugins/discourse-custom-wizard/spec/fixtures/subscription_client.rb", __FILE__)
|
"#{community_product_id}" => "community"
|
||||||
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
|
after do
|
||||||
undefine_client_classes
|
undefine_client_classes
|
||||||
end
|
end
|
||||||
|
|
||||||
it "detects the subscription client" do
|
it "detects the subscription client" do
|
||||||
|
undefine_client_classes
|
||||||
expect(described_class.client_installed?).to eq(false)
|
expect(described_class.client_installed?).to eq(false)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -50,7 +44,6 @@ describe CustomWizard::Subscription do
|
||||||
context "with subscription client" do
|
context "with subscription client" do
|
||||||
before do
|
before do
|
||||||
define_client_classes
|
define_client_classes
|
||||||
stub_client_methods
|
|
||||||
end
|
end
|
||||||
|
|
||||||
it "detects the subscription client" do
|
it "detects the subscription client" do
|
||||||
|
@ -58,6 +51,10 @@ describe CustomWizard::Subscription do
|
||||||
end
|
end
|
||||||
|
|
||||||
context "without a subscription" do
|
context "without a subscription" do
|
||||||
|
before do
|
||||||
|
SubscriptionClient.stubs(:find_subscriptions).returns(nil)
|
||||||
|
end
|
||||||
|
|
||||||
it "has none type" do
|
it "has none type" do
|
||||||
expect(described_class.type).to eq(:none)
|
expect(described_class.type).to eq(:none)
|
||||||
end
|
end
|
||||||
|
@ -71,19 +68,31 @@ describe CustomWizard::Subscription do
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
context "with a subscription" do
|
context "with subscriptions" do
|
||||||
|
def get_subscription_result(product_ids)
|
||||||
|
result = SubscriptionClient::Subscriptions::Result.new
|
||||||
|
result.supplier = SubscriptionClientSupplier.new(product_slugs)
|
||||||
|
result.resource = SubscriptionClientResource.new
|
||||||
|
result.subscriptions = product_ids.map { |product_id| SubscriptionClientSubscription.new(product_id) }
|
||||||
|
result.products = product_slugs
|
||||||
|
result
|
||||||
|
end
|
||||||
|
let!(:business_subscription_result) { get_subscription_result([business_product_id]) }
|
||||||
|
let!(:standard_subscription_result) { get_subscription_result([standard_product_id]) }
|
||||||
|
let!(:community_subscription_result) { get_subscription_result([community_product_id]) }
|
||||||
|
let!(:multiple_subscription_result) { get_subscription_result([community_product_id, business_product_id]) }
|
||||||
|
|
||||||
it "handles mapped values" do
|
it "handles mapped values" do
|
||||||
SubscriptionClientSubscription.stubs(:product_id).returns(CustomWizard::Subscription::STANDARD_PRODUCT_ID)
|
SubscriptionClient.stubs(:find_subscriptions).returns(standard_subscription_result)
|
||||||
expect(described_class.includes?(:wizard, :permitted, guests_permitted["permitted"])).to eq(true)
|
expect(described_class.includes?(:wizard, :permitted, guests_permitted["permitted"])).to eq(true)
|
||||||
|
|
||||||
SubscriptionClientSubscription.stubs(:product_id).returns(CustomWizard::Subscription::COMMUNITY_PRODUCT_ID)
|
SubscriptionClient.stubs(:find_subscriptions).returns(community_subscription_result)
|
||||||
expect(described_class.includes?(:wizard, :permitted, guests_permitted["permitted"])).to eq(false)
|
expect(described_class.includes?(:wizard, :permitted, guests_permitted["permitted"])).to eq(false)
|
||||||
end
|
end
|
||||||
end
|
|
||||||
|
|
||||||
context "with standard subscription" do
|
context "with a standard subscription" do
|
||||||
before do
|
before do
|
||||||
SubscriptionClientSubscription.stubs(:product_id).returns(CustomWizard::Subscription::STANDARD_PRODUCT_ID)
|
SubscriptionClient.stubs(:find_subscriptions).returns(standard_subscription_result)
|
||||||
end
|
end
|
||||||
|
|
||||||
it "detects standard type" do
|
it "detects standard type" do
|
||||||
|
@ -99,9 +108,9 @@ describe CustomWizard::Subscription do
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
context "with business subscription" do
|
context "with a business subscription" do
|
||||||
before do
|
before do
|
||||||
SubscriptionClientSubscription.stubs(:product_id).returns(CustomWizard::Subscription::BUSINESS_PRODUCT_ID)
|
SubscriptionClient.stubs(:find_subscriptions).returns(business_subscription_result)
|
||||||
end
|
end
|
||||||
|
|
||||||
it "detects business type" do
|
it "detects business type" do
|
||||||
|
@ -113,9 +122,9 @@ describe CustomWizard::Subscription do
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
context "with community subscription" do
|
context "with a community subscription" do
|
||||||
before do
|
before do
|
||||||
SubscriptionClientSubscription.stubs(:product_id).returns(CustomWizard::Subscription::COMMUNITY_PRODUCT_ID)
|
SubscriptionClient.stubs(:find_subscriptions).returns(community_subscription_result)
|
||||||
end
|
end
|
||||||
|
|
||||||
it "detects community type" do
|
it "detects community type" do
|
||||||
|
@ -126,5 +135,16 @@ describe CustomWizard::Subscription do
|
||||||
expect(described_class.includes?(:action, :type, 'create_category')).to eq(true)
|
expect(described_class.includes?(:action, :type, 'create_category')).to eq(true)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
context "with multiple subscriptions" do
|
||||||
|
before do
|
||||||
|
SubscriptionClient.stubs(:find_subscriptions).returns(multiple_subscription_result)
|
||||||
|
end
|
||||||
|
|
||||||
|
it "detects correct type in hierarchy" do
|
||||||
|
expect(described_class.type).to eq(:business)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
15
spec/fixtures/mapper/inputs.json
gevendort
15
spec/fixtures/mapper/inputs.json
gevendort
|
@ -195,6 +195,21 @@
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
|
"not_equals_pair": [
|
||||||
|
{
|
||||||
|
"type": "validation",
|
||||||
|
"pairs": [
|
||||||
|
{
|
||||||
|
"index": 0,
|
||||||
|
"key": "trust_level",
|
||||||
|
"key_type": "user_field",
|
||||||
|
"value": "1",
|
||||||
|
"value_type": "text",
|
||||||
|
"connector": "not_equal"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
],
|
||||||
"greater_than_pair": [
|
"greater_than_pair": [
|
||||||
{
|
{
|
||||||
"type": "validation",
|
"type": "validation",
|
||||||
|
|
40
spec/fixtures/subscription_client.rb
gevendort
40
spec/fixtures/subscription_client.rb
gevendort
|
@ -1,4 +1,40 @@
|
||||||
# frozen_string_literal: true
|
# frozen_string_literal: true
|
||||||
|
|
||||||
module SubscriptionClient; end
|
module SubscriptionClient
|
||||||
class SubscriptionClientSubscription; end
|
def self.find_subscriptions(resource_name)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
class SubscriptionClientSupplier
|
||||||
|
attr_reader :product_slugs
|
||||||
|
|
||||||
|
def initialize(product_slugs)
|
||||||
|
@product_slugs = product_slugs
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
class SubscriptionClientResource
|
||||||
|
end
|
||||||
|
|
||||||
|
class SubscriptionClientSubscription
|
||||||
|
attr_reader :product_id
|
||||||
|
|
||||||
|
def initialize(product_id)
|
||||||
|
@product_id = product_id
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
module SubscriptionClient
|
||||||
|
class Subscriptions
|
||||||
|
class Result
|
||||||
|
attr_accessor :supplier,
|
||||||
|
:resource,
|
||||||
|
:subscriptions,
|
||||||
|
:products
|
||||||
|
|
||||||
|
def any?
|
||||||
|
supplier.present? && resource.present? && subscriptions.present? && products.present?
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
|
@ -9,7 +9,26 @@ def get_wizard_fixture(path)
|
||||||
end
|
end
|
||||||
|
|
||||||
def enable_subscription(type)
|
def enable_subscription(type)
|
||||||
CustomWizard::Subscription.stubs(:client_installed?).returns(true)
|
|
||||||
CustomWizard::Subscription.stubs("#{type}?".to_sym).returns(true)
|
CustomWizard::Subscription.stubs("#{type}?".to_sym).returns(true)
|
||||||
CustomWizard::Subscription.any_instance.stubs("#{type}?".to_sym).returns(true)
|
CustomWizard::Subscription.any_instance.stubs("#{type}?".to_sym).returns(true)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def disable_subscriptions
|
||||||
|
%w[
|
||||||
|
standard
|
||||||
|
business
|
||||||
|
community
|
||||||
|
].each do |type|
|
||||||
|
CustomWizard::Subscription.stubs("#{type}?".to_sym).returns(false)
|
||||||
|
CustomWizard::Subscription.any_instance.stubs("#{type}?".to_sym).returns(false)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
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
|
||||||
|
|
44
spec/requests/custom_wizard/admin/admin_controller_spec.rb
Normale Datei
44
spec/requests/custom_wizard/admin/admin_controller_spec.rb
Normale Datei
|
@ -0,0 +1,44 @@
|
||||||
|
# frozen_string_literal: true
|
||||||
|
|
||||||
|
describe CustomWizard::AdminController do
|
||||||
|
fab!(:admin_user) { Fabricate(:user, admin: true) }
|
||||||
|
|
||||||
|
it "requires an admin" do
|
||||||
|
get "/admin/wizards.json"
|
||||||
|
expect(response.status).to eq(404)
|
||||||
|
end
|
||||||
|
|
||||||
|
context "with an admin" do
|
||||||
|
before do
|
||||||
|
sign_in(admin_user)
|
||||||
|
end
|
||||||
|
|
||||||
|
context "without a subscription" do
|
||||||
|
before do
|
||||||
|
disable_subscriptions
|
||||||
|
define_client_classes
|
||||||
|
end
|
||||||
|
|
||||||
|
it "returns the right subscription details" do
|
||||||
|
get "/admin/wizards.json"
|
||||||
|
expect(response.parsed_body["subscribed"]).to eq(false)
|
||||||
|
expect(response.parsed_body["subscription_attributes"]).to eq(CustomWizard::Subscription.attributes.as_json)
|
||||||
|
expect(response.parsed_body["subscription_client_installed"]).to eq(true)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
context "with a subscription" do
|
||||||
|
before do
|
||||||
|
enable_subscription("standard")
|
||||||
|
define_client_classes
|
||||||
|
end
|
||||||
|
|
||||||
|
it "returns the right subscription details" do
|
||||||
|
get "/admin/wizards.json"
|
||||||
|
expect(response.parsed_body["subscribed"]).to eq(true)
|
||||||
|
expect(response.parsed_body["subscription_type"]).to eq("standard")
|
||||||
|
expect(response.parsed_body["subscription_client_installed"]).to eq(true)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
|
@ -1,46 +0,0 @@
|
||||||
# frozen_string_literal: true
|
|
||||||
|
|
||||||
describe CustomWizard::AdminSubmissionsController do
|
|
||||||
fab!(:admin_user) { Fabricate(:user, admin: true) }
|
|
||||||
fab!(:user1) { Fabricate(:user) }
|
|
||||||
fab!(:user2) { Fabricate(:user) }
|
|
||||||
fab!(:user3) { Fabricate(:user) }
|
|
||||||
|
|
||||||
let(:template) { get_wizard_fixture("wizard") }
|
|
||||||
let(:template_2) {
|
|
||||||
temp = template.dup
|
|
||||||
temp["id"] = "super_mega_fun_wizard_2"
|
|
||||||
temp
|
|
||||||
}
|
|
||||||
|
|
||||||
before do
|
|
||||||
CustomWizard::Template.save(template, skip_jobs: true)
|
|
||||||
CustomWizard::Template.save(template_2, skip_jobs: true)
|
|
||||||
|
|
||||||
wizard1 = CustomWizard::Wizard.create(template["id"], user1)
|
|
||||||
wizard2 = CustomWizard::Wizard.create(template["id"], user2)
|
|
||||||
wizard3 = CustomWizard::Wizard.create(template_2["id"], user3)
|
|
||||||
|
|
||||||
CustomWizard::Submission.new(wizard1, step_1_field_1: "I am a user1's submission").save
|
|
||||||
CustomWizard::Submission.new(wizard2, step_1_field_1: "I am a user2's submission").save
|
|
||||||
CustomWizard::Submission.new(wizard3, step_1_field_1: "I am a user3's submission").save
|
|
||||||
|
|
||||||
sign_in(admin_user)
|
|
||||||
end
|
|
||||||
|
|
||||||
it "returns a list of wizards" do
|
|
||||||
get "/admin/wizards/submissions.json"
|
|
||||||
expect(response.parsed_body.length).to eq(2)
|
|
||||||
expect(response.parsed_body.first['id']).to eq(template['id'])
|
|
||||||
end
|
|
||||||
|
|
||||||
it "returns users' submissions for a wizard" do
|
|
||||||
get "/admin/wizards/submissions/#{template['id']}.json"
|
|
||||||
expect(response.parsed_body['submissions'].length).to eq(2)
|
|
||||||
end
|
|
||||||
|
|
||||||
it "downloads submissions" do
|
|
||||||
get "/admin/wizards/submissions/#{template_2['id']}/download"
|
|
||||||
expect(response.parsed_body.length).to eq(1)
|
|
||||||
end
|
|
||||||
end
|
|
|
@ -4,7 +4,7 @@ describe CustomWizard::LogSerializer do
|
||||||
fab!(:user) { Fabricate(:user) }
|
fab!(:user) { Fabricate(:user) }
|
||||||
|
|
||||||
it 'should return log attributes' do
|
it 'should return log attributes' do
|
||||||
CustomWizard::Log.create('first-test-wizard', 'perform_first_action', 'first_test_user', 'First log message')
|
CustomWizard::Log.create('first-test-wizard', 'perform_first_action', 'first_test_user', 'First log message', 1.day.ago)
|
||||||
CustomWizard::Log.create('second-test-wizard', 'perform_second_action', 'second_test_user', 'Second log message')
|
CustomWizard::Log.create('second-test-wizard', 'perform_second_action', 'second_test_user', 'Second log message')
|
||||||
|
|
||||||
json_array = ActiveModel::ArraySerializer.new(
|
json_array = ActiveModel::ArraySerializer.new(
|
||||||
|
|
Laden …
In neuem Issue referenzieren