summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNicholas Van Doorn <nick@super.gd>2021-05-17 15:40:35 -0700
committerGitHub <noreply@github.com>2021-05-17 15:40:35 -0700
commit676adfa988317ef15ee412f230e1431648774ff4 (patch)
tree582fbb6a032f5fa9f518186a9892901f13e4c9a1
parent638179c4d8f525ed5a6df5bbef00885acb8dda50 (diff)
parent2578877729a441676712f83beade318ca6dfa944 (diff)
Merge pull request #37 from Noah-Silvera/add-basic-taxjar-settings-ui
Add basic UI for Taxjar settings in solidus admin
-rw-r--r--CHANGELOG.md1
-rw-r--r--app/controllers/spree/admin/taxjar_settings_controller.rb8
-rw-r--r--app/overrides/spree/admin/shared/_configuration_menu.rb11
-rw-r--r--app/views/spree/admin/taxjar_settings/show.html.erb13
-rw-r--r--config/routes.rb7
-rw-r--r--spec/features/spree/admin/taxjar_settings_spec.rb48
-rw-r--r--spec/spec_helper.rb2
-rw-r--r--spec/super_good/solidus_taxjar/api_spec.rb6
8 files changed, 93 insertions, 3 deletions
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
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..87b97ce
--- /dev/null
+++ b/app/views/spree/admin/taxjar_settings/show.html.erb
@@ -0,0 +1,13 @@
+<%= render 'spree/admin/shared/taxes_tabs' %>
+
+<% content_for :page_title do %>
+ <%= "Taxjar Settings" %>
+<% end %>
+
+<% if ENV["TAXJAR_API_KEY"] %>
+ <table>
+ </table>
+<% else %>
+ <p>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.</p>
+ <p><i>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" %></i></p>
+<% 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..ae2e101
--- /dev/null
+++ b/spec/features/spree/admin/taxjar_settings_spec.rb
@@ -0,0 +1,48 @@
+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"
+
+ 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
+end
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.
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