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

68 Zeilen
2,3 KiB
Ruby

2021-03-11 07:30:15 +01:00
# frozen_string_literal: true
require_relative '../../../plugin_helper'
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) }
2020-11-03 01:24:20 +01:00
let(:template) {
JSON.parse(File.open(
"#{Rails.root}/plugins/discourse-custom-wizard/spec/fixtures/wizard.json"
).read)
}
2021-03-11 07:30:15 +01:00
2020-11-03 01:24:20 +01:00
before do
CustomWizard::Template.save(template, skip_jobs: true)
2021-03-11 07:30:15 +01:00
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
2020-11-03 01:24:20 +01:00
it "removes wizard templates" do
delete "/admin/wizards/wizard/#{template['id']}.json"
expect(response.status).to eq(200)
expect(CustomWizard::Template.exists?(template['id'])).to eq(false)
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