0
0
Fork 1
Spiegel von https://github.com/paviliondev/discourse-custom-wizard.git synchronisiert 2024-11-22 01:10:28 +01:00

Ensure prompt completion works as intended

- Users who have completed should never see prompt
- Add rspec test for this case
Dieser Commit ist enthalten in:
angus 2021-02-19 17:10:59 +11:00
Ursprung 38a68c07e2
Commit 1a175b4d2b
3 geänderte Dateien mit 24 neuen und 13 gelöschten Zeilen

Datei anzeigen

@ -229,12 +229,14 @@ class CustomWizard::Wizard
end
end
def self.list(user, template_opts: {})
def self.list(user, template_opts: {}, not_completed: false)
return [] unless user
CustomWizard::Template.list(template_opts).reduce([]) do |result, template|
wizard = new(template, user)
result.push(wizard) if wizard.can_access?
result.push(wizard) if wizard.can_access? && (
!not_completed || !wizard.completed?
)
result
end
end
@ -256,9 +258,9 @@ class CustomWizard::Wizard
template_opts: {
setting: 'prompt_completion',
order: "(value::json ->> 'permitted') IS NOT NULL DESC"
}
},
not_completed: true
)
if wizards.any?
wizards.map do |w|
{

Datei anzeigen

@ -29,11 +29,11 @@ describe CustomWizard::Wizard do
end
end
def progress_step(step_id, acting_user = user)
def progress_step(step_id, acting_user: user, wizard: @wizard)
UserHistory.create(
action: UserHistory.actions[:custom_wizard_step],
acting_user_id: acting_user.id,
context: @wizard.id,
context: wizard.id,
subject: step_id
)
end
@ -117,9 +117,9 @@ describe CustomWizard::Wizard do
end
it "lets a permitted user access a complete wizard with multiple submissions" do
progress_step("step_1", trusted_user)
progress_step("step_2", trusted_user)
progress_step("step_3", trusted_user)
progress_step("step_1", acting_user: trusted_user)
progress_step("step_2", acting_user: trusted_user)
progress_step("step_3", acting_user: trusted_user)
expect(
CustomWizard::Wizard.new(@permitted_template, trusted_user).can_access?
@ -127,9 +127,9 @@ describe CustomWizard::Wizard do
end
it "does not let an unpermitted user access a complete wizard without multiple submissions" do
progress_step("step_1", trusted_user)
progress_step("step_2", trusted_user)
progress_step("step_3", trusted_user)
progress_step("step_1", acting_user: trusted_user)
progress_step("step_2", acting_user: trusted_user)
progress_step("step_3", acting_user: trusted_user)
@permitted_template['multiple_submissions'] = false
@ -189,6 +189,7 @@ describe CustomWizard::Wizard do
template_json_3 = template_json.dup
template_json_3["id"] = 'super_mega_fun_wizard_3'
template_json_3["after_signup"] = true
template_json_3["prompt_completion"] = true
CustomWizard::Template.save(template_json_3, skip_jobs: true)
end
@ -204,6 +205,14 @@ describe CustomWizard::Wizard do
it "lists prompt completion wizards" do
expect(CustomWizard::Wizard.prompt_completion(user).length).to eq(2)
end
it "prompt completion does not include wizards user has completed" do
wizard_2 = CustomWizard::Wizard.new(CustomWizard::Template.find('super_mega_fun_wizard_2'), user)
progress_step("step_1", wizard: wizard_2)
progress_step("step_2", wizard: wizard_2)
progress_step("step_3", wizard: wizard_2)
expect(CustomWizard::Wizard.prompt_completion(user).length).to eq(1)
end
end
it "sets wizard redirects if user is permitted" do

Datei anzeigen

@ -5,7 +5,7 @@
"save_submissions": true,
"multiple_submissions": true,
"after_signup": false,
"prompt_completion": true,
"prompt_completion": false,
"theme_id": 2,
"steps": [
{