Spiegel von
https://github.com/paviliondev/discourse-custom-wizard.git
synchronisiert 2024-11-25 10:40:28 +01:00
52 Zeilen
Kein EOL
1,6 KiB
Ruby
52 Zeilen
Kein EOL
1,6 KiB
Ruby
require 'rails_helper'
|
|
|
|
describe CustomWizard::AdminTransferController do
|
|
fab!(:admin_user) { Fabricate(:user, admin: true) }
|
|
|
|
let(:template) {
|
|
JSON.parse(File.open(
|
|
"#{Rails.root}/plugins/discourse-custom-wizard/spec/fixtures/wizard.json"
|
|
).read)
|
|
}
|
|
|
|
before do
|
|
sign_in(admin_user)
|
|
|
|
CustomWizard::Template.save(template, skip_jobs: true)
|
|
|
|
template_2 = template.dup
|
|
template_2["id"] = 'super_mega_fun_wizard_2'
|
|
CustomWizard::Template.save(template_2, skip_jobs: true)
|
|
|
|
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)
|
|
|
|
@template_array = [template, template_2, template_3]
|
|
|
|
FileUtils.mkdir_p(file_from_fixtures_tmp_folder) unless Dir.exists?(file_from_fixtures_tmp_folder)
|
|
@tmp_file_path = File.join(file_from_fixtures_tmp_folder, SecureRandom.hex << 'wizards.json')
|
|
File.write(@tmp_file_path, @template_array.to_json)
|
|
end
|
|
|
|
it 'exports all the wizard templates' do
|
|
get '/admin/wizards/transfer/export.json', params: {
|
|
wizards: [
|
|
'super_mega_fun_wizard',
|
|
'super_mega_fun_wizard_2',
|
|
'super_mega_fun_wizard_3'
|
|
]
|
|
}
|
|
expect(response.status).to eq(200)
|
|
expect(response.parsed_body).to match_array(@template_array)
|
|
end
|
|
|
|
it 'imports wizard a template' do
|
|
post '/admin/wizards/transfer/import.json', params: {
|
|
file: fixture_file_upload(File.open(@tmp_file_path))
|
|
}
|
|
expect(response.status).to eq(200)
|
|
expect(response.parsed_body['success']).to eq(@template_array.map { |t| t['id'] })
|
|
end
|
|
end |