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

47 Zeilen
1,3 KiB
Ruby

2020-11-03 01:24:20 +01:00
require 'rails_helper'
describe CustomWizard::TemplateValidator do
2020-11-03 01:24:20 +01:00
fab!(:user) { Fabricate(:user) }
let(:template) {
JSON.parse(File.open(
"#{Rails.root}/plugins/discourse-custom-wizard/spec/fixtures/wizard.json"
).read).with_indifferent_access
}
it "validates valid templates" do
expect(
CustomWizard::TemplateValidator.new(template).perform
2020-11-03 01:24:20 +01:00
).to eq(true)
end
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
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
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
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
end