From 4c3eda59ea91458fb5af0025ecf0f6e6708f2b4f Mon Sep 17 00:00:00 2001 From: Nicholas Van Doorn Date: Wed, 17 Feb 2021 11:23:57 -0800 Subject: Use `solidus_dev_support` feature helper We are going to be writing feature specs for new admin user interface components. Note that we can remove the line that requires `rails_helper` as `feature_helper` also includes this. Co-authored-by: Noah Silvera --- spec/spec_helper.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index ae3528d..1d5762d 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -8,7 +8,7 @@ require File.expand_path("dummy/config/environment.rb", __dir__).tap { |file| system "bin/rake extension:test_app" unless File.exist? file } -require "solidus_dev_support/rspec/rails_helper" +require "solidus_dev_support/rspec/feature_helper" # Requires supporting ruby files with custom matchers and macros, etc, # in spec/support/ and its subdirectories. -- cgit v1.2.3 From a42a41f7539f06390ac657444dc39656cbd5debc Mon Sep 17 00:00:00 2001 From: Noah Silvera Date: Mon, 22 Feb 2021 13:09:48 -0800 Subject: Don't set global environment variables in tests If you set the `ENV` variable in a test, this carries over to other tests. This was affecting different tests which relied on the environment. Co-authored-by: Nick Van Doorn --- spec/super_good/solidus_taxjar/api_spec.rb | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/spec/super_good/solidus_taxjar/api_spec.rb b/spec/super_good/solidus_taxjar/api_spec.rb index df46a11..cdfed4e 100644 --- a/spec/super_good/solidus_taxjar/api_spec.rb +++ b/spec/super_good/solidus_taxjar/api_spec.rb @@ -5,7 +5,8 @@ RSpec.describe SuperGood::SolidusTaxjar::Api do subject { described_class.new } before do - ENV["TAXJAR_API_KEY"] = 'taxjar_api_token' + allow(ENV).to receive(:fetch).and_call_original + allow(ENV).to receive(:fetch).with("TAXJAR_API_KEY").and_return("taxjar_api_token") end it "sets the correct headers" do @@ -21,7 +22,8 @@ RSpec.describe SuperGood::SolidusTaxjar::Api do subject { described_class.default_taxjar_client } before do - ENV["TAXJAR_API_KEY"] = 'taxjar_api_token' + allow(ENV).to receive(:fetch).and_call_original + allow(ENV).to receive(:fetch).with("TAXJAR_API_KEY").and_return("taxjar_api_token") end it "returns an instance of the TaxJar client" do -- cgit v1.2.3 From cb335e2577189ab8c285bf3e174d18c706c42dd2 Mon Sep 17 00:00:00 2001 From: Noah Silvera Date: Mon, 8 Feb 2021 14:45:58 -0800 Subject: Add basic UI for Taxjar settings in solidus admin This commit adds a tab to the taxes section of the solidus admin settings. This provides the foundation for further configuration of taxjar through the solidus admin. The settings should be hidden if an API key has not been provided. This is to conform to the certification guidelines for an official Taxjar extension. Co-authored-by: Nick Van Doorn --- .../spree/admin/taxjar_settings_controller.rb | 8 ++++ .../spree/admin/shared/_configuration_menu.rb | 11 ++++++ .../spree/admin/taxjar_settings/show.html.erb | 12 ++++++ config/routes.rb | 7 ++++ spec/features/spree/admin/taxjar_settings_spec.rb | 45 ++++++++++++++++++++++ 5 files changed, 83 insertions(+) create mode 100644 app/controllers/spree/admin/taxjar_settings_controller.rb create mode 100644 app/overrides/spree/admin/shared/_configuration_menu.rb create mode 100644 app/views/spree/admin/taxjar_settings/show.html.erb create mode 100644 config/routes.rb create mode 100644 spec/features/spree/admin/taxjar_settings_spec.rb diff --git a/app/controllers/spree/admin/taxjar_settings_controller.rb b/app/controllers/spree/admin/taxjar_settings_controller.rb new file mode 100644 index 0000000..a3a54b4 --- /dev/null +++ b/app/controllers/spree/admin/taxjar_settings_controller.rb @@ -0,0 +1,8 @@ +module Spree + module Admin + class TaxjarSettingsController < Spree::Admin::BaseController + def show + end + end + end +end diff --git a/app/overrides/spree/admin/shared/_configuration_menu.rb b/app/overrides/spree/admin/shared/_configuration_menu.rb new file mode 100644 index 0000000..89d9a60 --- /dev/null +++ b/app/overrides/spree/admin/shared/_configuration_menu.rb @@ -0,0 +1,11 @@ +# frozen_string_literal: true + +Deface::Override.new( + virtual_path: 'spree/admin/shared/_taxes_tabs', + name: 'add_taxjar_admin_menu_links', + insert_bottom: "[data-hook='admin_settings_taxes_tabs']" +) do + <<-HTML + <%= configurations_sidebar_menu_item "TaxJar Settings", admin_taxjar_settings_path %> + HTML +end diff --git a/app/views/spree/admin/taxjar_settings/show.html.erb b/app/views/spree/admin/taxjar_settings/show.html.erb new file mode 100644 index 0000000..c66e646 --- /dev/null +++ b/app/views/spree/admin/taxjar_settings/show.html.erb @@ -0,0 +1,12 @@ +<%= render 'spree/admin/shared/taxes_tabs' %> + +<% content_for :page_title do %> + <%= "Taxjar Settings" %> +<% end %> + +<% if ENV["TAXJAR_API_KEY"] %> + +
+<% else %> +

