0
0
Fork 1
Spiegel von https://github.com/paviliondev/discourse-custom-wizard.git synchronisiert 2024-11-27 11:20:28 +01:00
discourse-custom-wizard/spec/requests/custom_wizard/admin/wizard_controller_spec.rb

82 Zeilen
2,8 KiB
Ruby

2021-03-11 07:30:15 +01:00
# frozen_string_literal: true
2020-11-03 01:24:20 +01:00
describe CustomWizard::AdminWizardController do
2021-03-11 07:30:15 +01:00
fab!(:admin_user) { Fabricate(:user, admin: true) }
fab!(:user1) { Fabricate(:user) }
fab!(:user2) { Fabricate(:user) }
2021-09-07 14:06:13 +02:00
let(:template) { get_wizard_fixture("wizard") }
2024-10-16 13:52:03 +02:00
let(:category) do
Fabricate(
:category,
custom_fields: {
create_topic_wizard: template["name"].parameterize(separator: "_"),
},
)
end
2021-03-11 07:30:15 +01:00
2020-11-03 01:24:20 +01:00
before do
2022-03-25 17:08:24 +01:00
enable_subscription("standard")
CustomWizard::Template.save(template, skip_jobs: true)
2020-11-03 01:24:20 +01:00
template_2 = template.dup
2024-10-16 13:52:03 +02:00
template_2["id"] = "super_mega_fun_wizard_2"
2020-11-03 01:24:20 +01:00
CustomWizard::Template.save(template_2, skip_jobs: true)
2021-03-11 07:30:15 +01:00
2020-11-03 01:24:20 +01:00
template_3 = template.dup
2024-10-16 13:52:03 +02:00
template_3["id"] = "super_mega_fun_wizard_3"
2020-11-03 01:24:20 +01:00
template_3["after_signup"] = true
CustomWizard::Template.save(template_3, skip_jobs: true)
2021-03-11 07:30:15 +01:00
2020-11-03 01:24:20 +01:00
sign_in(admin_user)
end
it "returns a basic list of wizard templates and wizard field types" do
get "/admin/wizards/wizard.json"
2024-10-16 13:52:03 +02:00
expect(response.parsed_body["wizard_list"].map { |w| w["id"] }).to match_array(
%w[super_mega_fun_wizard super_mega_fun_wizard_2 super_mega_fun_wizard_3],
)
expect(response.parsed_body["field_types"].keys).to eq(
CustomWizard::Field.types.keys.map(&:to_s),
)
2020-11-03 01:24:20 +01:00
end
2021-03-11 07:30:15 +01:00
2020-11-03 01:24:20 +01:00
it "returns a wizard template" do
2024-10-16 13:52:03 +02:00
get "/admin/wizards/wizard/#{template["id"]}.json"
expect(response.parsed_body["id"]).to eq(template["id"])
expect(response.parsed_body["steps"].length).to eq(3)
2020-11-03 01:24:20 +01:00
end
2021-03-11 07:30:15 +01:00
2023-07-15 11:00:54 +02:00
it "removes wizard templates whilst making sure create_topic_wizard settings for that wizard are removed from Categories" do
2024-10-16 13:52:03 +02:00
expect(
CategoryCustomField.find_by(
category_id: category.id,
name: "create_topic_wizard",
value: template["name"].parameterize(separator: "_"),
),
).not_to eq(nil)
delete "/admin/wizards/wizard/#{template["id"]}.json"
2020-11-03 01:24:20 +01:00
expect(response.status).to eq(200)
2024-10-16 13:52:03 +02:00
expect(CustomWizard::Template.exists?(template["id"])).to eq(false)
expect(
CategoryCustomField.find_by(
name: "create_topic_wizard",
value: template["name"].parameterize(separator: "_"),
),
).to eq(nil)
2020-11-03 01:24:20 +01:00
end
2021-03-11 07:30:15 +01:00
2020-11-03 01:24:20 +01:00
it "saves wizard templates" do
template_updated = template.dup
2024-10-16 13:52:03 +02:00
template_updated["name"] = "Super Mega Fun Wizard 2"
template_updated["multiple_submissions"] = false
template_updated["steps"][0]["fields"][0]["label"] = "Text 2"
2021-03-11 07:30:15 +01:00
2024-10-16 13:52:03 +02:00
put "/admin/wizards/wizard/#{template["id"]}.json", params: { wizard: template_updated }
2020-11-03 01:24:20 +01:00
expect(response.status).to eq(200)
2021-03-11 07:30:15 +01:00
2024-10-16 13:52:03 +02:00
updated_template = CustomWizard::Template.find("super_mega_fun_wizard")
expect(updated_template["name"]).to eq("Super Mega Fun Wizard 2")
expect(updated_template["multiple_submissions"]).to eq("false")
expect(updated_template["steps"][0]["fields"][0]["label"]).to eq("Text 2")
2020-11-03 01:24:20 +01:00
end
2021-03-11 07:30:15 +01:00
end