2021-03-11 07:30:15 +01:00
|
|
|
# frozen_string_literal: true
|
2020-11-09 04:32:36 +01:00
|
|
|
|
|
|
|
describe CustomWizard::AdminManagerController do
|
|
|
|
fab!(:admin_user) { Fabricate(:user, admin: true) }
|
2021-09-07 14:06:13 +02:00
|
|
|
let(:template) { get_wizard_fixture("wizard") }
|
2021-03-11 07:30:15 +01:00
|
|
|
|
2020-11-09 04:32:36 +01:00
|
|
|
before do
|
2023-09-28 14:47:22 +02:00
|
|
|
define_client_classes
|
2020-11-09 04:32:36 +01:00
|
|
|
sign_in(admin_user)
|
2021-03-11 07:30:15 +01:00
|
|
|
|
2020-11-09 04:32:36 +01:00
|
|
|
template_2 = template.dup
|
|
|
|
template_2["id"] = 'super_mega_fun_wizard_2'
|
|
|
|
template_3 = template.dup
|
|
|
|
template_3["id"] = 'super_mega_fun_wizard_3'
|
|
|
|
@template_array = [template, template_2, template_3]
|
2021-03-11 07:30:15 +01:00
|
|
|
|
2023-06-06 09:15:16 +02:00
|
|
|
FileUtils.mkdir_p(concurrency_safe_tmp_dir) unless Dir.exist?(concurrency_safe_tmp_dir)
|
|
|
|
@tmp_file_path = File.join(concurrency_safe_tmp_dir, SecureRandom.hex << 'wizards.json')
|
2020-11-09 04:32:36 +01:00
|
|
|
File.write(@tmp_file_path, @template_array.to_json)
|
|
|
|
end
|
2021-03-11 07:30:15 +01:00
|
|
|
|
2020-11-09 04:32:36 +01:00
|
|
|
it 'exports all the wizard templates' do
|
|
|
|
@template_array.each do |template|
|
|
|
|
CustomWizard::Template.save(template, skip_jobs: true)
|
|
|
|
end
|
2021-03-11 07:30:15 +01:00
|
|
|
|
2020-11-09 04:32:36 +01:00
|
|
|
get '/admin/wizards/manager/export.json', params: {
|
|
|
|
wizard_ids: [
|
|
|
|
'super_mega_fun_wizard',
|
|
|
|
'super_mega_fun_wizard_2',
|
|
|
|
'super_mega_fun_wizard_3'
|
|
|
|
]
|
|
|
|
}
|
2021-03-11 07:30:15 +01:00
|
|
|
|
2020-11-09 04:32:36 +01:00
|
|
|
expect(response.status).to eq(200)
|
|
|
|
expect(response.parsed_body).to match_array(@template_array)
|
|
|
|
end
|
2021-03-11 07:30:15 +01:00
|
|
|
|
2020-11-09 04:32:36 +01:00
|
|
|
context "import" do
|
|
|
|
it "works" do
|
|
|
|
templates = @template_array.map { |t| t.slice('id', 'name') }
|
2021-03-11 07:30:15 +01:00
|
|
|
|
|
|
|
post '/admin/wizards/manager/import.json', params: {
|
|
|
|
file: fixture_file_upload(File.open(@tmp_file_path))
|
2020-11-09 04:32:36 +01:00
|
|
|
}
|
2021-03-11 07:30:15 +01:00
|
|
|
|
2020-11-09 04:32:36 +01:00
|
|
|
expect(response.status).to eq(200)
|
|
|
|
expect(response.parsed_body['imported']).to match_array(templates)
|
2021-03-11 07:30:15 +01:00
|
|
|
expect(CustomWizard::Template.list.map { |t| t.slice('id', 'name') }).to match_array(templates)
|
2020-11-09 04:32:36 +01:00
|
|
|
end
|
2021-03-11 07:30:15 +01:00
|
|
|
|
2020-11-09 04:32:36 +01:00
|
|
|
it 'rejects a template with the same id as a saved template' do
|
|
|
|
templates = @template_array.map { |t| t.slice('id', 'name') }
|
2021-03-11 07:30:15 +01:00
|
|
|
|
|
|
|
post '/admin/wizards/manager/import.json', params: {
|
|
|
|
file: fixture_file_upload(File.open(@tmp_file_path))
|
2020-11-09 04:32:36 +01:00
|
|
|
}
|
2021-03-11 07:30:15 +01:00
|
|
|
|
2020-11-09 04:32:36 +01:00
|
|
|
expect(response.status).to eq(200)
|
|
|
|
expect(response.parsed_body['imported']).to match_array(templates)
|
2021-03-11 07:30:15 +01:00
|
|
|
|
|
|
|
post '/admin/wizards/manager/import.json', params: {
|
|
|
|
file: fixture_file_upload(File.open(@tmp_file_path))
|
2020-11-09 04:32:36 +01:00
|
|
|
}
|
2021-03-11 07:30:15 +01:00
|
|
|
|
2020-11-09 04:32:36 +01:00
|
|
|
expect(response.status).to eq(200)
|
|
|
|
expect(response.parsed_body['failures']).to match_array(
|
|
|
|
@template_array.map do |t|
|
|
|
|
{
|
|
|
|
id: t['id'],
|
|
|
|
messages: I18n.t("wizard.validation.conflict", wizard_id: t['id'])
|
|
|
|
}.as_json
|
|
|
|
end
|
|
|
|
)
|
|
|
|
end
|
|
|
|
end
|
2021-03-11 07:30:15 +01:00
|
|
|
|
2020-11-09 04:32:36 +01:00
|
|
|
it 'destroys wizard templates' do
|
|
|
|
templates = @template_array.map { |t| t.slice('id', 'name') }
|
2021-03-11 07:30:15 +01:00
|
|
|
|
2020-11-09 04:32:36 +01:00
|
|
|
@template_array.each do |template|
|
|
|
|
CustomWizard::Template.save(template, skip_jobs: true)
|
|
|
|
end
|
2021-03-11 07:30:15 +01:00
|
|
|
|
2020-11-09 04:32:36 +01:00
|
|
|
delete '/admin/wizards/manager/destroy.json', params: {
|
|
|
|
wizard_ids: [
|
|
|
|
'super_mega_fun_wizard',
|
|
|
|
'super_mega_fun_wizard_2',
|
|
|
|
'super_mega_fun_wizard_3'
|
|
|
|
]
|
|
|
|
}
|
2021-03-11 07:30:15 +01:00
|
|
|
|
2020-11-09 04:32:36 +01:00
|
|
|
expect(response.status).to eq(200)
|
|
|
|
expect(response.parsed_body['destroyed']).to match_array(templates)
|
|
|
|
expect(CustomWizard::Template.list.length).to eq(0)
|
|
|
|
end
|
2021-03-11 07:30:15 +01:00
|
|
|
end
|