Skip to content

A platform for community discussion. Free, open, simple.

FIX: Show Amazon prices below one dollar

Régis Hanolcbfcdf5e2d7e
diff --git a/lib/onebox/engine/amazon_onebox.rb b/lib/onebox/engine/amazon_onebox.rb
index f7454353a53..a1ce356fa99 100644
--- a/lib/onebox/engine/amazon_onebox.rb
+++ b/lib/onebox/engine/amazon_onebox.rb
@@ -122,7 +122,7 @@ module Onebox
text("#corePrice_feature_div .a-price .a-offscreen") ||
text(".mediaMatrixListItem.a-active .a-color-price")
- amount unless amount&.start_with?("$0")
+ amount if amount&.match?(/[1-9]/)
end
def text(path)
diff --git a/spec/lib/onebox/engine/amazon_onebox_spec.rb b/spec/lib/onebox/engine/amazon_onebox_spec.rb
index a0b02fb9a0c..d0ec8f6123e 100644
--- a/spec/lib/onebox/engine/amazon_onebox_spec.rb
+++ b/spec/lib/onebox/engine/amazon_onebox_spec.rb
@@ -124,7 +124,7 @@ RSpec.describe Onebox::Engine::AmazonOnebox do
stub_request(:get, link).to_return(
status: 200,
body:
- "<html><head><title>SwiftJet Car Wash Foam Gun</title><meta name='description' content='Foam gun'><link rel='canonical' href='https://www.amazon.com/clp/B082SBHKN2'></head><body><img id='landingImage' data-old-hires='' src='#{image}'></body></html>",
+ "<html><head><title>SwiftJet Car Wash Foam Gun</title><meta name='description' content='Foam gun'><link rel='canonical' href='https://www.amazon.com/clp/B082SBHKN2'></head><body><img id='landingImage' data-old-hires='' src='#{image}'><div id='corePrice_feature_div'><span class='a-price'><span class='a-offscreen'>$0.99</span></span></div></body></html>",
)
stub_request(:get, "https://www.amazon.com/clp/B082SBHKN2").to_return(
@@ -134,7 +134,12 @@ RSpec.describe Onebox::Engine::AmazonOnebox do
end
it "renders the product page" do
- expect(html).to include("SwiftJet Car Wash Foam Gun", %(href="#{link}"), %(src="#{image}"))
+ expect(html).to include(
+ "SwiftJet Car Wash Foam Gun",
+ %(href="#{link}"),
+ %(src="#{image}"),
+ "$0.99",
+ )
end
end