Spiegel von
https://github.com/paviliondev/discourse-custom-wizard.git
synchronisiert 2024-11-22 09:20:29 +01:00
Use dynamic time in after_time tests
Dieser Commit ist enthalten in:
Ursprung
63a3115dda
Commit
80080e0cf1
6 geänderte Dateien mit 14 neuen und 43 gelöschten Zeilen
|
@ -13,11 +13,6 @@ describe CustomWizard::Template do
|
||||||
"#{Rails.root}/plugins/discourse-custom-wizard/spec/fixtures/wizard/permitted.json"
|
"#{Rails.root}/plugins/discourse-custom-wizard/spec/fixtures/wizard/permitted.json"
|
||||||
).read)
|
).read)
|
||||||
}
|
}
|
||||||
let(:after_time) {
|
|
||||||
JSON.parse(File.open(
|
|
||||||
"#{Rails.root}/plugins/discourse-custom-wizard/spec/fixtures/wizard/after_time.json"
|
|
||||||
).read).with_indifferent_access
|
|
||||||
}
|
|
||||||
|
|
||||||
before do
|
before do
|
||||||
CustomWizard::Template.save(template_json, skip_jobs: true)
|
CustomWizard::Template.save(template_json, skip_jobs: true)
|
||||||
|
@ -88,13 +83,15 @@ describe CustomWizard::Template do
|
||||||
context "after time setting" do
|
context "after time setting" do
|
||||||
before do
|
before do
|
||||||
freeze_time Time.now
|
freeze_time Time.now
|
||||||
|
@scheduled_time = (Time.now + 3.hours).iso8601
|
||||||
|
|
||||||
@after_time_template = template_json.dup
|
@after_time_template = template_json.dup
|
||||||
@after_time_template["after_time"] = after_time['after_time']
|
@after_time_template["after_time"] = true
|
||||||
@after_time_template["after_time_scheduled"] = after_time['after_time_scheduled']
|
@after_time_template["after_time_scheduled"] = @scheduled_time
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'if enabled queues jobs after wizard is saved' do
|
it 'if enabled queues jobs after wizard is saved' do
|
||||||
expect_enqueued_with(job: :set_after_time_wizard, at: Time.parse(after_time['after_time_scheduled']).utc) do
|
expect_enqueued_with(job: :set_after_time_wizard, at: Time.parse(@scheduled_time).utc) do
|
||||||
CustomWizard::Template.save(@after_time_template)
|
CustomWizard::Template.save(@after_time_template)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -9,12 +9,6 @@ describe CustomWizard::Validator do
|
||||||
).read).with_indifferent_access
|
).read).with_indifferent_access
|
||||||
}
|
}
|
||||||
|
|
||||||
let(:after_time) {
|
|
||||||
JSON.parse(File.open(
|
|
||||||
"#{Rails.root}/plugins/discourse-custom-wizard/spec/fixtures/wizard/after_time.json"
|
|
||||||
).read).with_indifferent_access
|
|
||||||
}
|
|
||||||
|
|
||||||
it "validates valid templates" do
|
it "validates valid templates" do
|
||||||
expect(
|
expect(
|
||||||
CustomWizard::Validator.new(template).perform
|
CustomWizard::Validator.new(template).perform
|
||||||
|
@ -36,15 +30,15 @@ describe CustomWizard::Validator do
|
||||||
end
|
end
|
||||||
|
|
||||||
it "validates after time settings" do
|
it "validates after time settings" do
|
||||||
template[:after_time] = after_time[:after_time]
|
template[:after_time] = true
|
||||||
template[:after_time_scheduled] = after_time[:after_time_scheduled]
|
template[:after_time_scheduled] = (Time.now + 3.hours).iso8601
|
||||||
expect(
|
expect(
|
||||||
CustomWizard::Validator.new(template).perform
|
CustomWizard::Validator.new(template).perform
|
||||||
).to eq(true)
|
).to eq(true)
|
||||||
end
|
end
|
||||||
|
|
||||||
it "invalidates invalid after time settings" do
|
it "invalidates invalid after time settings" do
|
||||||
template[:after_time] = after_time[:after_time]
|
template[:after_time] = true
|
||||||
template[:after_time_scheduled] = "not a time"
|
template[:after_time_scheduled] = "not a time"
|
||||||
expect(
|
expect(
|
||||||
CustomWizard::Validator.new(template).perform
|
CustomWizard::Validator.new(template).perform
|
||||||
|
|
|
@ -11,12 +11,6 @@ describe CustomWizard::Wizard do
|
||||||
).read)
|
).read)
|
||||||
}
|
}
|
||||||
|
|
||||||
let(:after_time) {
|
|
||||||
JSON.parse(File.open(
|
|
||||||
"#{Rails.root}/plugins/discourse-custom-wizard/spec/fixtures/wizard/after_time.json"
|
|
||||||
).read)
|
|
||||||
}
|
|
||||||
|
|
||||||
let(:permitted_json) {
|
let(:permitted_json) {
|
||||||
JSON.parse(File.open(
|
JSON.parse(File.open(
|
||||||
"#{Rails.root}/plugins/discourse-custom-wizard/spec/fixtures/wizard/permitted.json"
|
"#{Rails.root}/plugins/discourse-custom-wizard/spec/fixtures/wizard/permitted.json"
|
||||||
|
@ -84,8 +78,8 @@ describe CustomWizard::Wizard do
|
||||||
progress_step("step_2")
|
progress_step("step_2")
|
||||||
progress_step("step_3")
|
progress_step("step_3")
|
||||||
|
|
||||||
template_json['after_time'] = after_time['after_time']
|
template_json['after_time'] = true
|
||||||
template_json['after_time_scheduled'] = after_time['after_time_scheduled']
|
template_json['after_time_scheduled'] = Time.now + 3.hours
|
||||||
|
|
||||||
wizard = CustomWizard::Wizard.new(template_json, user)
|
wizard = CustomWizard::Wizard.new(template_json, user)
|
||||||
|
|
||||||
|
|
4
spec/fixtures/wizard/after_time.json
gevendort
4
spec/fixtures/wizard/after_time.json
gevendort
|
@ -1,4 +0,0 @@
|
||||||
{
|
|
||||||
"after_time": true,
|
|
||||||
"after_time_scheduled": "2020-11-20T00:59:00.000Z"
|
|
||||||
}
|
|
|
@ -12,16 +12,11 @@ describe Jobs::ClearAfterTimeWizard do
|
||||||
"#{Rails.root}/plugins/discourse-custom-wizard/spec/fixtures/wizard.json"
|
"#{Rails.root}/plugins/discourse-custom-wizard/spec/fixtures/wizard.json"
|
||||||
).read).with_indifferent_access
|
).read).with_indifferent_access
|
||||||
}
|
}
|
||||||
let(:after_time) {
|
|
||||||
JSON.parse(File.open(
|
|
||||||
"#{Rails.root}/plugins/discourse-custom-wizard/spec/fixtures/wizard/after_time.json"
|
|
||||||
).read).with_indifferent_access
|
|
||||||
}
|
|
||||||
|
|
||||||
it "clears wizard redirect for all users " do
|
it "clears wizard redirect for all users " do
|
||||||
after_time_template = template.dup
|
after_time_template = template.dup
|
||||||
after_time_template["after_time"] = after_time['after_time']
|
after_time_template["after_time"] = true
|
||||||
after_time_template["after_time_scheduled"] = after_time['after_time_scheduled']
|
after_time_template["after_time_scheduled"] = (Time.now + 3.hours).iso8601
|
||||||
|
|
||||||
CustomWizard::Template.save(after_time_template)
|
CustomWizard::Template.save(after_time_template)
|
||||||
|
|
||||||
|
|
|
@ -12,16 +12,11 @@ describe Jobs::SetAfterTimeWizard do
|
||||||
"#{Rails.root}/plugins/discourse-custom-wizard/spec/fixtures/wizard.json"
|
"#{Rails.root}/plugins/discourse-custom-wizard/spec/fixtures/wizard.json"
|
||||||
).read).with_indifferent_access
|
).read).with_indifferent_access
|
||||||
}
|
}
|
||||||
let(:after_time) {
|
|
||||||
JSON.parse(File.open(
|
|
||||||
"#{Rails.root}/plugins/discourse-custom-wizard/spec/fixtures/wizard/after_time.json"
|
|
||||||
).read).with_indifferent_access
|
|
||||||
}
|
|
||||||
|
|
||||||
it "sets wizard redirect for all users " do
|
it "sets wizard redirect for all users " do
|
||||||
after_time_template = template.dup
|
after_time_template = template.dup
|
||||||
after_time_template["after_time"] = after_time['after_time']
|
after_time_template["after_time"] = true
|
||||||
after_time_template["after_time_scheduled"] = after_time['after_time_scheduled']
|
after_time_template["after_time_scheduled"] = (Time.now + 3.hours).iso8601
|
||||||
|
|
||||||
CustomWizard::Template.save(after_time_template)
|
CustomWizard::Template.save(after_time_template)
|
||||||
|
|
||||||
|
|
Laden …
In neuem Issue referenzieren