From da6e75faca1d50929f42f941beb297b7aff11843 Mon Sep 17 00:00:00 2001 From: Angus McLeod Date: Fri, 24 Feb 2023 14:17:00 +0100 Subject: [PATCH] Fix admin index --- app/controllers/custom_wizard/admin/admin.rb | 2 +- .../custom_wizard/subscription_spec.rb | 1 + .../admin/admin_controller_spec.rb | 39 ++++++++++++++++ .../admin/submissions_controller_spec.rb | 46 ------------------- 4 files changed, 41 insertions(+), 47 deletions(-) create mode 100644 spec/requests/custom_wizard/admin/admin_controller_spec.rb delete mode 100644 spec/requests/custom_wizard/admin/submissions_controller_spec.rb diff --git a/app/controllers/custom_wizard/admin/admin.rb b/app/controllers/custom_wizard/admin/admin.rb index 867be56c..aa8862b6 100644 --- a/app/controllers/custom_wizard/admin/admin.rb +++ b/app/controllers/custom_wizard/admin/admin.rb @@ -8,7 +8,7 @@ class CustomWizard::AdminController < ::Admin::AdminController subscribed: subcription.subscribed?, subscription_type: subcription.type, subscription_attributes: CustomWizard::Subscription.attributes, - subscription_client_installed: subcription.client_installed? + subscription_client_installed: CustomWizard::Subscription.client_installed? ) end diff --git a/spec/components/custom_wizard/subscription_spec.rb b/spec/components/custom_wizard/subscription_spec.rb index 2e29d641..461c97c9 100644 --- a/spec/components/custom_wizard/subscription_spec.rb +++ b/spec/components/custom_wizard/subscription_spec.rb @@ -27,6 +27,7 @@ describe CustomWizard::Subscription do end it "detects the subscription client" do + undefine_client_classes expect(described_class.client_installed?).to eq(false) end diff --git a/spec/requests/custom_wizard/admin/admin_controller_spec.rb b/spec/requests/custom_wizard/admin/admin_controller_spec.rb new file mode 100644 index 00000000..6a7d721c --- /dev/null +++ b/spec/requests/custom_wizard/admin/admin_controller_spec.rb @@ -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 diff --git a/spec/requests/custom_wizard/admin/submissions_controller_spec.rb b/spec/requests/custom_wizard/admin/submissions_controller_spec.rb deleted file mode 100644 index 3c740c85..00000000 --- a/spec/requests/custom_wizard/admin/submissions_controller_spec.rb +++ /dev/null @@ -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