From 8722de9394f3f70d6d763306bd87eef5f8cc19ea Mon Sep 17 00:00:00 2001 From: Elia Schito Date: Thu, 10 Nov 2022 16:20:16 +0100 Subject: [PATCH 01/13] Rename the spec helper to avoid conflicts with the target app --- .rspec | 1 - spec/features/backend/new_payment_method_spec.rb | 2 +- spec/features/frontend/cart_spec.rb | 2 +- spec/features/frontend/checkout_spec.rb | 2 +- spec/features/frontend/product_spec.rb | 2 +- spec/jobs/solidus_paypal_commerce_platform/webhook_job_spec.rb | 2 +- spec/lib/solidus_paypal_commerce_platform/client_spec.rb | 2 +- spec/lib/solidus_paypal_commerce_platform/configuration_spec.rb | 2 +- .../solidus_paypal_commerce_platform/payment_method_spec.rb | 2 +- .../solidus_paypal_commerce_platform/payment_source_spec.rb | 2 +- .../solidus_paypal_commerce_platform/paypal_address_spec.rb | 2 +- .../solidus_paypal_commerce_platform/paypal_order_spec.rb | 2 +- .../solidus_paypal_commerce_platform/state_guesser_spec.rb | 2 +- spec/models/solidus_paypal_commerce_platform/wizard_spec.rb | 2 +- .../solidus_paypal_commerce_platform/orders_controller_spec.rb | 2 +- .../shipping_rates_controller_spec.rb | 2 +- .../solidus_paypal_commerce_platform/wizard_controller_spec.rb | 2 +- ...elper.rb => solidus_paypal_commerce_platform_spec_helper.rb} | 0 18 files changed, 16 insertions(+), 17 deletions(-) rename spec/{spec_helper.rb => solidus_paypal_commerce_platform_spec_helper.rb} (100%) diff --git a/.rspec b/.rspec index 83e16f80..4e1e0d2f 100644 --- a/.rspec +++ b/.rspec @@ -1,2 +1 @@ --color ---require spec_helper diff --git a/spec/features/backend/new_payment_method_spec.rb b/spec/features/backend/new_payment_method_spec.rb index d12ec349..23893e4f 100644 --- a/spec/features/backend/new_payment_method_spec.rb +++ b/spec/features/backend/new_payment_method_spec.rb @@ -1,4 +1,4 @@ -require 'spec_helper' +require 'solidus_paypal_commerce_platform_spec_helper' RSpec.describe "creating a new payment" do stub_authorization! diff --git a/spec/features/frontend/cart_spec.rb b/spec/features/frontend/cart_spec.rb index 6b413df2..58b883f0 100644 --- a/spec/features/frontend/cart_spec.rb +++ b/spec/features/frontend/cart_spec.rb @@ -1,4 +1,4 @@ -require 'spec_helper' +require 'solidus_paypal_commerce_platform_spec_helper' RSpec.describe "Cart page" do describe "paypal payment method" do diff --git a/spec/features/frontend/checkout_spec.rb b/spec/features/frontend/checkout_spec.rb index 5e6cd31a..9e68b825 100644 --- a/spec/features/frontend/checkout_spec.rb +++ b/spec/features/frontend/checkout_spec.rb @@ -1,4 +1,4 @@ -require 'spec_helper' +require 'solidus_paypal_commerce_platform_spec_helper' RSpec.describe "Checkout" do describe "paypal payment method" do diff --git a/spec/features/frontend/product_spec.rb b/spec/features/frontend/product_spec.rb index faeb9a90..154e4083 100644 --- a/spec/features/frontend/product_spec.rb +++ b/spec/features/frontend/product_spec.rb @@ -1,4 +1,4 @@ -require 'spec_helper' +require 'solidus_paypal_commerce_platform_spec_helper' RSpec.describe "Product page", js: true do describe "paypal button" do diff --git a/spec/jobs/solidus_paypal_commerce_platform/webhook_job_spec.rb b/spec/jobs/solidus_paypal_commerce_platform/webhook_job_spec.rb index 58cc2d47..bb5bde2e 100644 --- a/spec/jobs/solidus_paypal_commerce_platform/webhook_job_spec.rb +++ b/spec/jobs/solidus_paypal_commerce_platform/webhook_job_spec.rb @@ -1,4 +1,4 @@ -require 'spec_helper' +require 'solidus_paypal_commerce_platform_spec_helper' RSpec.describe SolidusPaypalCommercePlatform::WebhookJob do let(:paypal_order_id) { SecureRandom.uuid } diff --git a/spec/lib/solidus_paypal_commerce_platform/client_spec.rb b/spec/lib/solidus_paypal_commerce_platform/client_spec.rb index 9892a64c..67cdca56 100644 --- a/spec/lib/solidus_paypal_commerce_platform/client_spec.rb +++ b/spec/lib/solidus_paypal_commerce_platform/client_spec.rb @@ -1,4 +1,4 @@ -require 'spec_helper' +require 'solidus_paypal_commerce_platform_spec_helper' RSpec.describe SolidusPaypalCommercePlatform::Client do subject(:client) { described_class.new(client_id: "1234") } diff --git a/spec/lib/solidus_paypal_commerce_platform/configuration_spec.rb b/spec/lib/solidus_paypal_commerce_platform/configuration_spec.rb index 3df8551e..8c17996f 100644 --- a/spec/lib/solidus_paypal_commerce_platform/configuration_spec.rb +++ b/spec/lib/solidus_paypal_commerce_platform/configuration_spec.rb @@ -1,4 +1,4 @@ -require 'spec_helper' +require 'solidus_paypal_commerce_platform_spec_helper' RSpec.describe SolidusPaypalCommercePlatform::Configuration do subject(:test_subject) { described_class.new } diff --git a/spec/models/solidus_paypal_commerce_platform/payment_method_spec.rb b/spec/models/solidus_paypal_commerce_platform/payment_method_spec.rb index ac73e270..59fffc20 100644 --- a/spec/models/solidus_paypal_commerce_platform/payment_method_spec.rb +++ b/spec/models/solidus_paypal_commerce_platform/payment_method_spec.rb @@ -1,4 +1,4 @@ -require 'spec_helper' +require 'solidus_paypal_commerce_platform_spec_helper' RSpec.describe SolidusPaypalCommercePlatform::PaymentMethod, type: :model do let(:paypal_payment_method) { create(:paypal_payment_method) } diff --git a/spec/models/solidus_paypal_commerce_platform/payment_source_spec.rb b/spec/models/solidus_paypal_commerce_platform/payment_source_spec.rb index 9c9d01da..2051bd2d 100644 --- a/spec/models/solidus_paypal_commerce_platform/payment_source_spec.rb +++ b/spec/models/solidus_paypal_commerce_platform/payment_source_spec.rb @@ -1,4 +1,4 @@ -require 'spec_helper' +require 'solidus_paypal_commerce_platform_spec_helper' RSpec.describe SolidusPaypalCommercePlatform::PaymentSource, type: :model do let(:order) { Spree::TestingSupport::OrderWalkthrough.up_to(:payment) } diff --git a/spec/models/solidus_paypal_commerce_platform/paypal_address_spec.rb b/spec/models/solidus_paypal_commerce_platform/paypal_address_spec.rb index b5b63896..ed07d2ed 100644 --- a/spec/models/solidus_paypal_commerce_platform/paypal_address_spec.rb +++ b/spec/models/solidus_paypal_commerce_platform/paypal_address_spec.rb @@ -1,4 +1,4 @@ -require 'spec_helper' +require 'solidus_paypal_commerce_platform_spec_helper' RSpec.describe SolidusPaypalCommercePlatform::PaypalAddress, type: :model do let(:order) { create(:order) } diff --git a/spec/models/solidus_paypal_commerce_platform/paypal_order_spec.rb b/spec/models/solidus_paypal_commerce_platform/paypal_order_spec.rb index 924ff375..d4bdb3a3 100644 --- a/spec/models/solidus_paypal_commerce_platform/paypal_order_spec.rb +++ b/spec/models/solidus_paypal_commerce_platform/paypal_order_spec.rb @@ -1,6 +1,6 @@ # frozen_string_literal: true -require 'spec_helper' +require 'solidus_paypal_commerce_platform_spec_helper' RSpec.describe SolidusPaypalCommercePlatform::PaypalOrder, type: :model do describe '#to_json' do diff --git a/spec/models/solidus_paypal_commerce_platform/state_guesser_spec.rb b/spec/models/solidus_paypal_commerce_platform/state_guesser_spec.rb index 473c65cd..14ff2f3b 100644 --- a/spec/models/solidus_paypal_commerce_platform/state_guesser_spec.rb +++ b/spec/models/solidus_paypal_commerce_platform/state_guesser_spec.rb @@ -1,4 +1,4 @@ -require 'spec_helper' +require 'solidus_paypal_commerce_platform_spec_helper' RSpec.describe SolidusPaypalCommercePlatform::StateGuesser, type: :model do let(:country) { create(:country, iso: "IT") } diff --git a/spec/models/solidus_paypal_commerce_platform/wizard_spec.rb b/spec/models/solidus_paypal_commerce_platform/wizard_spec.rb index da6edcbd..3f75e895 100644 --- a/spec/models/solidus_paypal_commerce_platform/wizard_spec.rb +++ b/spec/models/solidus_paypal_commerce_platform/wizard_spec.rb @@ -1,4 +1,4 @@ -require 'spec_helper' +require 'solidus_paypal_commerce_platform_spec_helper' RSpec.describe SolidusPaypalCommercePlatform::Wizard do describe "#nonce" do diff --git a/spec/requests/solidus_paypal_commerce_platform/orders_controller_spec.rb b/spec/requests/solidus_paypal_commerce_platform/orders_controller_spec.rb index 32b7eab2..132ca2a2 100644 --- a/spec/requests/solidus_paypal_commerce_platform/orders_controller_spec.rb +++ b/spec/requests/solidus_paypal_commerce_platform/orders_controller_spec.rb @@ -1,4 +1,4 @@ -require 'spec_helper' +require 'solidus_paypal_commerce_platform_spec_helper' RSpec.describe SolidusPaypalCommercePlatform::OrdersController, type: :request do stub_authorization! diff --git a/spec/requests/solidus_paypal_commerce_platform/shipping_rates_controller_spec.rb b/spec/requests/solidus_paypal_commerce_platform/shipping_rates_controller_spec.rb index a731f11b..cfa2c01e 100644 --- a/spec/requests/solidus_paypal_commerce_platform/shipping_rates_controller_spec.rb +++ b/spec/requests/solidus_paypal_commerce_platform/shipping_rates_controller_spec.rb @@ -1,4 +1,4 @@ -require 'spec_helper' +require 'solidus_paypal_commerce_platform_spec_helper' RSpec.describe SolidusPaypalCommercePlatform::ShippingRatesController, type: :request do stub_authorization! diff --git a/spec/requests/solidus_paypal_commerce_platform/wizard_controller_spec.rb b/spec/requests/solidus_paypal_commerce_platform/wizard_controller_spec.rb index 5a0ad336..d31727b3 100644 --- a/spec/requests/solidus_paypal_commerce_platform/wizard_controller_spec.rb +++ b/spec/requests/solidus_paypal_commerce_platform/wizard_controller_spec.rb @@ -1,4 +1,4 @@ -require 'spec_helper' +require 'solidus_paypal_commerce_platform_spec_helper' RSpec.describe SolidusPaypalCommercePlatform::WizardController, type: :request do stub_authorization! diff --git a/spec/spec_helper.rb b/spec/solidus_paypal_commerce_platform_spec_helper.rb similarity index 100% rename from spec/spec_helper.rb rename to spec/solidus_paypal_commerce_platform_spec_helper.rb From 65790ded9bda0979093114b7c645e0f929649a98 Mon Sep 17 00:00:00 2001 From: Elia Schito Date: Thu, 10 Nov 2022 16:22:36 +0100 Subject: [PATCH 02/13] Add a dummy app generator script We'll use the dummy app to run specs in a full-fledged target app. The sandbox script also got a couple of updates/fixes in parallel with what was don in bin/dummy-app. --- .gitignore | 1 + .rubocop.yml | 1 + bin/dummy-app | 36 ++++++++++++++++++++++++++++++++++++ bin/rails-dummy-app | 17 +++++++++++++++++ bin/sandbox | 11 +++-------- 5 files changed, 58 insertions(+), 8 deletions(-) create mode 100755 bin/dummy-app create mode 100755 bin/rails-dummy-app diff --git a/.gitignore b/.gitignore index 325c3c99..9b92ac78 100644 --- a/.gitignore +++ b/.gitignore @@ -15,6 +15,7 @@ pkg spec/dummy spec/examples.txt /sandbox +/dummy-app .rvmrc .ruby-version .ruby-gemset diff --git a/.rubocop.yml b/.rubocop.yml index df59fb56..17dfec2f 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -6,6 +6,7 @@ AllCops: TargetRubyVersion: '2.7' Exclude: - sandbox/**/* + - dummy-app/**/* - spec/dummy/**/* - vendor/bundle/**/* diff --git a/bin/dummy-app b/bin/dummy-app new file mode 100755 index 00000000..390d0f07 --- /dev/null +++ b/bin/dummy-app @@ -0,0 +1,36 @@ +#!/usr/bin/env bash + +set -e + +extension_name="solidus_paypal_commerce_platform" + +# Stay away from the bundler env of the containing extension. +function unbundled { + ruby -rbundler -e'b = proc {system *ARGV}; Bundler.respond_to?(:with_unbundled_env) ? Bundler.with_unbundled_env(&b) : Bundler.with_clean_env(&b)' -- $@ +} + +# "sqlite" is set by the ORB extension instead of "sqlite3", +# all other options are already in the format expected by `rails new`. +test "$DB" = "sqlite" && export DB="sqlite3" + +rm -rf ./dummy-app +unbundled bundle exec rails new dummy-app \ + --database=${DB:-sqlite3} \ + --skip-bundle \ + --skip-git \ + --skip-keeps \ + --skip-rc \ + --skip-spring \ + --skip-javascript + +if [ ! -d "dummy-app" ]; then + echo 'dummy-app rails application failed' + exit 1 +fi + +cd ./dummy-app +unbundled bundle add solidus --github solidusio/solidus --branch "${BRANCH:-master}" --version '> 0.a' +unbundled bundle exec rake db:drop db:create +unbundled bundle exec rails generate solidus:install --auto-accept --payment-method=none --no-seed --no-sample $@ +unbundled bundle add $extension_name --path .. +unbundled bundle exec rails generate $extension_name:install --auto-accept diff --git a/bin/rails-dummy-app b/bin/rails-dummy-app new file mode 100755 index 00000000..58a3513d --- /dev/null +++ b/bin/rails-dummy-app @@ -0,0 +1,17 @@ +#!/usr/bin/env ruby + +root = "#{__dir__}/.." +app_root = "#{root}/dummy-app" + +unless File.exist? "#{app_root}/bin/rails" + warn 'Creating the dummy-app app...' + Dir.chdir root do + system "#{root}/bin/dummy-app" or begin + warn 'Automatic creation of the dummy-app app failed' + exit 1 + end + end +end + +Dir.chdir app_root +exec "#{app_root}/bin/rails", *ARGV diff --git a/bin/sandbox b/bin/sandbox index 5503c629..169f447b 100755 --- a/bin/sandbox +++ b/bin/sandbox @@ -29,7 +29,7 @@ extension_name="solidus_paypal_commerce_platform" # Stay away from the bundler env of the containing extension. function unbundled { - ruby -rbundler -e'b = proc {system *ARGV}; Bundler.respond_to?(:with_unbundled_env) ? Bundler.with_unbundled_env(&b) : Bundler.with_clean_env(&b)' -- $@ + ruby -rbundler -e'b = proc {system *ARGV}; Bundler.respond_to?(:with_unbundled_env) ? Bundler.with_unbundled_env(&b) : Bundler.with_clean_env(&b)' -- "$@" } rm -rf ./sandbox @@ -48,14 +48,9 @@ if [ ! -d "sandbox" ]; then fi cd ./sandbox -cat <> Gemfile - gem 'solidus', github: 'solidusio/solidus', branch: '$BRANCH' - gem 'pry-byebug', platforms: :mri, groups: [:test, :development] -RUBY - -unbundled bundle install --gemfile Gemfile +unbundled bundle add solidus --github solidusio/solidus --branch "${BRANCH:-master}" --version '> 0.a' unbundled bundle exec rake db:drop db:create -unbundled bundle exec rails generate solidus:install --auto-accept $@ +unbundled bundle exec rails generate solidus:install --auto-accept "$@" echo echo "🚀 Sandbox app successfully created for $extension_name!" From 8a8a31c1dcf4f0c4e5a98fe063cebadcdd428bc9 Mon Sep 17 00:00:00 2001 From: Elia Schito Date: Fri, 11 Nov 2022 16:37:32 +0100 Subject: [PATCH 03/13] Use a single option to control migrations Defaults to not run migrations. --- .../install/install_generator.rb | 12 ++---------- 1 file changed, 2 insertions(+), 10 deletions(-) diff --git a/lib/generators/solidus_paypal_commerce_platform/install/install_generator.rb b/lib/generators/solidus_paypal_commerce_platform/install/install_generator.rb index 62c629ac..aaafb0bb 100644 --- a/lib/generators/solidus_paypal_commerce_platform/install/install_generator.rb +++ b/lib/generators/solidus_paypal_commerce_platform/install/install_generator.rb @@ -3,16 +3,14 @@ module SolidusPaypalCommercePlatform module Generators class InstallGenerator < Rails::Generators::Base - class_option :auto_run_migrations, type: :boolean, default: false - - # This should only be used by the solidus installer prior to v3.3. - class_option :skip_migrations, type: :boolean, default: false, hide: true + class_option :migrate, type: :boolean, default: true source_root File.expand_path('templates', __dir__) def install_solidus_core_support template 'initializer.rb', 'config/initializers/solidus_paypal_commerce_platform.rb' rake 'railties:install:migrations FROM=solidus_paypal_commerce_platform' + run 'bin/rails db:migrate' if options[:migrate] route "mount SolidusPaypalCommercePlatform::Engine, at: '/solidus_paypal_commerce_platform'" end @@ -47,12 +45,6 @@ def install_solidus_frontend_support end end - def run_migrations - return rake 'db:migrate' if options[:auto_run_migrations] && !options[:skip_migrations] - - say_status :skip, 'db:migrate' - end - private def support_code_for(gem_name, run_if: Bundler.locked_gems.specs.map(&:name).include?(gem_name), &block) From b65803ce2ad7de0a596fa98e33364a90cfbf45a7 Mon Sep 17 00:00:00 2001 From: Elia Schito Date: Tue, 22 Nov 2022 11:17:08 +0100 Subject: [PATCH 04/13] Streamline the spec helper Rely on the SSF spec helper and only add to support things that are specific to this extension (e.g. factories and helpers). --- ...us_paypal_commerce_platform_spec_helper.rb | 27 ++----------------- spec/support/capybara.rb | 11 -------- .../factories.rb | 5 ++++ .../paypal_sdk_script_tag_helper.rb | 2 +- 4 files changed, 8 insertions(+), 37 deletions(-) delete mode 100644 spec/support/capybara.rb create mode 100644 spec/support/solidus_paypal_commerce_platform/factories.rb rename spec/support/{ => solidus_paypal_commerce_platform}/paypal_sdk_script_tag_helper.rb (84%) diff --git a/spec/solidus_paypal_commerce_platform_spec_helper.rb b/spec/solidus_paypal_commerce_platform_spec_helper.rb index 90a967d1..9d161c7d 100644 --- a/spec/solidus_paypal_commerce_platform_spec_helper.rb +++ b/spec/solidus_paypal_commerce_platform_spec_helper.rb @@ -1,28 +1,5 @@ # frozen_string_literal: true -# Configure Rails Environment -ENV['RAILS_ENV'] = 'test' +require 'solidus_starter_frontend_helper' -# Run Coverage report -require 'solidus_dev_support/rspec/coverage' - -# Create the dummy app if it's still missing. -dummy_env = "#{__dir__}/dummy/config/environment.rb" -system 'bin/rake extension:test_app' unless File.exist? dummy_env -require dummy_env - -# Requires factories and other useful helpers defined in spree_core. -require 'solidus_dev_support/rspec/feature_helper' -require 'spree/testing_support/order_walkthrough' - -# Requires supporting ruby files with custom matchers and macros, etc, -# in spec/support/ and its subdirectories. -Dir["#{__dir__}/support/**/*.rb"].sort.each { |f| require f } - -# Requires factories defined in lib/solidus_paypal_commerce_platform/testing_support/factories.rb -SolidusDevSupport::TestingSupport::Factories.load_for(SolidusPaypalCommercePlatform::Engine) - -RSpec.configure do |config| - config.infer_spec_type_from_file_location! - config.use_transactional_fixtures = false -end +Dir["#{__dir__}/support/solidus_paypal_commerce_platform/**/*.rb"].sort.each { |f| require f } diff --git a/spec/support/capybara.rb b/spec/support/capybara.rb deleted file mode 100644 index 46baf938..00000000 --- a/spec/support/capybara.rb +++ /dev/null @@ -1,11 +0,0 @@ -require "capybara/cuprite" - -Capybara.javascript_driver = :cuprite - -Capybara.register_driver(:cuprite) do |app| - # Set `export INSPECTOR=true` and add `page.driver.debug(binding)` to open a Chrome tab - # to debug the browser status. - # - # See also: https://github.com/rubycdp/cuprite#debugging - Capybara::Cuprite::Driver.new(app, window_size: [1920, 1080], inspector: ENV.fetch("INSPECTOR", nil)) -end diff --git a/spec/support/solidus_paypal_commerce_platform/factories.rb b/spec/support/solidus_paypal_commerce_platform/factories.rb new file mode 100644 index 00000000..b5438dfb --- /dev/null +++ b/spec/support/solidus_paypal_commerce_platform/factories.rb @@ -0,0 +1,5 @@ +FactoryBot.definition_file_paths << SolidusPaypalCommercePlatform::Engine.root.join( + 'lib/solidus_paypal_commerce_platform/testing_support/factories' +).to_s + +FactoryBot.reload diff --git a/spec/support/paypal_sdk_script_tag_helper.rb b/spec/support/solidus_paypal_commerce_platform/paypal_sdk_script_tag_helper.rb similarity index 84% rename from spec/support/paypal_sdk_script_tag_helper.rb rename to spec/support/solidus_paypal_commerce_platform/paypal_sdk_script_tag_helper.rb index 5cf9b2a7..1f7f7782 100644 --- a/spec/support/paypal_sdk_script_tag_helper.rb +++ b/spec/support/solidus_paypal_commerce_platform/paypal_sdk_script_tag_helper.rb @@ -9,5 +9,5 @@ def js_sdk_script_partner_id end RSpec.configure do |config| - config.include PaypalSdkScriptTagHelper, type: :feature + config.include PaypalSdkScriptTagHelper, type: :system end From d00526311e038f4082ff40f5da51dae36a09df50 Mon Sep 17 00:00:00 2001 From: Elia Schito Date: Tue, 22 Nov 2022 11:23:03 +0100 Subject: [PATCH 05/13] Move feature specs under spec/system That allows better compatibility with what the SSF expects. --- .rubocop.yml | 4 ++-- spec/{features => system}/backend/new_payment_method_spec.rb | 0 spec/{features => system}/frontend/cart_spec.rb | 0 spec/{features => system}/frontend/checkout_spec.rb | 0 spec/{features => system}/frontend/product_spec.rb | 0 5 files changed, 2 insertions(+), 2 deletions(-) rename spec/{features => system}/backend/new_payment_method_spec.rb (100%) rename spec/{features => system}/frontend/cart_spec.rb (100%) rename spec/{features => system}/frontend/checkout_spec.rb (100%) rename spec/{features => system}/frontend/product_spec.rb (100%) diff --git a/.rubocop.yml b/.rubocop.yml index 17dfec2f..19104513 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -24,10 +24,10 @@ Naming/VariableNumber: RSpec/AnyInstance: Enabled: false -# Feature specs are not describing any class or module. +# System specs are not describing any class or module. RSpec/DescribeClass: Exclude: - - spec/features/**/* + - spec/system/**/* # No need to make the code more complex for no real gain. RSpec/MessageSpies: diff --git a/spec/features/backend/new_payment_method_spec.rb b/spec/system/backend/new_payment_method_spec.rb similarity index 100% rename from spec/features/backend/new_payment_method_spec.rb rename to spec/system/backend/new_payment_method_spec.rb diff --git a/spec/features/frontend/cart_spec.rb b/spec/system/frontend/cart_spec.rb similarity index 100% rename from spec/features/frontend/cart_spec.rb rename to spec/system/frontend/cart_spec.rb diff --git a/spec/features/frontend/checkout_spec.rb b/spec/system/frontend/checkout_spec.rb similarity index 100% rename from spec/features/frontend/checkout_spec.rb rename to spec/system/frontend/checkout_spec.rb diff --git a/spec/features/frontend/product_spec.rb b/spec/system/frontend/product_spec.rb similarity index 100% rename from spec/features/frontend/product_spec.rb rename to spec/system/frontend/product_spec.rb From be460ecf200cc70021dbad205fca69316a101c92 Mon Sep 17 00:00:00 2001 From: Elia Schito Date: Tue, 22 Nov 2022 11:24:07 +0100 Subject: [PATCH 06/13] Cleanup the main Gemfile Everything now happens in the dummy-app gemfile. --- Gemfile | 41 ----------------------------------------- 1 file changed, 41 deletions(-) diff --git a/Gemfile b/Gemfile index adca338b..7f4f5e95 100644 --- a/Gemfile +++ b/Gemfile @@ -1,46 +1,5 @@ # frozen_string_literal: true source 'https://rubygems.org' -git_source(:github) { |repo| "https://github.com/#{repo}.git" } - -branch = ENV.fetch('SOLIDUS_BRANCH', 'master') -solidus_git, solidus_frontend_git = if (branch == 'master') || (branch >= 'v3.2') - %w[solidusio/solidus solidusio/solidus_frontend] - else - %w[solidusio/solidus] * 2 - end -gem 'solidus', github: solidus_git, branch: branch -gem 'solidus_frontend', github: solidus_frontend_git, branch: branch - -# Needed to help Bundler figure out how to resolve dependencies, -# otherwise it takes forever to resolve them. -# See https://github.com/bundler/bundler/issues/6677 -gem 'rails', ENV.fetch('RAILS_VERSION', '>0.a') - -# Provides basic authentication functionality for testing parts of your engine -gem 'solidus_auth_devise' - -case ENV.fetch('DB', nil) -when 'mysql' - gem 'mysql2' -when 'postgresql' - gem 'pg' -else - gem 'sqlite3' -end - -if Gem::Version.new(RUBY_VERSION) >= Gem::Version.new('3') - # 'net/smtp' is required by 'mail', see: - # - https://github.com/ruby/net-protocol/issues/10 - # - https://stackoverflow.com/a/72474475 - gem 'net-smtp', require: false -end gemspec - -# Use a local Gemfile to include development dependencies that might not be -# relevant for the project or for other contributors, e.g. pry-byebug. -# -# We use `send` instead of calling `eval_gemfile` to work around an issue with -# how Dependabot parses projects: https://github.com/dependabot/dependabot-core/issues/1658. -send(:eval_gemfile, 'Gemfile-local') if File.exist? 'Gemfile-local' From f14087ef223f8c0360dcefe1ffccb5fd57f65ece Mon Sep 17 00:00:00 2001 From: Elia Schito Date: Tue, 22 Nov 2022 11:24:27 +0100 Subject: [PATCH 07/13] Stick to the capybara js driver provided by SSF --- solidus_paypal_commerce_platform.gemspec | 1 - 1 file changed, 1 deletion(-) diff --git a/solidus_paypal_commerce_platform.gemspec b/solidus_paypal_commerce_platform.gemspec index abc5dda9..9cd8e207 100644 --- a/solidus_paypal_commerce_platform.gemspec +++ b/solidus_paypal_commerce_platform.gemspec @@ -36,6 +36,5 @@ Gem::Specification.new do |spec| spec.add_dependency 'paypalhttp' - spec.add_development_dependency 'cuprite' spec.add_development_dependency 'solidus_dev_support', '~> 2.5' end From f9c5461f98b79681d2901b2db28bde0bcbbf936e Mon Sep 17 00:00:00 2001 From: Elia Schito Date: Tue, 22 Nov 2022 12:53:49 +0100 Subject: [PATCH 08/13] Run specs within the dummy-app/ --- .circleci/config.yml | 30 +++++++++++++++++++++--------- README.md | 13 +++---------- Rakefile | 7 ++++++- bin/rspec | 7 +++++++ 4 files changed, 37 insertions(+), 20 deletions(-) create mode 100755 bin/rspec diff --git a/.circleci/config.yml b/.circleci/config.yml index 52ae484c..973948a3 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -9,33 +9,45 @@ orbs: # or goes EOL. solidusio_extensions: solidusio/extensions@volatile +commands: + test-with-starter-frontend: + steps: + - checkout + - browser-tools/install-chrome + - run: + name: Install libvips + command: sudo apt-get install -y libvips + - solidusio_extensions/test-branch: + branch: master + command: | + export FRONTEND=starter + sudo gem update --system + gem install bundler + bin/dummy-app + bin/rspec + - solidusio_extensions/store-test-results + jobs: run-specs-with-postgres: executor: name: solidusio_extensions/postgres ruby_version: '3.1' steps: - - checkout - - browser-tools/install-chrome - - solidusio_extensions/run-tests + - test-with-starter-frontend run-specs-with-mysql: executor: name: solidusio_extensions/mysql ruby_version: '3.0' steps: - - checkout - - browser-tools/install-chrome - - solidusio_extensions/run-tests + - test-with-starter-frontend run-specs-with-sqlite: executor: name: solidusio_extensions/sqlite ruby_version: '2.7' steps: - - checkout - - browser-tools/install-chrome - - solidusio_extensions/run-tests + - test-with-starter-frontend lint-code: executor: solidusio_extensions/sqlite-memory diff --git a/README.md b/README.md index b0cf3632..f89a95bd 100644 --- a/README.md +++ b/README.md @@ -145,10 +145,10 @@ See more about preferences [here](https://guides.solidus.io/developers/preferenc First bundle your dependencies, then run `bin/rake`. `bin/rake` will default to building the dummy app if it does not exist, then it will run specs. The dummy app can be regenerated by using -`bin/rake extension:test_app`. +`bin/dummy-app`. ```shell -bundle +bin/setup bin/rake ``` @@ -158,13 +158,6 @@ To run [Rubocop](https://github.com/bbatsov/rubocop) static code analysis run bundle exec rubocop ``` -When testing your application's integration with this extension you may use its factories. -Simply add this require statement to your spec_helper: - -```ruby -require 'solidus_paypal_commerce_platform/factories' -``` - ### Running the sandbox To run this extension in a sandboxed Solidus application, you can run `bin/sandbox`. The path for @@ -216,4 +209,4 @@ By using this extension, you are giving back to Solidus. PayPal will pay a fee t ## License -Copyright (c) 2020 Nebulab srls, released under the New BSD License +Copyright (c) 2022 Nebulab srls, released under the New BSD License diff --git a/Rakefile b/Rakefile index c08aa468..8e964326 100644 --- a/Rakefile +++ b/Rakefile @@ -3,4 +3,9 @@ require 'solidus_dev_support/rake_tasks' SolidusDevSupport::RakeTasks.install -task default: 'extension:specs' +task :default do + require 'bundler' + Bundler.with_unbundled_env do + sh 'bin/rspec' + end +end diff --git a/bin/rspec b/bin/rspec new file mode 100755 index 00000000..a958a4fe --- /dev/null +++ b/bin/rspec @@ -0,0 +1,7 @@ +#!/usr/bin/env bash +bin/rails-dummy-app g solidus_paypal_commerce_platform:install --force --migrate +cd dummy-app/ +rspec $@ +exit_status=$? +cd - +exit $exit_status From fcbfd534288ee50d9d95b35c45a9139f353a33b7 Mon Sep 17 00:00:00 2001 From: Elia Schito Date: Tue, 22 Nov 2022 13:16:12 +0100 Subject: [PATCH 09/13] Switch from SF to SSF in the install generator --- bin/dummy-app | 7 ++-- bin/rspec | 8 +++- .../install/install_generator.rb | 37 +++++++++++++++---- .../solidus_paypal_commerce_platform.js | 0 .../button_actions.js | 0 .../buttons.js | 0 .../namespace.js | 0 .../solidus_paypal_commerce_platform.css | 0 .../orders_controller.rb | 0 .../payments_controller.rb | 0 .../paypal_orders_controller.rb | 0 .../shipping_rates_controller.rb | 0 .../wizard_controller.rb | 0 .../_paypal_commerce_platform.html.erb | 0 .../_paypal_commerce_platform.html.erb | 0 .../_paypal_commerce_platform.html.erb | 0 .../cart/_cart_buttons.html.erb | 0 .../payments/_payment.html.erb | 0 .../product/_product_buttons.html.erb | 0 .../shared/_javascript_sdk_tag.html.erb | 0 .../solidus_paypal_commerce_platform.rb} | 0 solidus_paypal_commerce_platform.gemspec | 2 +- 22 files changed, 41 insertions(+), 13 deletions(-) rename {app => lib/generators/solidus_paypal_commerce_platform/install/templates/app}/assets/javascripts/spree/frontend/solidus_paypal_commerce_platform.js (100%) rename {app => lib/generators/solidus_paypal_commerce_platform/install/templates/app}/assets/javascripts/spree/frontend/solidus_paypal_commerce_platform/button_actions.js (100%) rename {app => lib/generators/solidus_paypal_commerce_platform/install/templates/app}/assets/javascripts/spree/frontend/solidus_paypal_commerce_platform/buttons.js (100%) rename {app => lib/generators/solidus_paypal_commerce_platform/install/templates/app}/assets/javascripts/spree/frontend/solidus_paypal_commerce_platform/namespace.js (100%) rename {app => lib/generators/solidus_paypal_commerce_platform/install/templates/app}/assets/stylesheets/spree/frontend/solidus_paypal_commerce_platform.css (100%) rename {app => lib/generators/solidus_paypal_commerce_platform/install/templates/app}/controllers/solidus_paypal_commerce_platform/orders_controller.rb (100%) rename {app => lib/generators/solidus_paypal_commerce_platform/install/templates/app}/controllers/solidus_paypal_commerce_platform/payments_controller.rb (100%) rename {app => lib/generators/solidus_paypal_commerce_platform/install/templates/app}/controllers/solidus_paypal_commerce_platform/paypal_orders_controller.rb (100%) rename {app => lib/generators/solidus_paypal_commerce_platform/install/templates/app}/controllers/solidus_paypal_commerce_platform/shipping_rates_controller.rb (100%) rename {app => lib/generators/solidus_paypal_commerce_platform/install/templates/app}/controllers/solidus_paypal_commerce_platform/wizard_controller.rb (100%) rename lib/{views/frontend/spree/checkout => generators/solidus_paypal_commerce_platform/install/templates/app/views/checkouts}/payment/_paypal_commerce_platform.html.erb (100%) rename lib/{views/frontend/spree => generators/solidus_paypal_commerce_platform/install/templates/app/views}/orders/payment/_paypal_commerce_platform.html.erb (100%) rename lib/{views/frontend/spree => generators/solidus_paypal_commerce_platform/install/templates/app/views}/products/payment/_paypal_commerce_platform.html.erb (100%) rename lib/{views/frontend => generators/solidus_paypal_commerce_platform/install/templates/app/views}/solidus_paypal_commerce_platform/cart/_cart_buttons.html.erb (100%) rename lib/{views/frontend => generators/solidus_paypal_commerce_platform/install/templates/app/views}/solidus_paypal_commerce_platform/payments/_payment.html.erb (100%) rename lib/{views/frontend => generators/solidus_paypal_commerce_platform/install/templates/app/views}/solidus_paypal_commerce_platform/product/_product_buttons.html.erb (100%) rename lib/{views/frontend => generators/solidus_paypal_commerce_platform/install/templates/app/views}/solidus_paypal_commerce_platform/shared/_javascript_sdk_tag.html.erb (100%) rename lib/generators/solidus_paypal_commerce_platform/install/templates/{initializer.rb => config/initializers/solidus_paypal_commerce_platform.rb} (100%) diff --git a/bin/dummy-app b/bin/dummy-app index 390d0f07..94e5dc3c 100755 --- a/bin/dummy-app +++ b/bin/dummy-app @@ -6,7 +6,7 @@ extension_name="solidus_paypal_commerce_platform" # Stay away from the bundler env of the containing extension. function unbundled { - ruby -rbundler -e'b = proc {system *ARGV}; Bundler.respond_to?(:with_unbundled_env) ? Bundler.with_unbundled_env(&b) : Bundler.with_clean_env(&b)' -- $@ + ruby -rbundler -e'b = proc {system *ARGV}; Bundler.respond_to?(:with_unbundled_env) ? Bundler.with_unbundled_env(&b) : Bundler.with_clean_env(&b)' -- "$@" } # "sqlite" is set by the ORB extension instead of "sqlite3", @@ -31,6 +31,7 @@ fi cd ./dummy-app unbundled bundle add solidus --github solidusio/solidus --branch "${BRANCH:-master}" --version '> 0.a' unbundled bundle exec rake db:drop db:create -unbundled bundle exec rails generate solidus:install --auto-accept --payment-method=none --no-seed --no-sample $@ +unbundled bundle exec rails generate solidus:install --auto-accept --payment-method=none --no-seed --no-sample "$@" unbundled bundle add $extension_name --path .. -unbundled bundle exec rails generate $extension_name:install --auto-accept +unbundled bundle exec rails generate $extension_name:install --migrate --specs=all + diff --git a/bin/rspec b/bin/rspec index a958a4fe..1c074aff 100755 --- a/bin/rspec +++ b/bin/rspec @@ -1,7 +1,11 @@ #!/usr/bin/env bash -bin/rails-dummy-app g solidus_paypal_commerce_platform:install --force --migrate + +set -e + +bin/rails-dummy-app generate solidus_paypal_commerce_platform:install --force --migrate --specs=all + cd dummy-app/ -rspec $@ +rspec "$@" exit_status=$? cd - exit $exit_status diff --git a/lib/generators/solidus_paypal_commerce_platform/install/install_generator.rb b/lib/generators/solidus_paypal_commerce_platform/install/install_generator.rb index aaafb0bb..2458b1d2 100644 --- a/lib/generators/solidus_paypal_commerce_platform/install/install_generator.rb +++ b/lib/generators/solidus_paypal_commerce_platform/install/install_generator.rb @@ -4,11 +4,12 @@ module SolidusPaypalCommercePlatform module Generators class InstallGenerator < Rails::Generators::Base class_option :migrate, type: :boolean, default: true + class_option :specs, type: :string, enum: %w[all frontend], default: 'frontend' source_root File.expand_path('templates', __dir__) def install_solidus_core_support - template 'initializer.rb', 'config/initializers/solidus_paypal_commerce_platform.rb' + directory 'config/initializers', 'config/initializers' rake 'railties:install:migrations FROM=solidus_paypal_commerce_platform' run 'bin/rails db:migrate' if options[:migrate] route "mount SolidusPaypalCommercePlatform::Engine, at: '/solidus_paypal_commerce_platform'" @@ -29,19 +30,41 @@ def install_solidus_backend_support end end - def install_solidus_frontend_support - support_code_for('solidus_frontend') do + def install_solidus_starter_frontend_support + solidus_frontend_is_missing = !Bundler.locked_gems.specs.map(&:name).include?('solidus_frontend') + + # We can't do better than this for now, over time we might want to mark things differently + support_code_for('solidus_starter_frontend', run_if: solidus_frontend_is_missing) do + directory 'app', 'app' append_file( - 'vendor/assets/javascripts/spree/frontend/all.js', - "//= require spree/frontend/solidus_paypal_commerce_platform\n", + 'app/assets/javascripts/solidus_starter_frontend.js', + "//= require spree/frontend/solidus_paypal_commerce_platform\n" ) inject_into_file( - 'vendor/assets/stylesheets/spree/frontend/all.css', + 'app/assets/stylesheets/solidus_starter_frontend.css', " *= require spree/frontend/solidus_paypal_commerce_platform\n", before: %r{\*/}, verbose: true, ) - directory engine.root.join("lib/views/frontend"), 'app/views/' + + spec_paths = + case options[:specs] + when 'all' then %w[spec] + when 'frontend' + %w[ + spec/solidus_paypal_commerce_platform_spec_helper.rb + spec/system/frontend + spec/support + ] + end + + spec_paths.each do |path| + if engine.root.join(path).directory? + directory engine.root.join(path), path + else + template engine.root.join(path), path + end + end end end diff --git a/app/assets/javascripts/spree/frontend/solidus_paypal_commerce_platform.js b/lib/generators/solidus_paypal_commerce_platform/install/templates/app/assets/javascripts/spree/frontend/solidus_paypal_commerce_platform.js similarity index 100% rename from app/assets/javascripts/spree/frontend/solidus_paypal_commerce_platform.js rename to lib/generators/solidus_paypal_commerce_platform/install/templates/app/assets/javascripts/spree/frontend/solidus_paypal_commerce_platform.js diff --git a/app/assets/javascripts/spree/frontend/solidus_paypal_commerce_platform/button_actions.js b/lib/generators/solidus_paypal_commerce_platform/install/templates/app/assets/javascripts/spree/frontend/solidus_paypal_commerce_platform/button_actions.js similarity index 100% rename from app/assets/javascripts/spree/frontend/solidus_paypal_commerce_platform/button_actions.js rename to lib/generators/solidus_paypal_commerce_platform/install/templates/app/assets/javascripts/spree/frontend/solidus_paypal_commerce_platform/button_actions.js diff --git a/app/assets/javascripts/spree/frontend/solidus_paypal_commerce_platform/buttons.js b/lib/generators/solidus_paypal_commerce_platform/install/templates/app/assets/javascripts/spree/frontend/solidus_paypal_commerce_platform/buttons.js similarity index 100% rename from app/assets/javascripts/spree/frontend/solidus_paypal_commerce_platform/buttons.js rename to lib/generators/solidus_paypal_commerce_platform/install/templates/app/assets/javascripts/spree/frontend/solidus_paypal_commerce_platform/buttons.js diff --git a/app/assets/javascripts/spree/frontend/solidus_paypal_commerce_platform/namespace.js b/lib/generators/solidus_paypal_commerce_platform/install/templates/app/assets/javascripts/spree/frontend/solidus_paypal_commerce_platform/namespace.js similarity index 100% rename from app/assets/javascripts/spree/frontend/solidus_paypal_commerce_platform/namespace.js rename to lib/generators/solidus_paypal_commerce_platform/install/templates/app/assets/javascripts/spree/frontend/solidus_paypal_commerce_platform/namespace.js diff --git a/app/assets/stylesheets/spree/frontend/solidus_paypal_commerce_platform.css b/lib/generators/solidus_paypal_commerce_platform/install/templates/app/assets/stylesheets/spree/frontend/solidus_paypal_commerce_platform.css similarity index 100% rename from app/assets/stylesheets/spree/frontend/solidus_paypal_commerce_platform.css rename to lib/generators/solidus_paypal_commerce_platform/install/templates/app/assets/stylesheets/spree/frontend/solidus_paypal_commerce_platform.css diff --git a/app/controllers/solidus_paypal_commerce_platform/orders_controller.rb b/lib/generators/solidus_paypal_commerce_platform/install/templates/app/controllers/solidus_paypal_commerce_platform/orders_controller.rb similarity index 100% rename from app/controllers/solidus_paypal_commerce_platform/orders_controller.rb rename to lib/generators/solidus_paypal_commerce_platform/install/templates/app/controllers/solidus_paypal_commerce_platform/orders_controller.rb diff --git a/app/controllers/solidus_paypal_commerce_platform/payments_controller.rb b/lib/generators/solidus_paypal_commerce_platform/install/templates/app/controllers/solidus_paypal_commerce_platform/payments_controller.rb similarity index 100% rename from app/controllers/solidus_paypal_commerce_platform/payments_controller.rb rename to lib/generators/solidus_paypal_commerce_platform/install/templates/app/controllers/solidus_paypal_commerce_platform/payments_controller.rb diff --git a/app/controllers/solidus_paypal_commerce_platform/paypal_orders_controller.rb b/lib/generators/solidus_paypal_commerce_platform/install/templates/app/controllers/solidus_paypal_commerce_platform/paypal_orders_controller.rb similarity index 100% rename from app/controllers/solidus_paypal_commerce_platform/paypal_orders_controller.rb rename to lib/generators/solidus_paypal_commerce_platform/install/templates/app/controllers/solidus_paypal_commerce_platform/paypal_orders_controller.rb diff --git a/app/controllers/solidus_paypal_commerce_platform/shipping_rates_controller.rb b/lib/generators/solidus_paypal_commerce_platform/install/templates/app/controllers/solidus_paypal_commerce_platform/shipping_rates_controller.rb similarity index 100% rename from app/controllers/solidus_paypal_commerce_platform/shipping_rates_controller.rb rename to lib/generators/solidus_paypal_commerce_platform/install/templates/app/controllers/solidus_paypal_commerce_platform/shipping_rates_controller.rb diff --git a/app/controllers/solidus_paypal_commerce_platform/wizard_controller.rb b/lib/generators/solidus_paypal_commerce_platform/install/templates/app/controllers/solidus_paypal_commerce_platform/wizard_controller.rb similarity index 100% rename from app/controllers/solidus_paypal_commerce_platform/wizard_controller.rb rename to lib/generators/solidus_paypal_commerce_platform/install/templates/app/controllers/solidus_paypal_commerce_platform/wizard_controller.rb diff --git a/lib/views/frontend/spree/checkout/payment/_paypal_commerce_platform.html.erb b/lib/generators/solidus_paypal_commerce_platform/install/templates/app/views/checkouts/payment/_paypal_commerce_platform.html.erb similarity index 100% rename from lib/views/frontend/spree/checkout/payment/_paypal_commerce_platform.html.erb rename to lib/generators/solidus_paypal_commerce_platform/install/templates/app/views/checkouts/payment/_paypal_commerce_platform.html.erb diff --git a/lib/views/frontend/spree/orders/payment/_paypal_commerce_platform.html.erb b/lib/generators/solidus_paypal_commerce_platform/install/templates/app/views/orders/payment/_paypal_commerce_platform.html.erb similarity index 100% rename from lib/views/frontend/spree/orders/payment/_paypal_commerce_platform.html.erb rename to lib/generators/solidus_paypal_commerce_platform/install/templates/app/views/orders/payment/_paypal_commerce_platform.html.erb diff --git a/lib/views/frontend/spree/products/payment/_paypal_commerce_platform.html.erb b/lib/generators/solidus_paypal_commerce_platform/install/templates/app/views/products/payment/_paypal_commerce_platform.html.erb similarity index 100% rename from lib/views/frontend/spree/products/payment/_paypal_commerce_platform.html.erb rename to lib/generators/solidus_paypal_commerce_platform/install/templates/app/views/products/payment/_paypal_commerce_platform.html.erb diff --git a/lib/views/frontend/solidus_paypal_commerce_platform/cart/_cart_buttons.html.erb b/lib/generators/solidus_paypal_commerce_platform/install/templates/app/views/solidus_paypal_commerce_platform/cart/_cart_buttons.html.erb similarity index 100% rename from lib/views/frontend/solidus_paypal_commerce_platform/cart/_cart_buttons.html.erb rename to lib/generators/solidus_paypal_commerce_platform/install/templates/app/views/solidus_paypal_commerce_platform/cart/_cart_buttons.html.erb diff --git a/lib/views/frontend/solidus_paypal_commerce_platform/payments/_payment.html.erb b/lib/generators/solidus_paypal_commerce_platform/install/templates/app/views/solidus_paypal_commerce_platform/payments/_payment.html.erb similarity index 100% rename from lib/views/frontend/solidus_paypal_commerce_platform/payments/_payment.html.erb rename to lib/generators/solidus_paypal_commerce_platform/install/templates/app/views/solidus_paypal_commerce_platform/payments/_payment.html.erb diff --git a/lib/views/frontend/solidus_paypal_commerce_platform/product/_product_buttons.html.erb b/lib/generators/solidus_paypal_commerce_platform/install/templates/app/views/solidus_paypal_commerce_platform/product/_product_buttons.html.erb similarity index 100% rename from lib/views/frontend/solidus_paypal_commerce_platform/product/_product_buttons.html.erb rename to lib/generators/solidus_paypal_commerce_platform/install/templates/app/views/solidus_paypal_commerce_platform/product/_product_buttons.html.erb diff --git a/lib/views/frontend/solidus_paypal_commerce_platform/shared/_javascript_sdk_tag.html.erb b/lib/generators/solidus_paypal_commerce_platform/install/templates/app/views/solidus_paypal_commerce_platform/shared/_javascript_sdk_tag.html.erb similarity index 100% rename from lib/views/frontend/solidus_paypal_commerce_platform/shared/_javascript_sdk_tag.html.erb rename to lib/generators/solidus_paypal_commerce_platform/install/templates/app/views/solidus_paypal_commerce_platform/shared/_javascript_sdk_tag.html.erb diff --git a/lib/generators/solidus_paypal_commerce_platform/install/templates/initializer.rb b/lib/generators/solidus_paypal_commerce_platform/install/templates/config/initializers/solidus_paypal_commerce_platform.rb similarity index 100% rename from lib/generators/solidus_paypal_commerce_platform/install/templates/initializer.rb rename to lib/generators/solidus_paypal_commerce_platform/install/templates/config/initializers/solidus_paypal_commerce_platform.rb diff --git a/solidus_paypal_commerce_platform.gemspec b/solidus_paypal_commerce_platform.gemspec index 9cd8e207..dfb95eb2 100644 --- a/solidus_paypal_commerce_platform.gemspec +++ b/solidus_paypal_commerce_platform.gemspec @@ -23,7 +23,7 @@ Gem::Specification.new do |spec| # The `git ls-files -z` loads the files in the RubyGem that have been added into git. files = Dir.chdir(__dir__) { `git ls-files -z`.split("\x0") } - spec.files = files.grep_v(%r{^(test|spec|features)/}) + spec.files = files # don't exclude specs, they need to be copied to the target app spec.bindir = "exe" spec.executables = files.grep(%r{^exe/}) { |f| File.basename(f) } spec.require_paths = ["lib"] From 875b78d4e1fa6cdc97315aba7277f1b3d16d1b12 Mon Sep 17 00:00:00 2001 From: Elia Schito Date: Tue, 22 Nov 2022 13:16:12 +0100 Subject: [PATCH 10/13] Fix support for SSF Frontend paths are no longer defined within the Spree::Core routes and are now coming directly from the main app. Removed `Spree::` namespaces where they're no longer needed. Adjusted selectors for the updated HTML. Some specs have been changed to reduce the usage of `let` and appease rubocop. Use vanilla JS instead of relying on `window.Spree` and jQuery, which are no longer available in SSF. --- .../solidus_paypal_commerce_platform.js | 7 + .../button_actions.js | 296 +++++++++++------- .../_paypal_commerce_platform.html.erb | 9 +- .../_paypal_commerce_platform.html.erb | 7 +- .../_paypal_commerce_platform.html.erb | 2 +- .../shared/_javascript_sdk_tag.html.erb | 6 +- spec/system/frontend/cart_spec.rb | 14 +- spec/system/frontend/checkout_spec.rb | 4 +- spec/system/frontend/product_spec.rb | 79 +++-- 9 files changed, 248 insertions(+), 176 deletions(-) diff --git a/lib/generators/solidus_paypal_commerce_platform/install/templates/app/assets/javascripts/spree/frontend/solidus_paypal_commerce_platform.js b/lib/generators/solidus_paypal_commerce_platform/install/templates/app/assets/javascripts/spree/frontend/solidus_paypal_commerce_platform.js index 345a7015..e9a3b71b 100644 --- a/lib/generators/solidus_paypal_commerce_platform/install/templates/app/assets/javascripts/spree/frontend/solidus_paypal_commerce_platform.js +++ b/lib/generators/solidus_paypal_commerce_platform/install/templates/app/assets/javascripts/spree/frontend/solidus_paypal_commerce_platform.js @@ -1,3 +1,10 @@ //= require spree/frontend/solidus_paypal_commerce_platform/namespace //= require spree/frontend/solidus_paypal_commerce_platform/button_actions //= require spree/frontend/solidus_paypal_commerce_platform/buttons +//= require_self + +Object.assign(SolidusPaypalCommercePlatform, { + current_order_id: null, + current_order_token: null, + api_key: null, +}) diff --git a/lib/generators/solidus_paypal_commerce_platform/install/templates/app/assets/javascripts/spree/frontend/solidus_paypal_commerce_platform/button_actions.js b/lib/generators/solidus_paypal_commerce_platform/install/templates/app/assets/javascripts/spree/frontend/solidus_paypal_commerce_platform/button_actions.js index 465123d0..ddf4550e 100644 --- a/lib/generators/solidus_paypal_commerce_platform/install/templates/app/assets/javascripts/spree/frontend/solidus_paypal_commerce_platform/button_actions.js +++ b/lib/generators/solidus_paypal_commerce_platform/install/templates/app/assets/javascripts/spree/frontend/solidus_paypal_commerce_platform/button_actions.js @@ -1,3 +1,41 @@ +// Attach inline GET-compatible params to a path. +// The path is assumed to be base off the current location. +// The data structure will wrap keys beyond the first level in +// square brackets, e.g. `{a: {b: 123}}` will become `a[b]=123`. +const urlWithParams = (path, data) => { + const url = new URL(path, window.location) + + const formKey = (keys) => { + if (keys.length === 0) return '' + if (keys.length === 1) return keys[0] + + // Wrap any key beyond the first one in square brackets + return `${keys.shift()}${keys.map((k) => `[${k}]`).join()}` + } + + const appendSearchParams = (parentKeys, data) => + Object.entries(data).forEach(([key, value]) => { + + if (typeof value === 'object') + appendSearchParams([...parentKeys, key], value) + else + url.searchParams.append(formKey([...parentKeys, key]), value) + }) + + appendSearchParams([], data) + return url +} + +const authHeader = (options = {}) => { + const apiKey = SolidusPaypalCommercePlatform.api_key + if (options.require && !apiKey) throw new Error("Missing api key") + + + return { + 'Authorization': `Bearer ${apiKey}`, + [document.querySelector('meta[name="csrf-param"]')?.content]: document.querySelector('meta[name="csrf-token"]')?.content, + } +} SolidusPaypalCommercePlatform.showOverlay = function() { document.getElementById("paypal_commerce_platform_overlay").style.display = "block"; } @@ -12,59 +50,67 @@ SolidusPaypalCommercePlatform.handleError = function(error) { throw error } -SolidusPaypalCommercePlatform.sendOrder = function(payment_method_id) { - return Spree.ajax({ - url: '/solidus_paypal_commerce_platform/paypal_orders/' + Spree.current_order_id, - method: 'GET', - data: { - payment_method_id: payment_method_id, - order_token: Spree.current_order_token - } - }).then(function(success_response) { - return success_response.table.result.table.id - }, function(failure_response) { - return failure_response.responseJSON.table.error.table +SolidusPaypalCommercePlatform.sendOrder = async function(payment_method_id) { + if (!payment_method_id) throw new Error("payment_method_id is missing!") + + const url = urlWithParams(`/solidus_paypal_commerce_platform/paypal_orders/${SolidusPaypalCommercePlatform.current_order_id}`, { + payment_method_id: payment_method_id, + order_token: SolidusPaypalCommercePlatform.current_order_token, }) + + const response = await fetch(url, {headers: authHeader()}) + const data = await response.json() + + if (response.ok) { + return data.table.result.table.id + } else { + return data.table.error.table + } } -SolidusPaypalCommercePlatform.createAndSendOrder = function(payment_method_id) { - return SolidusPaypalCommercePlatform.createOrder().then(function(){ - return SolidusPaypalCommercePlatform.sendOrder(payment_method_id) - }) +SolidusPaypalCommercePlatform.createAndSendOrder = async function(payment_method_id) { + await SolidusPaypalCommercePlatform.createOrder() + return await SolidusPaypalCommercePlatform.sendOrder(payment_method_id) } -SolidusPaypalCommercePlatform.createOrder = function() { - var data = { - order: { - line_items_attributes: [{ - variant_id: SolidusPaypalCommercePlatform.getVariantId(), - quantity: SolidusPaypalCommercePlatform.getQuantity() - }] +SolidusPaypalCommercePlatform.createOrder = async function() { + const response = await fetch( + "/solidus_paypal_commerce_platform/orders", + { + method: 'POST', + headers: { + ...authHeader(), + 'Content-Type': 'application/json' + }, + body: JSON.stringify({ + order: { + line_items_attributes: [{ + variant_id: SolidusPaypalCommercePlatform.getVariantId(), + quantity: SolidusPaypalCommercePlatform.getQuantity() + }] + } + }), } - } + ) + const data = await response.json() - return Spree.ajax({ - url: "/solidus_paypal_commerce_platform/orders", - method: 'POST', - data: data, - error: function(response) { - message = response.responseJSON - alert('A problem has occurred while creating your order - ' + message); - } - }).then(function(response) { - Spree.current_order_id = response.number - Spree.current_order_token = response.guest_token - }); + if (response.ok) { + SolidusPaypalCommercePlatform.current_order_id = data.number + SolidusPaypalCommercePlatform.current_order_token = data.guest_token + } else { + console.error('A problem has occurred while creating your order', data); + alert('A problem has occurred while creating your order - ' + JSON.stringify(data)) + } } SolidusPaypalCommercePlatform.getVariantId = function() { var variants = document.getElementsByName("variant_id") var variant_id; - if(variants.length == 1){ + + if (variants.length == 1){ variant_id = variants[0].value - }else{ - var i; - for (i = 0; i < variants.length; i++) { + } else { + for (var i = 0; i < variants.length; i++) { if (variants[i].checked) { variant_id = variants[i].value } @@ -82,50 +128,52 @@ SolidusPaypalCommercePlatform.approveOrder = function(data, actions) { actions.order.get().then(function(response){ SolidusPaypalCommercePlatform.updateAddress(response).then(function() { SolidusPaypalCommercePlatform.verifyTotal(response.purchase_units[0].amount.value).then(function(){ - $("#payments_source_paypal_order_id").val(data.orderID) - $("#payments_source_paypal_email").val(response.payer.email_address) - $("#payments_source_paypal_funding_source").val(SolidusPaypalCommercePlatform.fundingSource) - $("#checkout_form_payment").submit() + document.querySelector("#payments_source_paypal_order_id").value = data.orderID + document.querySelector("#payments_source_paypal_email").value = response.payer.email_address + document.querySelector("#payments_source_paypal_funding_source").value = SolidusPaypalCommercePlatform.fundingSource + document.querySelector("#checkout_form_payment").submit() }) }) }) } -SolidusPaypalCommercePlatform.shippingChange = function(data, actions) { - Spree.ajax({ - url: '/solidus_paypal_commerce_platform/shipping_rates', - method: 'GET', - data: { - order_id: Spree.current_order_id, - order_token: Spree.current_order_token, - address: data.shipping_address - }, - error: function(response) { - message = response.responseJSON; - console.log('There were some problems with your payment address - ' + message); - actions.reject() - } - }).then(function(response) { - actions.order.patch([response]).catch(function() { +SolidusPaypalCommercePlatform.shippingChange = async function(paypalData, actions) { + const shipping_address = paypalData.shipping_address + + url = urlWithParams('/solidus_paypal_commerce_platform/shipping_rates', { + order_id: SolidusPaypalCommercePlatform.current_order_id, + order_token: SolidusPaypalCommercePlatform.current_order_token, + address: shipping_address, + }) + + const response = await fetch(url, {headers: authHeader()}) + const data = await response.json() + + if (response.ok) { + return actions.order.patch([data]).catch(function(e) { + console.error('There were some problems with your payment address while trying to patch the order', e); actions.reject() }) - }) + } else { + console.error('There were some problems with your payment address', data); + return actions.reject() + } } -SolidusPaypalCommercePlatform.verifyTotal = function(paypal_total) { - return Spree.ajax({ - url: '/solidus_paypal_commerce_platform/verify_total', - method: 'GET', - data: { - order_id: Spree.current_order_id, - order_token: Spree.current_order_token, +SolidusPaypalCommercePlatform.verifyTotal = async function(paypal_total) { + const response = await fetch( + urlWithParams('/solidus_paypal_commerce_platform/verify_total', { + order_id: SolidusPaypalCommercePlatform.current_order_id, + order_token: SolidusPaypalCommercePlatform.current_order_token, paypal_total: paypal_total - }, - error: function(response) { - SolidusPaypalCommercePlatform.hideOverlay() - alert('There were some problems with your payment - ' + response.responseJSON.errors.expected_total); - } - }) + }), { + headers: authHeader() + }) + + if (!response.ok) { + SolidusPaypalCommercePlatform.hideOverlay() + alert('There were some problems with your payment - ' + response.responseJSON.errors.expected_total); + } } SolidusPaypalCommercePlatform.finalizeOrder = function(payment_method_id, data, actions) { @@ -144,26 +192,35 @@ SolidusPaypalCommercePlatform.finalizeOrder = function(payment_method_id, data, }) } -SolidusPaypalCommercePlatform.advanceOrder = function() { - return Spree.ajax({ - url: '/api/checkouts/' + Spree.current_order_id + '/advance', - method: 'PUT', - data: { - order_token: Spree.current_order_token - }, - error: function(response) { - SolidusPaypalCommercePlatform.hideOverlay() - alert('There were some problems with your order'); - } - }) +SolidusPaypalCommercePlatform.advanceOrder = async function() { + const response = await fetch( + `/api/checkouts/${SolidusPaypalCommercePlatform.current_order_id}/advance`, { + headers: { + ...authHeader(), + 'Content-Type': 'application/json' + }, + method: 'PUT', + body: JSON.stringify({ + order_token: SolidusPaypalCommercePlatform.current_order_token + }) + }) + + if (!response.ok) { + SolidusPaypalCommercePlatform.hideOverlay() + alert('There were some problems with your order'); + } } -SolidusPaypalCommercePlatform.addPayment = function(paypal_amount, payment_method_id, data, email) { - return Spree.ajax({ - url: '/api/checkouts/' + Spree.current_order_id + '/payments', +SolidusPaypalCommercePlatform.addPayment = async function(paypal_amount, payment_method_id, data, email) { + const response = await fetch( + `/api/checkouts/${SolidusPaypalCommercePlatform.current_order_id}/payments`, { method: 'POST', - data: { - order_token: Spree.current_order_token, + headers: { + ...authHeader(), + 'Content-Type': 'application/json' + }, + body: JSON.stringify({ + order_token: SolidusPaypalCommercePlatform.current_order_token, payment: { amount: paypal_amount, payment_method_id: payment_method_id, @@ -173,34 +230,43 @@ SolidusPaypalCommercePlatform.addPayment = function(paypal_amount, payment_metho paypal_funding_source: SolidusPaypalCommercePlatform.fundingSource } } - }, - error: function(response) { - SolidusPaypalCommercePlatform.hideOverlay() - alert('There were some problems with your payment'); - } + }) }) + + if (!response.ok) { + SolidusPaypalCommercePlatform.hideOverlay() + alert('There were some problems with your payment'); + } } -SolidusPaypalCommercePlatform.updateAddress = function(response) { - var shipping = response.purchase_units[0].shipping; - if (!shipping) return Promise.resolve({}); +SolidusPaypalCommercePlatform.updateAddress = async function(payload) { + var shipping = payload.purchase_units[0].shipping + if (!shipping) return Promise.resolve({}) - var updated_address = shipping.address; - return Spree.ajax({ - url: '/solidus_paypal_commerce_platform/update_address', - method: 'POST', - data: { - address: { - updated_address: updated_address, - recipient: response.payer + var updated_address = shipping.address + + const response = await fetch( + '/solidus_paypal_commerce_platform/update_address', { + method: 'POST', + headers: { + ...authHeader(), + 'Content-Type': 'application/json' }, - order_id: Spree.current_order_id, - order_token: Spree.current_order_token - }, - error: function(response) { - SolidusPaypalCommercePlatform.hideOverlay() - message = response.responseJSON; - alert('There were some problems with your payment address - ' + message); + body: JSON.stringify({ + address: { + updated_address: updated_address, + recipient: payload.payer + }, + order_id: SolidusPaypalCommercePlatform.current_order_id, + order_token: SolidusPaypalCommercePlatform.current_order_token + }), } - }) + ) + + if (!response.ok) { + SolidusPaypalCommercePlatform.hideOverlay() + const message = await response.text() + console.error('There were some problems with your payment address - ', message); + alert('There were some problems with your payment address - ' + message) + } } diff --git a/lib/generators/solidus_paypal_commerce_platform/install/templates/app/views/checkouts/payment/_paypal_commerce_platform.html.erb b/lib/generators/solidus_paypal_commerce_platform/install/templates/app/views/checkouts/payment/_paypal_commerce_platform.html.erb index 6ffba4b0..1ed17854 100644 --- a/lib/generators/solidus_paypal_commerce_platform/install/templates/app/views/checkouts/payment/_paypal_commerce_platform.html.erb +++ b/lib/generators/solidus_paypal_commerce_platform/install/templates/app/views/checkouts/payment/_paypal_commerce_platform.html.erb @@ -9,13 +9,14 @@ <% unless payment_method.render_only_venmo_standalone? %> @@ -23,7 +24,7 @@ <% if payment_method.venmo_standalone_enabled? %> diff --git a/lib/generators/solidus_paypal_commerce_platform/install/templates/app/views/orders/payment/_paypal_commerce_platform.html.erb b/lib/generators/solidus_paypal_commerce_platform/install/templates/app/views/orders/payment/_paypal_commerce_platform.html.erb index bc279955..5f1f2c27 100644 --- a/lib/generators/solidus_paypal_commerce_platform/install/templates/app/views/orders/payment/_paypal_commerce_platform.html.erb +++ b/lib/generators/solidus_paypal_commerce_platform/install/templates/app/views/orders/payment/_paypal_commerce_platform.html.erb @@ -6,10 +6,11 @@
diff --git a/lib/generators/solidus_paypal_commerce_platform/install/templates/app/views/products/payment/_paypal_commerce_platform.html.erb b/lib/generators/solidus_paypal_commerce_platform/install/templates/app/views/products/payment/_paypal_commerce_platform.html.erb index da9bf061..2dc034a1 100644 --- a/lib/generators/solidus_paypal_commerce_platform/install/templates/app/views/products/payment/_paypal_commerce_platform.html.erb +++ b/lib/generators/solidus_paypal_commerce_platform/install/templates/app/views/products/payment/_paypal_commerce_platform.html.erb @@ -7,7 +7,7 @@ diff --git a/lib/generators/solidus_paypal_commerce_platform/install/templates/app/views/solidus_paypal_commerce_platform/shared/_javascript_sdk_tag.html.erb b/lib/generators/solidus_paypal_commerce_platform/install/templates/app/views/solidus_paypal_commerce_platform/shared/_javascript_sdk_tag.html.erb index 18109255..f0c86d89 100644 --- a/lib/generators/solidus_paypal_commerce_platform/install/templates/app/views/solidus_paypal_commerce_platform/shared/_javascript_sdk_tag.html.erb +++ b/lib/generators/solidus_paypal_commerce_platform/install/templates/app/views/solidus_paypal_commerce_platform/shared/_javascript_sdk_tag.html.erb @@ -1,6 +1,8 @@ <% currency = @order ? @order.currency : current_pricing_options.currency %> - diff --git a/spec/system/frontend/cart_spec.rb b/spec/system/frontend/cart_spec.rb index 58b883f0..7ae41f4a 100644 --- a/spec/system/frontend/cart_spec.rb +++ b/spec/system/frontend/cart_spec.rb @@ -8,7 +8,7 @@ before do user = create(:user) order.user = user - visit spree.root_path + visit '/' click_link 'Login' fill_in 'spree_user[email]', with: user.email @@ -16,7 +16,7 @@ click_button 'Login' paypal_payment_method - allow_any_instance_of(Spree::OrdersController).to receive_messages( + allow_any_instance_of(OrdersController).to receive_messages( current_order: order, try_spree_current_user: user ) @@ -24,25 +24,25 @@ context "when generating a script tag" do it "generates a url with the correct credentials attached" do - visit '/cart' + visit '/cart/edit' expect(js_sdk_script_query).to include("client-id=#{paypal_payment_method.preferences[:client_id]}") end it "generates a partner_id attribute with the correct partner code attached" do - visit '/cart' + visit '/cart/edit' expect(js_sdk_script_partner_id).to eq("Solidus_PCP_SP") end it "generates a URL with the correct currency" do - allow(order).to receive(:currency).and_return "EUR" - visit '/cart' + order.update currency: "EUR" + visit '/cart/edit' expect(js_sdk_script_query).to include("currency=EUR") end context "when auto-capture is set to true" do it "generates a url with intent capture" do paypal_payment_method.update(auto_capture: true) - visit '/cart' + visit '/cart/edit' expect(js_sdk_script_query).to include("client-id=#{paypal_payment_method.preferences[:client_id]}") expect(js_sdk_script_query).to include("intent=capture") diff --git a/spec/system/frontend/checkout_spec.rb b/spec/system/frontend/checkout_spec.rb index 9e68b825..ed4296d4 100644 --- a/spec/system/frontend/checkout_spec.rb +++ b/spec/system/frontend/checkout_spec.rb @@ -8,7 +8,7 @@ before do user = create(:user) - visit spree.root_path + visit '/' click_link 'Login' fill_in 'spree_user[email]', with: user.email fill_in 'spree_user[password]', with: 'secret' @@ -17,7 +17,7 @@ order.recalculate paypal_payment_method - allow_any_instance_of(Spree::CheckoutController).to receive_messages( + allow_any_instance_of(CheckoutsController).to receive_messages( current_order: order, try_spree_current_user: user ) end diff --git a/spec/system/frontend/product_spec.rb b/spec/system/frontend/product_spec.rb index 154e4083..65060d0c 100644 --- a/spec/system/frontend/product_spec.rb +++ b/spec/system/frontend/product_spec.rb @@ -2,37 +2,48 @@ RSpec.describe "Product page", js: true do describe "paypal button" do - let(:paypal_payment_method) { create(:paypal_payment_method) } - let(:product) { create(:product, variants: [variant, variant_two]) } - let(:store) { create(:store) } - let(:variant) { create(:variant) } - let(:variant_two) { create(:variant) } - - before do - paypal_payment_method - end + before { create(:store, default: true) } + + let!(:paypal_payment_method) { create(:paypal_payment_method) } + let!(:variants) { + option_type = create(:option_type) + product = create(:product, option_types: [option_type], slug: 'foo-bar') + option_s = create(:option_value, option_type: option_type, presentation: 'S') + option_xs = create(:option_value, option_type: option_type, presentation: 'XS') + + [ + create(:variant, product: product, option_values: [option_s]), + create(:variant, product: product, option_values: [option_xs]), + ] + } context "when generating a script tag" do it "generates a url with the correct credentials attached" do - visit "/products/#{product.slug}" + visit "/products/foo-bar" + expect(js_sdk_script_query).to include("client-id=#{paypal_payment_method.preferences[:client_id]}") end it "generates a partner_id attribute with the correct partner code attached" do - visit "/products/#{product.slug}" + visit "/products/foo-bar" + expect(js_sdk_script_partner_id).to eq("Solidus_PCP_SP") end it "generates a URL with the correct currency" do allow_any_instance_of(SolidusPaypalCommercePlatform::PricingOptions).to receive(:currency).and_return "EUR" - visit "/products/#{product.slug}" + + visit "/products/foo-bar" + expect(js_sdk_script_query).to include("currency=EUR") end context "when auto-capture is set to true" do it "generates a url with intent capture" do paypal_payment_method.update(auto_capture: true) - visit "/products/#{product.slug}" + + visit "/products/foo-bar" + expect(js_sdk_script_query).to include("client-id=#{paypal_payment_method.preferences[:client_id]}") expect(js_sdk_script_query).to include("intent=capture") end @@ -40,62 +51,46 @@ end describe "order creation" do - before do - allow_any_instance_of(Spree::Core::ControllerHelpers::Store).to receive(:current_store) { store } - visit "/products/#{product.slug}" - - # Stubbing out paypal methods since their JS doesn't load in correctly on tests - page.execute_script("paypal = {}") - page.execute_script("paypal.render = function(){}") - page.execute_script("paypal.Buttons = function(){return paypal}") - - # Waiting until the paypal button becomes available, because the SPCP namespace - # isn't immediately available - page.find_by_id('paypal-button-container') - end - it "creates an order successfully" do + visit "/products/foo-bar" page.evaluate_script("SolidusPaypalCommercePlatform.createOrder()") - page.driver.wait_for_network_idle expect(Spree::Order.last).to be_an_instance_of(Spree::Order) end it "sets the Spree number and token variables" do + visit "/products/foo-bar" page.evaluate_script("SolidusPaypalCommercePlatform.createOrder()") - page.driver.wait_for_network_idle - expect(page.evaluate_script("Spree.current_order_id")).to eq Spree::Order.last.number - expect(page.evaluate_script("Spree.current_order_token")).to eq Spree::Order.last.guest_token + order = Spree::Order.last + expect(page.evaluate_script("SolidusPaypalCommercePlatform.current_order_id")).to eq order.number + expect(page.evaluate_script("SolidusPaypalCommercePlatform.current_order_token")).to eq order.guest_token end it "uses the specified quantity" do - quantity = 12 - fill_in('quantity', with: quantity) - + visit "/products/foo-bar" + fill_in('quantity', with: 12) page.evaluate_script("SolidusPaypalCommercePlatform.createOrder()") - page.driver.wait_for_network_idle - expect(Spree::Order.last.line_items.first.quantity).to eq quantity + expect(Spree::Order.last.line_items.first.quantity).to eq(12) end it "uses the selected variant" do - page.choose("variant_id_#{variant_two.id}") + visit "/products/foo-bar" + find('label', text: 'XS').click page.evaluate_script("SolidusPaypalCommercePlatform.createOrder()") - page.driver.wait_for_network_idle - expect(Spree::Order.last.line_items.first.variant_id).to eq variant_two.id + expect(Spree::Order.last.line_items.first.variant).to eq(variants.last) end it "assigns the order to the api token holder" do user = create(:user) user.generate_spree_api_key! - page.evaluate_script("Spree.api_key = #{user.spree_api_key.to_json}") + visit "/products/foo-bar" + page.evaluate_script("SolidusPaypalCommercePlatform.api_key = #{user.spree_api_key.to_json}") page.evaluate_script("SolidusPaypalCommercePlatform.createOrder()") - page.driver.wait_for_network_idle - expect(Spree::Order.last).to be_an_instance_of(Spree::Order) expect(Spree::Order.last.user).to eq(user) end end From 2337b77ea47ab4d22314f0cc5ab26e5ebb964482 Mon Sep 17 00:00:00 2001 From: Elia Schito Date: Mon, 21 Nov 2022 18:22:27 +0100 Subject: [PATCH 11/13] Skip product and cart buttons until there's support on SSF's side --- spec/system/frontend/cart_spec.rb | 2 +- spec/system/frontend/product_spec.rb | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/spec/system/frontend/cart_spec.rb b/spec/system/frontend/cart_spec.rb index 7ae41f4a..d563f231 100644 --- a/spec/system/frontend/cart_spec.rb +++ b/spec/system/frontend/cart_spec.rb @@ -1,7 +1,7 @@ require 'solidus_paypal_commerce_platform_spec_helper' RSpec.describe "Cart page" do - describe "paypal payment method" do + describe "paypal payment method", :skip do let(:order) { Spree::TestingSupport::OrderWalkthrough.up_to(:address) } let(:paypal_payment_method) { create(:paypal_payment_method) } diff --git a/spec/system/frontend/product_spec.rb b/spec/system/frontend/product_spec.rb index 65060d0c..608933ef 100644 --- a/spec/system/frontend/product_spec.rb +++ b/spec/system/frontend/product_spec.rb @@ -1,7 +1,7 @@ require 'solidus_paypal_commerce_platform_spec_helper' RSpec.describe "Product page", js: true do - describe "paypal button" do + describe "paypal button", :skip do before { create(:store, default: true) } let!(:paypal_payment_method) { create(:paypal_payment_method) } From 8840af2965c117742a890f32bda13823e89d46f7 Mon Sep 17 00:00:00 2001 From: Elia Schito Date: Wed, 23 Nov 2022 12:44:58 +0100 Subject: [PATCH 12/13] Fix typos in the readme --- README.md | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index f89a95bd..dac595c0 100644 --- a/README.md +++ b/README.md @@ -31,7 +31,7 @@ Since PayPal is being used as the checkout if the user checks out on the product A) Turn off cart and product page checkout - configurable on the admin payment method page for PayPal Commerce Platform. -OR- -B) Collect the users phone number seperately +B) Collect the users phone number separately and then override the `Spree::Address` method `require_phone?` to return `true`. @@ -93,6 +93,7 @@ end The instances of your wizard class should respond to `#name` and `#partial_name`, where `partial_name` will return the path to the partial you'd like to display on the wizard setup section. In our case, we just display a button to direct the user to PayPal. ## State Guesser + PayPal users can change their shipping address directly on PayPal, which will update their address on Solidus as well. However, in some instances, Solidus uses the incorrect subregion level for states, which causes validation problems @@ -101,7 +102,7 @@ with the addresses that PayPal sends to us. For instance, if your user lives in Pescara, Italy, then PayPal will return "Pescara" as the state. However on older version of Solidus, the region "Abruzzo" is used, so the address will not be able to validate. To solve this -issue, we've implented a class that attempts to guess the state of the user +issue, we've implemented a class that attempts to guess the state of the user using Carmen subregions if the state cannot be initially found. You can, of course, implement your own state guesser and set it like this: @@ -121,6 +122,7 @@ With product and cart page checkout, the user is directed to the checkout confir PayPals API does not allow for admin-side payments. Instead, backend users taking payments for customers will need to use the PayPal Virtual Terminal to take payments. [More info is available on the PayPal website.](https://www.paypal.com/merchantapps/appcenter/acceptpayments/virtualterminal?locale.x=en_US) ## Venmo + Venmo is currently available to US merchants and buyers. There are also other [prequisites](https://developer.paypal.com/docs/business/checkout/pay-with-venmo/#eligibility). If the transaction supports Venmo and it is enabled by the following, then a button should appear for it on checkout payment page. Note, Venmo cannot currently be rendered on the product or cart pages. @@ -135,6 +137,7 @@ See more about preferences([Configuration](#configuration)) below. [_As Venmo is only available in the US, you may want to mock your location for testing_](#mocking-your-buyer-country) ## Configuration + The easiest way to change the `Payment Method`'s preferences is through admin: `Settings > Payments > "PayPal Commerce Platform" > Edit`. See more about preferences [here](https://guides.solidus.io/developers/preferences/add-model-preferences.html#access-your-preferences)/ @@ -175,6 +178,7 @@ Use Ctrl-C to stop ``` ### Mocking your buyer country + PayPal normally looks at your IP geolocation to see where you are located to determine what funding sources are available to you. For example, Venmo is currently only available to US buyers. Because of this, you may want to pretend you are from US check that that Venmo is correctly integrated for these customers. To do this, set the payment method's preference of `force_buyer_country` to "US". See more information about preferences above. From 002dfe83cd096a616f4ac2df689f6d54117c52e2 Mon Sep 17 00:00:00 2001 From: Elia Schito Date: Fri, 25 Nov 2022 18:03:58 +0100 Subject: [PATCH 13/13] Use explicit options to control which components get installed Checking the installed gems is not completely reliable, especially when it comes to checking their absence. This more explicit mode allows for more control and good defaults. --- .../install/install_generator.rb | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/lib/generators/solidus_paypal_commerce_platform/install/install_generator.rb b/lib/generators/solidus_paypal_commerce_platform/install/install_generator.rb index 2458b1d2..6359f685 100644 --- a/lib/generators/solidus_paypal_commerce_platform/install/install_generator.rb +++ b/lib/generators/solidus_paypal_commerce_platform/install/install_generator.rb @@ -4,6 +4,8 @@ module SolidusPaypalCommercePlatform module Generators class InstallGenerator < Rails::Generators::Base class_option :migrate, type: :boolean, default: true + class_option :backend, type: :boolean, default: true + class_option :starter_frontend, type: :boolean, default: true class_option :specs, type: :string, enum: %w[all frontend], default: 'frontend' source_root File.expand_path('templates', __dir__) @@ -16,7 +18,7 @@ def install_solidus_core_support end def install_solidus_backend_support - support_code_for('solidus_backend') do + support_code_for(:solidus_backend) do append_file( 'vendor/assets/javascripts/spree/backend/all.js', "//= require spree/backend/solidus_paypal_commerce_platform\n" @@ -31,10 +33,7 @@ def install_solidus_backend_support end def install_solidus_starter_frontend_support - solidus_frontend_is_missing = !Bundler.locked_gems.specs.map(&:name).include?('solidus_frontend') - - # We can't do better than this for now, over time we might want to mark things differently - support_code_for('solidus_starter_frontend', run_if: solidus_frontend_is_missing) do + support_code_for(:solidus_starter_frontend) do directory 'app', 'app' append_file( 'app/assets/javascripts/solidus_starter_frontend.js', @@ -70,12 +69,12 @@ def install_solidus_starter_frontend_support private - def support_code_for(gem_name, run_if: Bundler.locked_gems.specs.map(&:name).include?(gem_name), &block) - if run_if - say_status :install, "[#{engine.engine_name}] #{gem_name} code", :blue + def support_code_for(component_name, &block) + if options[component_name] + say_status :install, "[#{engine.engine_name}] solidus_#{component_name}", :blue shell.indent(&block) else - say_status :skip, "[#{engine.engine_name}] #{gem_name} code", :blue + say_status :skip, "[#{engine.engine_name}] solidus_#{component_name}", :blue end end