- Add subsonic boolean field to products with composite filter indexes - Add TextDetector utility for detecting subsonic/casing from product titles - Wire TextDetector into SgAmmo (casing + subsonic) and LuckyGunner (subsonic + fallback casing) - Extend latest_prices_for_caliber with casing, grain_weight, and subsonic filter options - Add distinct_grain_weights_for_caliber and distinct_casings_for_caliber queries - Add filter UI with toggleable casing, grain weight, and subsonic buttons - Add grain weight column and subsonic badge to product table - Refresh filter options on PubSub price updates for real-time UI - Implement Target Sports USA scraper with 18 caliber mappings - Display all prices in dollar format ($0.38 instead of 38¢)
69 lines
2 KiB
Elixir
69 lines
2 KiB
Elixir
defmodule Ammoprices.Scraping.TextDetectorTest do
|
|
use ExUnit.Case, async: true
|
|
|
|
alias Ammoprices.Scraping.TextDetector
|
|
|
|
describe "detect_subsonic/1" do
|
|
test "detects 'subsonic' in title" do
|
|
assert TextDetector.detect_subsonic("Federal 9mm 147gr Subsonic HP") == true
|
|
end
|
|
|
|
test "detects 'sub-sonic' in title" do
|
|
assert TextDetector.detect_subsonic("Federal 9mm Sub-Sonic 147gr") == true
|
|
end
|
|
|
|
test "detects 'sub sonic' in title" do
|
|
assert TextDetector.detect_subsonic("Federal 9mm Sub Sonic 147gr") == true
|
|
end
|
|
|
|
test "is case-insensitive" do
|
|
assert TextDetector.detect_subsonic("Federal 9mm SUBSONIC 147gr") == true
|
|
end
|
|
|
|
test "returns false for non-subsonic title" do
|
|
assert TextDetector.detect_subsonic("Federal 9mm 115gr FMJ") == false
|
|
end
|
|
|
|
test "returns false for nil" do
|
|
assert TextDetector.detect_subsonic(nil) == false
|
|
end
|
|
end
|
|
|
|
describe "detect_casing/1" do
|
|
test "detects steel case" do
|
|
assert TextDetector.detect_casing("Wolf 9mm 115gr FMJ Steel Case") == "steel"
|
|
end
|
|
|
|
test "detects steel cased" do
|
|
assert TextDetector.detect_casing("Wolf 9mm 115gr FMJ Steel Cased") == "steel"
|
|
end
|
|
|
|
test "detects brass case" do
|
|
assert TextDetector.detect_casing("Blazer Brass 9mm 115gr FMJ") == "brass"
|
|
end
|
|
|
|
test "detects brass cased" do
|
|
assert TextDetector.detect_casing("Federal 9mm Brass Cased 115gr") == "brass"
|
|
end
|
|
|
|
test "detects aluminum case" do
|
|
assert TextDetector.detect_casing("CCI Aluminum Case 9mm 115gr") == "aluminum"
|
|
end
|
|
|
|
test "detects nickel plated as brass" do
|
|
assert TextDetector.detect_casing("Speer 9mm Nickel Plated 124gr") == "brass"
|
|
end
|
|
|
|
test "returns nil for no match" do
|
|
assert TextDetector.detect_casing("Federal 9mm 115gr FMJ") == nil
|
|
end
|
|
|
|
test "returns nil for nil input" do
|
|
assert TextDetector.detect_casing(nil) == nil
|
|
end
|
|
|
|
test "is case-insensitive" do
|
|
assert TextDetector.detect_casing("Wolf 9mm STEEL CASE 115gr") == "steel"
|
|
end
|
|
end
|
|
end
|