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

65 Zeilen
2,7 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") }
let(:category) { Fabricate(:category, custom_fields: { create_topic_wizard: template['name'].parameterize(separator: "_") }) }
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
template_2["id"] = 'super_mega_fun_wizard_2'
template_2["permitted"] = template_2['permitted']
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
template_3["id"] = 'super_mega_fun_wizard_3'
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"
expect(
response.parsed_body['wizard_list'].map { |w| w['id'] }
).to match_array(['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))
end
2021-03-11 07:30:15 +01:00
2020-11-03 01:24:20 +01:00
it "returns a wizard template" do
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)
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
expect(CategoryCustomField.find_by(category_id: category.id, name: 'create_topic_wizard', value: template['name'].parameterize(separator: "_"))).not_to eq(nil)
2020-11-03 01:24:20 +01:00
delete "/admin/wizards/wizard/#{template['id']}.json"
expect(response.status).to eq(200)
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
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
2020-11-03 01:24:20 +01:00
put "/admin/wizards/wizard/#{template['id']}.json", params: { wizard: template_updated }
expect(response.status).to eq(200)
2021-03-11 07:30:15 +01:00
2020-11-03 01:24:20 +01: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")
end
2021-03-11 07:30:15 +01:00
end