You must provide a TaxJar API token to configure the extension. Please see the extension readme for details.

+<% end %> diff --git a/config/routes.rb b/config/routes.rb new file mode 100644 index 0000000..36ac61d --- /dev/null +++ b/config/routes.rb @@ -0,0 +1,7 @@ +# frozen_string_literal: true + +Spree::Core::Engine.routes.draw do + namespace :admin do + resource :taxjar_settings, only: [:show] + end +end diff --git a/spec/features/spree/admin/taxjar_settings_spec.rb b/spec/features/spree/admin/taxjar_settings_spec.rb new file mode 100644 index 0000000..620b89b --- /dev/null +++ b/spec/features/spree/admin/taxjar_settings_spec.rb @@ -0,0 +1,45 @@ +require 'spec_helper' + +RSpec.feature 'Admin TaxJar Settings', js: true do + stub_authorization! + + background do + create :store, default: true + end + + describe "Taxjar settings tab" do + before do + allow(ENV).to receive(:[]).and_call_original + allow(ENV).to receive(:[]).with("TAXJAR_API_KEY").and_return(api_token) + end + + context "Taxjar API token is set" do + let(:api_token) { "token" } + + it "shows a blank settings page" do + + visit "/admin" + click_on "Settings" + expect(page).to have_content("Taxes") + click_on "Taxes" + expect(page).to have_content("TaxJar Settings") + click_on "TaxJar Settings" + expect(page).not_to have_content "You must provide a TaxJar API token" + end + end + + context "Taxjar API token isn't set" do + let(:api_token) { nil } + + it "shows a descriptive error message" do + visit "/admin" + click_on "Settings" + expect(page).to have_content("Taxes") + click_on "Taxes" + expect(page).to have_content("TaxJar Settings") + click_on "TaxJar Settings" + expect(page).to have_content "You must provide a TaxJar API token" + end + end + end +end -- cgit v1.2.3 From d565f94d316fe5297f936a49a0346ea086ac3e73 Mon Sep 17 00:00:00 2001 From: Noah Silvera Date: Mon, 22 Feb 2021 13:25:09 -0800 Subject: Provide helpful links for setting up Taxjar To comply with the certification guidelines for Taxjar, we should provide links to signup for Taxjar, and a link to a help article on aquiring a Taxjar token. --- app/views/spree/admin/taxjar_settings/show.html.erb | 3 ++- spec/features/spree/admin/taxjar_settings_spec.rb | 3 +++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/app/views/spree/admin/taxjar_settings/show.html.erb b/app/views/spree/admin/taxjar_settings/show.html.erb index c66e646..87b97ce 100644 --- a/app/views/spree/admin/taxjar_settings/show.html.erb +++ b/app/views/spree/admin/taxjar_settings/show.html.erb @@ -8,5 +8,6 @@
<% else %> -

You must provide a TaxJar API token to configure the extension. Please see the extension readme for details.

+

You must provide a TaxJar API token to use this extension. You can sign up for TaxJar <%= link_to "here", "https://app.taxjar.com/api_sign_up", target: "_blank", rel: "noreferrer" %>. Please see the extension documentation for details on providing this token to the extension.

+

For more help in aquiring a TaxJar API token, see <%= link_to "How do I get a TaxJar sales tax API token?", "https://support.taxjar.com/article/160-how-do-i-get-a-sales-tax-api-token", target: "_blank", rel: "noreferrer" %>

<% end %> diff --git a/spec/features/spree/admin/taxjar_settings_spec.rb b/spec/features/spree/admin/taxjar_settings_spec.rb index 620b89b..ae2e101 100644 --- a/spec/features/spree/admin/taxjar_settings_spec.rb +++ b/spec/features/spree/admin/taxjar_settings_spec.rb @@ -39,6 +39,9 @@ RSpec.feature 'Admin TaxJar Settings', js: true do expect(page).to have_content("TaxJar Settings") click_on "TaxJar Settings" expect(page).to have_content "You must provide a TaxJar API token" + + expect(page).to have_link(href: "https://app.taxjar.com/api_sign_up") + expect(page).to have_link(href: "https://support.taxjar.com/article/160-how-do-i-get-a-sales-tax-api-token") end end end -- cgit v1.2.3 From 2578877729a441676712f83beade318ca6dfa944 Mon Sep 17 00:00:00 2001 From: Noah Silvera Date: Mon, 22 Feb 2021 12:36:52 -0800 Subject: Update changelog to reflect PR content Add a note in the changelog describing how this PR adds a admin interface for basic taxjar settings. --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 08e4491..644b2ff 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,7 @@ - [#58](https://github.com/SuperGoodSoft/solidus_taxjar/pull/58) Take shipping promotions into account in default calculator - [#59](https://github.com/SuperGoodSoft/solidus_taxjar/pull/59) Add pry debugging tools - [#69](https://github.com/SuperGoodSoft/solidus_taxjar/pull/69) Lock ExecJS version +- [#37](https://github.com/SuperGoodSoft/solidus_taxjar/pull/37) Added a basic Taxjar settings admin interface which displays placeholder text. ## v0.18.1 -- cgit v1.2.3