0
0
Fork 1
Spiegel von https://github.com/paviliondev/discourse-custom-wizard.git synchronisiert 2024-11-25 10:40:28 +01:00
discourse-custom-wizard/spec/extensions/extra_locales_controller_spec.rb

67 Zeilen
1,9 KiB
Ruby

2021-03-11 07:30:15 +01:00
# frozen_string_literal: true
describe ExtraLocalesControllerCustomWizard, type: :request do
let(:new_user) { Fabricate(:user, trust_level: TrustLevel[0]) }
let(:staff_user) { Fabricate(:moderator) }
2021-03-11 07:30:15 +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
let(:permitted) {
JSON.parse(File.open(
"#{Rails.root}/plugins/discourse-custom-wizard/spec/fixtures/wizard/permitted.json"
).read)
}
2021-03-11 07:30:15 +01:00
before do
CustomWizard::Template.save(template, skip_jobs: true)
end
2021-03-11 07:30:15 +01:00
before do
js_hash = ExtraLocalesController.bundle_js_hash("wizard")
@locale_url = "#{Discourse.base_path}/extra-locales/wizard?v=#{js_hash}"
end
2021-03-11 07:30:15 +01:00
it "generates the correct wizard locale url" do
expect(ExtraLocalesController.url("wizard")).to eq(@locale_url)
end
2021-03-11 07:30:15 +01:00
it "returns wizard locales when requested by user in wizard" do
sign_in(new_user)
2021-03-11 07:30:15 +01:00
get @locale_url, headers: { 'REFERER' => "/w/super-mega-fun-wizard" }
expect(response.status).to eq(200)
end
2021-03-11 07:30:15 +01:00
2021-05-30 15:00:51 +02:00
it "returns wizard locales when requested by user in a wizard step" do
sign_in(new_user)
get @locale_url, headers: { 'REFERER' => "/w/super-mega-fun-wizard/steps/step_1" }
expect(response.status).to eq(200)
end
it "return wizard locales if user cant access wizard" do
template[:permitted] = permitted["permitted"]
CustomWizard::Template.save(template.as_json)
2021-03-11 07:30:15 +01:00
sign_in(new_user)
get @locale_url, headers: { 'REFERER' => "/w/super-mega-fun-wizard" }
expect(response.status).to eq(200)
end
2021-03-11 07:30:15 +01:00
it "doesnt return wizard locales to non-staff when requested outside of wizard" do
sign_in(new_user)
get @locale_url
expect(response.status).to eq(403)
end
2021-03-11 07:30:15 +01:00
it "returns wizard locales to staff when requested outside of wizard" do
sign_in(staff_user)
get @locale_url
expect(response.status).to eq(200)
end
2021-03-11 07:30:15 +01:00
end