ammocpr/test/ammoprices/scraping/scrape_job_test.exs
Graham McIntire 16a28ac01c
Add Target Sports USA scraper, product filtering, and subsonic detection
- 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¢)
2026-03-11 16:28:04 -05:00

35 lines
1,008 B
Elixir

defmodule Ammoprices.Scraping.ScrapeJobTest do
use Ammoprices.DataCase
use Oban.Testing, repo: Ammoprices.Repo
import Ammoprices.Fixtures
alias Ammoprices.Scraping.ScrapeJob
@fixture_html File.read!("test/fixtures/lucky_gunner/9mm.html")
setup do
retailer_fixture(%{name: "Lucky Gunner", slug: "lucky-gunner", base_url: "https://www.luckygunner.com"})
retailer_fixture(%{name: "SGAmmo", slug: "sgammo", base_url: "https://www.sgammo.com"})
retailer_fixture(%{
name: "Target Sports USA",
slug: "target-sports-usa",
base_url: "https://www.targetsportsusa.com"
})
caliber_fixture(%{name: "9mm Luger", slug: "9mm-luger", category: "handgun", aliases: ["9mm", "9x19"]})
Req.Test.stub(Ammoprices.Scraping.HttpClient, fn conn ->
Req.Test.html(conn, @fixture_html)
end)
:ok
end
describe "perform/1" do
test "executes scrape for all enabled scrapers and calibers" do
assert :ok = perform_job(ScrapeJob, %{})
end
end
end