diff --git a/internal/cardsinfo/names_test.go b/internal/cardsinfo/names_test.go index f93dd60..436eccc 100644 --- a/internal/cardsinfo/names_test.go +++ b/internal/cardsinfo/names_test.go @@ -40,6 +40,7 @@ func TestGetOriginalName_Dict(t *testing.T) { name := GetOriginalName("card", dict) assert.Equal(t, "Card", name) } + func TestGetOriginalName_BadJson(t *testing.T) { defer gock.Off() @@ -47,3 +48,14 @@ func TestGetOriginalName_BadJson(t *testing.T) { name := GetOriginalName("card", nil) assert.Equal(t, "", name) } + +func TestGetOriginalName_DoubleSide(t *testing.T) { + defer gock.Off() + + gock.New(ScryfallUrl + "/cards/named?fuzzy=card").Reply(http.StatusOK).JSON(Card{ + Name: "Legion's Landing // Adanto, the First Fort", + Layout: "transform", + }) + name := GetOriginalName("card", nil) + assert.Equal(t, "Legion's Landing | Adanto, the First Fort", name) +} diff --git a/internal/cardsinfo/prices.go b/internal/cardsinfo/prices.go index 541f06a..774b5fe 100644 --- a/internal/cardsinfo/prices.go +++ b/internal/cardsinfo/prices.go @@ -1,7 +1,6 @@ package cardsinfo import ( - "fmt" "net/url" "github.com/antchfx/htmlquery" @@ -9,7 +8,7 @@ import ( ) const scgDomain = "https://starcitygames.com" -const scgSearchUrlTemplate = "https://starcitygames.hawksearch.com/sites/starcitygames/?search_query=%v" +const scgSearchUrlTemplate = "https://starcitygames.hawksearch.com/sites/starcitygames/?search_query=" func GetPrices(name string) ([]CardPrice, error) { prices, err := GetPricesScg(name) @@ -24,7 +23,7 @@ func GetPrices(name string) ([]CardPrice, error) { func GetPricesScg(name string) ([]CardPrice, error) { escapedName := url.QueryEscape(name) - searchUrl := fmt.Sprintf(scgSearchUrlTemplate, escapedName) + searchUrl := scgSearchUrlTemplate + escapedName node, err := htmlquery.LoadURL(searchUrl) if err != nil { return nil, errors.Wrap(err, "cannot load url") diff --git a/internal/cardsinfo/prices_test.go b/internal/cardsinfo/prices_test.go index f85b70a..6435597 100644 --- a/internal/cardsinfo/prices_test.go +++ b/internal/cardsinfo/prices_test.go @@ -1,13 +1,64 @@ package cardsinfo import ( + "gopkg.in/h2non/gock.v1" + "net/http" + "os" "testing" "github.com/stretchr/testify/assert" ) -func TestParser(t *testing.T) { - prices, err := GetPrices("Black lotus") +func TestGetPrices_Ok(t *testing.T) { + defer gock.Off() + + file, _ := os.Open("test_data/AcademyRuinsTest.html") + gock.New(scgSearchUrlTemplate + "card").Reply(http.StatusOK).Body(file) + prices, err := GetPrices("card") assert.Nil(t, err) - assert.NotEmpty(t, prices) + assert.Equal(t, []CardPrice{ + &ScgCardPrice{ + Price: "$6.99", + Edition: "Double Masters", + Link: "https://starcitygames.com/academy-ruins-sgl-mtg-2xm-309-enn/?sku=SGL-MTG-2XM-309-ENN1", + }, + &ScgCardPrice{ + Price: "$9.99", + Edition: "Double Masters (Foil)", + Link: "https://starcitygames.com/academy-ruins-sgl-mtg-2xm-309-enf/?sku=SGL-MTG-2XM-309-ENF1", + }, + &ScgCardPrice{ + Price: "$11.99", + Edition: "Double Masters - Variants", + Link: "https://starcitygames.com/academy-ruins-sgl-mtg-2xm2-369-enn/?sku=SGL-MTG-2XM2-369-ENN1", + }, + &ScgCardPrice{ + Price: "$14.99", + Edition: "Double Masters - Variants (Foil)", + Link: "https://starcitygames.com/academy-ruins-sgl-mtg-2xm2-369-enf/?sku=SGL-MTG-2XM2-369-ENF1", + }, + &ScgCardPrice{ + Price: "$7.99", + Edition: "Modern Masters: 2013 Edition", + Link: "https://starcitygames.com/academy-ruins-sgl-mtg-mma-219-enn/?sku=SGL-MTG-MMA-219-ENN1", + }, + }, prices) +} + +func TestGetPrices_Unavailable(t *testing.T) { + defer gock.Off() + + gock.New(scgSearchUrlTemplate + "card").Reply(http.StatusBadGateway) + _, err := GetPrices("card") + assert.NotNil(t, err) +} + +func TestGetPrices_Empty(t *testing.T) { + defer gock.Off() + + file, _ := os.Open("test_data/EmptyTest.html") + gock.New(scgSearchUrlTemplate + "card").Reply(http.StatusOK).Body(file) + prices, err := GetPrices("card") + assert.Nil(t, err) + assert.Nil(t, prices) } diff --git a/internal/cardsinfo/test_data/AcademyRuinsTest.html b/internal/cardsinfo/test_data/AcademyRuinsTest.html new file mode 100644 index 0000000..16102be --- /dev/null +++ b/internal/cardsinfo/test_data/AcademyRuinsTest.html @@ -0,0 +1,3005 @@ +
+ +
+
Academy Ruins at Star City Games
+
+
+
+
+ +
+
+ +
+ + + + + + +
+ + + +
+ + +
+ +
+ +
+
+ + + + + + + + + +
+
+
+ +
+ Showing 1 - 8 of 8 +
+
+ + +
+ +
+ +
+ +
+ + +
+ +
+ + + + + + Page 1 of 1 +
+
+
+ + + + +
+ + +
+ +
+ + + + + + + + +
+
+ +
+
+ +
+
+
+ +
+
+
+ + + + +
+
+
+
+
+ +
+
+ Near Mint - English + Flag + +
+
$5.94$6.99
+
QTY: 1
+
+ +
+ + + +
+ +
+ + +
+
+ +
+
+
+ +
+ + + +
+
The qty you entered is invalid. Please try again.
+
+
+ +
+
+
+
    +
  • + + +
  • +
+
+
+
+
+ + +
+ +
+
+ +
+ + +
+ +
+ + + +
+
+
+
+ + + + +
+
+ +
+
+ +
+
+
+ +
+
+
+ + + + +
+
+
+
+
+ +
+
+ Near Mint - English + Flag + +
+
$8.49$9.99
+
QTY: 13
+
+ +
+ + + +
+ +
+ + +
+
+ +
+
+
+ +
+ + + +
+
The qty you entered is invalid. Please try again.
+
+
+ +
+
+
+
    +
  • + + +
  • +
+
+
+
+
+ + +
+ +
+
+ +
+ + +
+ +
+ + + +
+
+
+
+ + + + +
+ + +
+
+
+ + + + +
+
+
+
+
+ +
+
+ Near Mint - English + Flag + +
+
$10.19$11.99
+
QTY: 12
+
+ +
+ + + +
+ +
+ + +
+
+ +
+
+
+ +
+ + + +
+
The qty you entered is invalid. Please try again.
+
+
+ +
+
+
+
    +
  • + + +
  • +
+
+
+
+
+ + +
+ +
+
+ +
+ + +
+ +
+ + + +
+
+
+
+ + + + +
+ + +
+
+
+ + + + +
+
+
+
+
+ +
+
+ Near Mint - English + Flag + +
+
$12.74$14.99
+
QTY: 0
+
+ +
+ + +
+ +
+
+ +
+ + +
+ +
+ + + +
+
+
+
+ + + + + + +
+ + +
+
+
+ + + + +
+
+
+
+
+ +
+
+ Near Mint - English + Flag + +
+
$6.79$7.99
+
QTY: 6
+
+ +
+ + + +
+ +
+ + +
+
+ +
+
+
+ +
+ + + +
+
The qty you entered is invalid. Please try again.
+
+
+ +
+
+
+
    +
  • + + +
  • +
+
+
+
+
+ + +
+ +
+
+ +
+
+ Played - English + Flag + +
+
$5.82$6.85
+
QTY: 1
+
+ +
+ + + +
+ +
+ + +
+
+ +
+
+
+ +
+ + + +
+
The qty you entered is invalid. Please try again.
+
+
+ +
+
+
+
    +
  • + + +
  • +
+
+
+
+
+ + +
+ +
+
+ +
+ + +
+ +
+ + + +
+
+
+
+ + + + +
+ + +
+
+
+ + + + +
+
+
+
+
+ +
+
+ Near Mint - English + Flag + +
+
$13.59$15.99
+
QTY: 3
+
+ +
+ + + +
+ +
+ + +
+
+ +
+
+
+ +
+ + + +
+
The qty you entered is invalid. Please try again.
+
+
+ +
+
+
+
    +
  • + + +
  • +
+
+
+
+
+ + +
+ +
+
+ +
+ + +
+ +
+ + + +
+
+
+
+ + + + +
+
+ +
+
+ +
+
+
+ +
+
+
+ + + + +
+
+
+
+
+ +
+
+ Near Mint - English + Flag + +
+
$7.64$8.99
+
QTY: 4
+
+ +
+ + + +
+ +
+ + +
+
+ +
+
+
+ +
+ + + +
+
The qty you entered is invalid. Please try again.
+
+
+ +
+
+
+
    +
  • + + +
  • +
+
+
+
+
+ + +
+ +
+
+ +
+
+ Played - English + Flag + +
+
$6.54$7.69
+
QTY: 39
+
+ +
+ + + +
+ +
+ + +
+
+ +
+
+
+ +
+ + + +
+
The qty you entered is invalid. Please try again.
+
+
+ +
+
+
+
    +
  • + + +
  • +
+
+
+
+
+ + +
+ +
+
+ +
+ +
+ + +
+ +
+
+ Near Mint - Chinese - Simplified + Flag + +
+
$6.11$7.19
+
+
QTY: 3
+
+ +
+ + + +
+ +
+ + +
+
+ +
+
+
+ +
+ + + +
+
The qty you entered is invalid. Please try again.
+
+
+ +
+
+
+
    +
  • + + +
  • +
+
+
+
+
+ + +
+ +
+
+ +
+
+ Played - Chinese - Simplified + Flag + +
+
$5.23$6.15
+
+
QTY: 4
+
+ +
+ + + +
+ +
+ + +
+
+ +
+
+
+ +
+ + + +
+
The qty you entered is invalid. Please try again.
+
+
+ +
+
+
+
    +
  • + + +
  • +
+
+
+
+
+ + +
+ +
+
+ +
+
+ Near Mint - French + Flag + +
+
$5.74$6.75
+
+
QTY: 13
+
+ +
+ + + +
+ +
+ + +
+
+ +
+
+
+ +
+ + + +
+
The qty you entered is invalid. Please try again.
+
+
+ +
+
+
+
    +
  • + + +
  • +
+
+
+
+
+ + +
+ +
+
+ +
+
+ Played - French + Flag + +
+
$4.92$5.79
+
+
QTY: 4
+
+ +
+ + + +
+ +
+ + +
+
+ +
+
+
+ +
+ + + +
+
The qty you entered is invalid. Please try again.
+
+
+ +
+
+
+
    +
  • + + +
  • +
+
+
+
+
+ + +
+ +
+
+ +
+
+ Near Mint - Italian + Flag + +
+
$5.74$6.75
+
+
QTY: 7
+
+ +
+ + + +
+ +
+ + +
+
+ +
+
+
+ +
+ + + +
+
The qty you entered is invalid. Please try again.
+
+
+ +
+
+
+
    +
  • + + +
  • +
+
+
+
+
+ + +
+ +
+
+ +
+
+ Played - Italian + Flag + +
+
$4.92$5.79
+
+
QTY: 8
+
+ +
+ + + +
+ +
+ + +
+
+ +
+
+
+ +
+ + + +
+
The qty you entered is invalid. Please try again.
+
+
+ +
+
+
+
    +
  • + + +
  • +
+
+
+
+
+ + +
+ +
+
+ +
+
+ Near Mint - Portuguese + Flag + +
+
$5.74$6.75
+
+
QTY: 3
+
+ +
+ + + +
+ +
+ + +
+
+ +
+
+
+ +
+ + + +
+
The qty you entered is invalid. Please try again.
+
+
+ +
+
+
+
    +
  • + + +
  • +
+
+
+
+
+ + +
+ +
+
+ +
+
+ Played - Portuguese + Flag + +
+
$4.92$5.79
+
+
QTY: 1
+
+ +
+ + + +
+ +
+ + +
+
+ +
+
+
+ +
+ + + +
+
The qty you entered is invalid. Please try again.
+
+
+ +
+
+
+
    +
  • + + +
  • +
+
+
+
+
+ + +
+ +
+
+ +
+
+ Near Mint - Russian + Flag + +
+
$11.25 +
+
QTY: 3
+
+ +
+ + + +
+ +
+ + +
+
+ +
+
+
+ +
+ + + +
+
The qty you entered is invalid. Please try again.
+
+
+ +
+
+
+
    +
  • + + +
  • +
+
+
+
+
+ + +
+ +
+
+ +
+
+ Played - Russian + Flag + +
+
$8.15$9.59
+
+
QTY: 5
+
+ +
+ + + +
+ +
+ + +
+
+ +
+
+
+ +
+ + + +
+
The qty you entered is invalid. Please try again.
+
+
+ +
+
+
+
    +
  • + + +
  • +
+
+
+
+
+ + +
+ +
+
+ +
+
+ Near Mint - Spanish + Flag + +
+
$5.74$6.75
+
+
QTY: 5
+
+ +
+ + + +
+ +
+ + +
+
+ +
+
+
+ +
+ + + +
+
The qty you entered is invalid. Please try again.
+
+
+ +
+
+
+
    +
  • + + +
  • +
+
+
+
+
+ + +
+ +
+
+ +
+
+ Played - Spanish + Flag + +
+
$4.92$5.79
+
+
QTY: 3
+
+ +
+ + + +
+ +
+ + +
+
+ +
+
+
+ +
+ + + +
+
The qty you entered is invalid. Please try again.
+
+
+ +
+
+
+
    +
  • + + +
  • +
+
+
+
+
+ + +
+ +
+
+ +
+ + + +
+
+
+
+ + + + +
+
+ +
+
+ +
+
+
+ +
+
+
+ + + + +
+
+
+
+
+ +
+
+ Near Mint - English + Flag + +
+
$63.74$74.99
+
QTY: 0
+
+ +
+ + +
+ +
+
+ +
+
+ Played - English + Flag + +
+
$42.49$49.99
+
QTY: 3
+
+ +
+ + + +
+ +
+ + +
+
+ +
+
+
+ +
+ + + +
+
The qty you entered is invalid. Please try again.
+
+
+ +
+
+
+
    +
  • + + +
  • +
+
+
+
+
+ + +
+ +
+
+ +
+ +
+ + +
+ +
+
+ Near Mint - French + Flag + +
+
$50.99$59.99
+
+
QTY: 1
+
+ +
+ + + +
+ +
+ + +
+
+ +
+
+
+ +
+ + + +
+
The qty you entered is invalid. Please try again.
+
+
+ +
+
+
+
    +
  • + + +
  • +
+
+
+
+
+ + +
+ +
+
+ +
+
+ Played - French + Flag + +
+
$33.99$39.99
+
+
QTY: 2
+
+ +
+ + + +
+ +
+ + +
+
+ +
+
+
+ +
+ + + +
+
The qty you entered is invalid. Please try again.
+
+
+ +
+
+
+
    +
  • + + +
  • +
+
+
+
+
+ + +
+ +
+
+ +
+
+ Played - Italian + Flag + +
+
$33.99$39.99
+
+
QTY: 3
+
+ +
+ + + +
+ +
+ + +
+
+ +
+
+
+ +
+ + + +
+
The qty you entered is invalid. Please try again.
+
+
+ +
+
+
+
    +
  • + + +
  • +
+
+
+
+
+ + +
+ +
+
+ +
+
+ Played - Spanish + Flag + +
+
$33.99$39.99
+
+
QTY: 1
+
+ +
+ + + +
+ +
+ + +
+
+ +
+
+
+ +
+ + + +
+
The qty you entered is invalid. Please try again.
+
+
+ +
+
+
+
    +
  • + + +
  • +
+
+
+
+
+ + +
+ +
+
+ +
+ + + +
+
+
+
+ + + + + + + + + +
+ +
+ + +
+
+
+ +
+ Showing 1 - 8 of 8 +
+
+ + +
+ +
+ +
+ +
+ + +
+ +
+ + + + + + Page 1 of 1 +
+
+
+ + + + +
+ + +
+ +
+ +
+ +
+ + +
+ +
+ +
+ + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + +
+ Narrow Results +
+ +
+
+ +
+

+ In Stock Only + +

+
+ + + + +
+
+
+

+ Product Type + +

+
+ + + + +
+
+
+

+ Finish + +

+
+ + + + +
+
+
+

+ Condition + +

+
+ + + + +
+
+
+

+ Rarity + +

+
+ + + + +
+
+
+

+ Language + +

+ +
+
+

+ Color + +

+
+ + + + +
+
+ +
+

+ Tournament Legality + +

+
+ + + + +
+
+ +
+
+ +
+ +
+ + +
+ + + + + + + +
+
+ + + + + + + +
+ + +
+ + + + + + + +
+
+ + + + + + + +
+ + +
+ + + + + + + +
+
+ + + + + + + +
+ + +
+ + + + + + + +
+
+ + + + + + + +
+ + +
+ + + + + + + +
+
+ + + + + + + +
+ + +
+ + +
+

Search Results for Academy Ruins

+
+ + + + +
+ diff --git a/internal/cardsinfo/test_data/EmptyTest.html b/internal/cardsinfo/test_data/EmptyTest.html new file mode 100644 index 0000000..755aec3 --- /dev/null +++ b/internal/cardsinfo/test_data/EmptyTest.html @@ -0,0 +1,356 @@ +
+ +
+
Nosuchcardever at Star City Games
+
+
+
+
+ +
+
+ +
+ + + + + + +
+ + + +
+ + +
+ +
+ +
+
+ + + + + + + + + +
+ +
+ + +
+ Search was unable to find any results for "nosuchcardever", you may have typed your word incorrectly, or are being too specific. Try using a broader search phrase. +
+ + + + +
+ +
+ + +
+ +
+ +
+ +
+ + +
+ +
+ +
+ + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + +
+ Narrow Results +
+ +
+
+ + +
+
+ +
+ +
+ + +
+ + + + + + + +
+
+ + + + + + + +
+ + +
+ + + + + + + +
+
+ + + + + + + +
+ + +
+ + +
+ +
+ + + + + +
+
+ + + + + + + +
+ + +
+ + + +

 - Please double check your spelling.
 - Try searching for an item that is less specific.
 - You can always narrow your search results later. 



+ + + +
+
+ + + + + + + +
+ + +
+ + + + + + +
+
+ + + + +

+ + Rathi Dragon +

+ SGL-MTG-9ED-210-JAF +

+

+ $19.99 + +

+
+ +
+ +
+
+ View Details + + +
+
+
+
+ + + +
+
+ + + + +

+ + Rathi Dragon +

+ SGL-MTG-9ED-210-ZSF +

+

+ $14.99 + +

+
+ +
+ +
+
+ View Details + + +
+
+
+
+ + + +
+
+ + + + +

+ + Rathi Dragon +

+ SGL-MTG-9ED-210-ENN +

+

+ $0.49 + +

+
+ +
+ +
+
+ View Details + + +
+
+
+
+ + + + + + + + + + + + + + + +
+
+ + + + + + + +
+ + +
+ + +
+

Search Results for Nosuchcardever

+
+ + + + +
+