1
0
Fork 0

Fix admin index

Dieser Commit ist enthalten in:
Angus McLeod 2023-02-24 14:17:00 +01:00
Ursprung bc81ca89aa
Commit da6e75faca
4 geänderte Dateien mit 41 neuen und 47 gelöschten Zeilen

Datei anzeigen

@ -8,7 +8,7 @@ class CustomWizard::AdminController < ::Admin::AdminController
subscribed: subcription.subscribed?, subscribed: subcription.subscribed?,
subscription_type: subcription.type, subscription_type: subcription.type,
subscription_attributes: CustomWizard::Subscription.attributes, subscription_attributes: CustomWizard::Subscription.attributes,
subscription_client_installed: subcription.client_installed? subscription_client_installed: CustomWizard::Subscription.client_installed?
) )
end end

Datei anzeigen

@ -27,6 +27,7 @@ describe CustomWizard::Subscription do
end end
it "detects the subscription client" do it "detects the subscription client" do
undefine_client_classes
expect(described_class.client_installed?).to eq(false) expect(described_class.client_installed?).to eq(false)
end end

Datei anzeigen

@ -0,0 +1,39 @@
# frozen_string_literal: true
describe CustomWizard::AdminController do
fab!(:admin_user) { Fabricate(:user, admin: true) }
it "requires an admin" do
get "/admin/wizards.json"
expect(response.status).to eq(404)
end
context "with an admin" do
before do
sign_in(admin_user)
end
context "without a subscription" do
it "returns the right subscription details" do
get "/admin/wizards.json"
expect(response.parsed_body["subscribed"]).to eq(false)
expect(response.parsed_body["subscription_attributes"]).to eq(CustomWizard::Subscription.attributes.as_json)
expect(response.parsed_body["subscription_client_installed"]).to eq(false)
end
end
context "with a subscription" do
before do
enable_subscription("standard")
load File.expand_path("#{Rails.root}/plugins/discourse-custom-wizard/spec/fixtures/subscription_client.rb", __FILE__)
end
it "returns the right subscription details" do
get "/admin/wizards.json"
expect(response.parsed_body["subscribed"]).to eq(true)
expect(response.parsed_body["subscription_type"]).to eq("standard")
expect(response.parsed_body["subscription_client_installed"]).to eq(true)
end
end
end
end

Datei anzeigen

@ -1,46 +0,0 @@
# frozen_string_literal: true
describe CustomWizard::AdminSubmissionsController do
fab!(:admin_user) { Fabricate(:user, admin: true) }
fab!(:user1) { Fabricate(:user) }
fab!(:user2) { Fabricate(:user) }
fab!(:user3) { Fabricate(:user) }
let(:template) { get_wizard_fixture("wizard") }
let(:template_2) {
temp = template.dup
temp["id"] = "super_mega_fun_wizard_2"
temp
}
before do
CustomWizard::Template.save(template, skip_jobs: true)
CustomWizard::Template.save(template_2, skip_jobs: true)
wizard1 = CustomWizard::Wizard.create(template["id"], user1)
wizard2 = CustomWizard::Wizard.create(template["id"], user2)
wizard3 = CustomWizard::Wizard.create(template_2["id"], user3)
CustomWizard::Submission.new(wizard1, step_1_field_1: "I am a user1's submission").save
CustomWizard::Submission.new(wizard2, step_1_field_1: "I am a user2's submission").save
CustomWizard::Submission.new(wizard3, step_1_field_1: "I am a user3's submission").save
sign_in(admin_user)
end
it "returns a list of wizards" do
get "/admin/wizards/submissions.json"
expect(response.parsed_body.length).to eq(2)
expect(response.parsed_body.first['id']).to eq(template['id'])
end
it "returns users' submissions for a wizard" do
get "/admin/wizards/submissions/#{template['id']}.json"
expect(response.parsed_body['submissions'].length).to eq(2)
end
it "downloads submissions" do
get "/admin/wizards/submissions/#{template_2['id']}/download"
expect(response.parsed_body.length).to eq(1)
end
end