Remove surrounding whitespace from pasted DFC URL

This commit is contained in:
Maikel Linke
2025-02-25 15:55:34 +11:00
parent b6153fc155
commit 9d5ce0ede5
2 changed files with 7 additions and 8 deletions

View File

@@ -15,7 +15,7 @@ module Admin
def index
# Fetch DFC catalog JSON for preview
api = DfcRequest.new(spree_current_user)
@catalog_url = params.require(:catalog_url)
@catalog_url = params.require(:catalog_url).strip
@catalog_json = api.call(@catalog_url)
graph = DfcIo.import(@catalog_json)
catalog = DfcCatalog.new(graph)

View File

@@ -20,18 +20,17 @@ RSpec.describe "DFC Product Import" do
it "imports from given catalog" do
visit admin_product_import_path
# We are testing against our own catalog for now but we want to replace
# this with the URL of another app when available.
# We also add a common mistake: copying the URL with an extra space.
host = Rails.application.default_url_options[:host]
url = " http://#{host}/api/dfc/enterprises/#{enterprise.id}/catalog_items"
fill_in "catalog_url", with: url
fill_in "catalog_url", with: "invalid url"
select enterprise.name, from: "Create products for enterprise"
click_button "Preview"
expect(page).to have_content "This catalog URL is not valid"
url = "http://#{host}/api/dfc/enterprises/#{enterprise.id}/catalog_items"
# We are testing against our own catalog for now but we want to replace
# this with the URL of another app when available.
# We also add a common mistake: copying the URL with an extra space.
host = Rails.application.default_url_options[:host]
url = " http://#{host}/api/dfc/enterprises/#{enterprise.id}/catalog_items"
fill_in "catalog_url", with: url
select enterprise.name, from: "Create products for enterprise"
click_button "Preview"