0
0
Fork 1
Spiegel von https://github.com/paviliondev/discourse-custom-wizard.git synchronisiert 2024-11-10 04:12:53 +01:00
discourse-custom-wizard/spec/components/custom_wizard/template_validator_spec.rb

94 Zeilen
2,7 KiB
Ruby

2021-03-11 07:30:15 +01:00
# frozen_string_literal: true
require_relative '../../plugin_helper'
2020-11-03 01:24:20 +01:00
describe CustomWizard::TemplateValidator do
2020-11-03 01:24:20 +01:00
fab!(:user) { Fabricate(:user) }
2021-09-07 14:06:13 +02:00
let(:template) { get_wizard_fixture("wizard") }
let(:create_category) { get_wizard_fixture("actions/create_category") }
let(:user_condition) { get_wizard_fixture("condition/user_condition") }
2021-03-11 07:30:15 +01:00
2020-11-03 01:24:20 +01:00
it "validates valid templates" do
expect(
CustomWizard::TemplateValidator.new(template).perform
2020-11-03 01:24:20 +01:00
).to eq(true)
end
2021-03-11 07:30:15 +01:00
2020-11-03 01:24:20 +01:00
it "invalidates templates without required attributes" do
template.delete(:id)
expect(
CustomWizard::TemplateValidator.new(template).perform
2020-11-03 01:24:20 +01:00
).to eq(false)
end
2021-03-11 07:30:15 +01:00
2020-11-03 01:24:20 +01:00
it "invalidates templates with duplicate ids if creating a new template" do
CustomWizard::Template.save(template)
expect(
CustomWizard::TemplateValidator.new(template, create: true).perform
2020-11-03 01:24:20 +01:00
).to eq(false)
end
2021-03-11 07:30:15 +01:00
2020-11-03 01:24:20 +01:00
it "validates after time settings" do
2020-11-23 01:40:46 +01:00
template[:after_time] = true
template[:after_time_scheduled] = (Time.now + 3.hours).iso8601
2020-11-03 01:24:20 +01:00
expect(
CustomWizard::TemplateValidator.new(template).perform
2020-11-03 01:24:20 +01:00
).to eq(true)
end
2021-03-11 07:30:15 +01:00
2020-11-03 01:24:20 +01:00
it "invalidates invalid after time settings" do
2020-11-23 01:40:46 +01:00
template[:after_time] = true
2020-11-03 01:24:20 +01:00
template[:after_time_scheduled] = "not a time"
expect(
CustomWizard::TemplateValidator.new(template).perform
2020-11-03 01:24:20 +01:00
).to eq(false)
end
2021-09-07 14:06:13 +02:00
it "invalidates pro step attributes without a pro subscription" do
template[:steps][0][:condition] = user_condition['condition']
expect(
CustomWizard::TemplateValidator.new(template).perform
).to eq(false)
end
it "invalidates pro field attributes without a pro subscription" do
template[:steps][0][:fields][0][:condition] = user_condition['condition']
expect(
CustomWizard::TemplateValidator.new(template).perform
).to eq(false)
end
it "invalidates pro actions without a pro subscription" do
template[:actions] << create_category
expect(
CustomWizard::TemplateValidator.new(template).perform
).to eq(false)
end
context "with pro subscription" do
before do
enable_pro
end
it "validates pro step attributes" do
template[:steps][0][:condition] = user_condition['condition']
expect(
CustomWizard::TemplateValidator.new(template).perform
).to eq(true)
end
it "validates pro field attributes" do
template[:steps][0][:fields][0][:condition] = user_condition['condition']
expect(
CustomWizard::TemplateValidator.new(template).perform
).to eq(true)
end
it "validates pro actions" do
template[:actions] << create_category
expect(
CustomWizard::TemplateValidator.new(template).perform
).to eq(true)
end
end
2021-03-11 07:30:15 +01:00
end