Covered prices.go with tests
This commit is contained in:
parent
90d8cc9c48
commit
b823cffe69
5 changed files with 3429 additions and 6 deletions
|
|
@ -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)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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")
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
}
|
||||
|
|
|
|||
3005
internal/cardsinfo/test_data/AcademyRuinsTest.html
Normal file
3005
internal/cardsinfo/test_data/AcademyRuinsTest.html
Normal file
File diff suppressed because it is too large
Load diff
356
internal/cardsinfo/test_data/EmptyTest.html
Normal file
356
internal/cardsinfo/test_data/EmptyTest.html
Normal file
|
|
@ -0,0 +1,356 @@
|
|||
<div>
|
||||
|
||||
<div id="hawkmetarobots"><meta name="robots" content="noindex,nofollow" /></div>
|
||||
<div id="hawkheadertitle"><title>Nosuchcardever at Star City Games</title></div>
|
||||
<div id="hawkmetadescription"></div>
|
||||
<div id="hawkmetakeywords"></div>
|
||||
<div id="hawkrelcanonical"></div>
|
||||
<div id="hawklandingpagecontent"></div>
|
||||
|
||||
<div id="hawktoptext">
|
||||
<div id="hawk-backToTop">
|
||||
<img src="//manage.hawksearch.com/sites/shared/images/top.png" />
|
||||
</div>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
</div>
|
||||
|
||||
|
||||
|
||||
<div id="hawktoppager">
|
||||
|
||||
|
||||
<div class="clearfix">
|
||||
|
||||
<div class="hawk-searchView">
|
||||
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
</div>
|
||||
|
||||
<div id="hawkitemlist">
|
||||
|
||||
|
||||
<div style="padding-top:15px;" class="hawk-">
|
||||
Search was unable to find any results for <b>"nosuchcardever"</b>, you may have typed your word incorrectly, or are being too specific. Try using a broader search phrase.
|
||||
</div>
|
||||
|
||||
|
||||
|
||||
|
||||
</div>
|
||||
|
||||
<div id="hawkbottompager">
|
||||
|
||||
|
||||
</div>
|
||||
|
||||
<div id="hawkexplain">
|
||||
|
||||
</div>
|
||||
|
||||
<div id="hawksmartbug">
|
||||
|
||||
|
||||
</div>
|
||||
|
||||
<div id="hawkrelated">
|
||||
|
||||
</div>
|
||||
|
||||
|
||||
|
||||
<div id="hawkfacets">
|
||||
<input type="hidden" id="hdnhawkcompare" value="" />
|
||||
<input type="hidden" id="hdnhawkprv" value="" />
|
||||
<input type="hidden" id="hdnhawklp" value="" />
|
||||
<input type="hidden" id="hdnhawkadv" value="" />
|
||||
<input type="hidden" id="hdnhawkit" value="" />
|
||||
<input type="hidden" id="hdnhawkoperator" value="" />
|
||||
<input type="hidden" id="hdnhawkexpand" value="" />
|
||||
<input type="hidden" id="hdnhawkkeyword" value="nosuchcardever" />
|
||||
<input type="hidden" id="hdnhawkpg" value="" />
|
||||
<input type="hidden" id="hdnhawkmpp" value="24" />
|
||||
<input type="hidden" id="hdnhawksortby" value="" />
|
||||
<input type="hidden" id="hdnhawkb" value="" />
|
||||
<input type="hidden" id="hdnhawkcustom" value="" />
|
||||
<input type="hidden" id="hdnhawkdefaultmpp" value="24" />
|
||||
<input type="hidden" id="hdnhawkkeywordfield" value="search_query" />
|
||||
<input type="hidden" id="hdnhawktrackingid" value="54966a4b-5aca-48a6-bdc6-634cac18c27b" />
|
||||
<input type="hidden" id="hdnhawkflags" value="" />
|
||||
<input type="hidden" id="hdnhawktrackingversion" value="v2" />
|
||||
<input type="hidden" id="hdnhawkaid" value="" />
|
||||
<input type="hidden" id="hdnhawkp" value="" />
|
||||
<input type="hidden" id="hdnhawkssfid" value="35158" />
|
||||
<input type="hidden" id="hdnhawkislpc" value="0" />
|
||||
<input type="hidden" id="hdnhawkislpcip" value="0" />
|
||||
<input type="hidden" id="hdnhawksearchable" value="" />
|
||||
<input type="hidden" id="hdnhawksearchablefacets" value="" />
|
||||
<div class="hawk-railNavHeading">
|
||||
Narrow Results
|
||||
</div>
|
||||
|
||||
<div class="hawkRailNav">
|
||||
<div class="hawk-guidedNavWrapper">
|
||||
|
||||
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="clear"></div>
|
||||
|
||||
</div>
|
||||
|
||||
|
||||
<div id="hawkbannertop" class="hawk-bannerTop">
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
</div>
|
||||
<div id="hawkbannertopmobile" class="bannerTopMobile">
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
</div>
|
||||
|
||||
|
||||
<div id="hawkbannerlefttop" class="hawk-bannerLeftTop">
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
</div>
|
||||
<div id="hawkbannerlefttopMobile" class="bannerLeftTopMobile">
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
</div>
|
||||
|
||||
|
||||
<div id="hawkbannerleftbottom" class="hawk-bannerLeftBottom">
|
||||
|
||||
|
||||
<div>
|
||||
<div class="TagCloud">
|
||||
|
||||
<span class="TagWeight3" title="Count: 10534"><a href="/search?keyword=blood moon">blood moon</a></span>
|
||||
<span class="TagWeight5" title="Count: 8885"><a href="/search?keyword=chrome mox">chrome mox</a></span>
|
||||
<span class="TagWeight4" title="Count: 9488"><a href="/search?keyword=demonic tutor">demonic tutor</a></span>
|
||||
<span class="TagWeight1" title="Count: 47974"><a href="/search?keyword=force of will">force of will</a></span>
|
||||
<span class="TagWeight5" title="Count: 8719"><a href="/search?keyword=grim tutor">grim tutor</a></span>
|
||||
<span class="TagWeight4" title="Count: 9751"><a href="/search?keyword=jeweled lotus">jeweled lotus</a></span>
|
||||
<span class="TagWeight5" title="Count: 8370"><a href="/search?keyword=lightning bolt">lightning bolt</a></span>
|
||||
<span class="TagWeight5" title="Count: 8885"><a href="/search?keyword=lotus cobra">lotus cobra</a></span>
|
||||
<span class="TagWeight2" title="Count: 16372"><a href="/search?keyword=mana crypt">mana crypt</a></span>
|
||||
<span class="TagWeight3" title="Count: 12372"><a href="/search?keyword=mana drain">mana drain</a></span>
|
||||
<span class="TagWeight4" title="Count: 9300"><a href="/search?keyword=mox opal">mox opal</a></span>
|
||||
<span class="TagWeight2" title="Count: 14914"><a href="/search?keyword=sol ring">sol ring</a></span>
|
||||
<span class="TagWeight3" title="Count: 12017"><a href="/search?keyword=thoughtseize">thoughtseize</a></span>
|
||||
<span class="TagWeight5" title="Count: 7886"><a href="/search?keyword=uro">uro</a></span>
|
||||
<span class="TagWeight4" title="Count: 10162"><a href="/search?keyword=vampiric tutor">vampiric tutor</a></span>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
</div>
|
||||
<div id="hawkbannerleftbottommobile" class="bannerLeftBottomMobile">
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
</div>
|
||||
|
||||
|
||||
<div id="hawkbannerbottom" class="hawk-bannerBottom">
|
||||
|
||||
|
||||
|
||||
<p><span style="background-color:#ffff00;"></span></p><span style="font-size:14px;"> - Please double check your spelling.</span><br style="font-size:14px;" /><span style="font-size:14px;"> - Try searching for an item that is less specific.</span><br style="font-size:14px;" /><span style="font-size:14px;"> - You can always narrow your search results later. </span><span style="background-color:#ffff00;"></span><span style="background-color:#ffff00;"><br /></span><p><span style="background-color:#ffff00;"></span><span style="background-color:#ffff00;"><br /></span><br /></p>
|
||||
|
||||
|
||||
|
||||
</div>
|
||||
<div id="hawkbannerbottomMobile" class="bannerBottomMobile">
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
</div>
|
||||
|
||||
|
||||
<div id="hawkbannerbottom2" class="hawk-bannerBottom2"><div id="ctl00_BannerBottom2_FeaturedBottom2_titleDiv" class="hawk-featured-title">Popular Items</div>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<div class="grid_3 " >
|
||||
<div class="itemWrapper hawk-itemWrapper">
|
||||
|
||||
<a href="/rathi-dragon-sgl-mtg-9ed-210-jaf/" id="ctl00_BannerBottom2_FeaturedBottom2_lvItems_ctrl0_ctl00_item_lnk1" class="itemLink" onclick="return HawkSearch.link(event,'54966a4b-5aca-48a6-bdc6-634cac18c27b',1,'99998',0);">
|
||||
<img class="itemImage hawk-itemImage" src="" alt="" style="height:190px;" />
|
||||
</a>
|
||||
<h3 class="itemTitle">
|
||||
<em style="display: block;"></em>
|
||||
<a href="/rathi-dragon-sgl-mtg-9ed-210-jaf/" id="ctl00_BannerBottom2_FeaturedBottom2_lvItems_ctrl0_ctl00_item_lnk2" onclick="return HawkSearch.link(event,'54966a4b-5aca-48a6-bdc6-634cac18c27b',1,'99998',0);">Rathi Dragon</a>
|
||||
</h3>
|
||||
<span class="itemSku">SGL-MTG-9ED-210-JAF</span>
|
||||
<p class="itemDesc"></p>
|
||||
<p class="itemPrice">
|
||||
$19.99
|
||||
|
||||
</p>
|
||||
<div class="clearfix">
|
||||
|
||||
</div>
|
||||
|
||||
<div class="clearfix">
|
||||
<div class="itemButtons clearfix">
|
||||
<a href="/rathi-dragon-sgl-mtg-9ed-210-jaf/" id="ctl00_BannerBottom2_FeaturedBottom2_lvItems_ctrl0_ctl00_item_lnk3" class="btnWrapper" onclick="return HawkSearch.link(event,'54966a4b-5aca-48a6-bdc6-634cac18c27b',1,'99998',0);"><span class="btn">View Details</span></a>
|
||||
|
||||
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
|
||||
<div class="grid_3 " >
|
||||
<div class="itemWrapper hawk-itemWrapper">
|
||||
|
||||
<a href="/rathi-dragon-sgl-mtg-9ed-210-zsf/" id="ctl00_BannerBottom2_FeaturedBottom2_lvItems_ctrl0_ctl01_item_lnk1" class="itemLink" onclick="return HawkSearch.link(event,'54966a4b-5aca-48a6-bdc6-634cac18c27b',2,'99996',0);">
|
||||
<img class="itemImage hawk-itemImage" src="" alt="" style="height:190px;" />
|
||||
</a>
|
||||
<h3 class="itemTitle">
|
||||
<em style="display: block;"></em>
|
||||
<a href="/rathi-dragon-sgl-mtg-9ed-210-zsf/" id="ctl00_BannerBottom2_FeaturedBottom2_lvItems_ctrl0_ctl01_item_lnk2" onclick="return HawkSearch.link(event,'54966a4b-5aca-48a6-bdc6-634cac18c27b',2,'99996',0);">Rathi Dragon</a>
|
||||
</h3>
|
||||
<span class="itemSku">SGL-MTG-9ED-210-ZSF</span>
|
||||
<p class="itemDesc"></p>
|
||||
<p class="itemPrice">
|
||||
$14.99
|
||||
|
||||
</p>
|
||||
<div class="clearfix">
|
||||
|
||||
</div>
|
||||
|
||||
<div class="clearfix">
|
||||
<div class="itemButtons clearfix">
|
||||
<a href="/rathi-dragon-sgl-mtg-9ed-210-zsf/" id="ctl00_BannerBottom2_FeaturedBottom2_lvItems_ctrl0_ctl01_item_lnk3" class="btnWrapper" onclick="return HawkSearch.link(event,'54966a4b-5aca-48a6-bdc6-634cac18c27b',2,'99996',0);"><span class="btn">View Details</span></a>
|
||||
|
||||
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
|
||||
<div class="grid_3 " >
|
||||
<div class="itemWrapper hawk-itemWrapper">
|
||||
|
||||
<a href="/rathi-dragon-sgl-mtg-9ed-210-enn/" id="ctl00_BannerBottom2_FeaturedBottom2_lvItems_ctrl0_ctl02_item_lnk1" class="itemLink" onclick="return HawkSearch.link(event,'54966a4b-5aca-48a6-bdc6-634cac18c27b',3,'99995',0);">
|
||||
<img class="itemImage hawk-itemImage" src="https://cdn11.bigcommerce.com/s-3b5vpig99v/products/99995/images/402488/RathiDragon__87752.1590611958.386.513.jpg?c=2" alt="" style="height:190px;" />
|
||||
</a>
|
||||
<h3 class="itemTitle">
|
||||
<em style="display: block;"></em>
|
||||
<a href="/rathi-dragon-sgl-mtg-9ed-210-enn/" id="ctl00_BannerBottom2_FeaturedBottom2_lvItems_ctrl0_ctl02_item_lnk2" onclick="return HawkSearch.link(event,'54966a4b-5aca-48a6-bdc6-634cac18c27b',3,'99995',0);">Rathi Dragon</a>
|
||||
</h3>
|
||||
<span class="itemSku">SGL-MTG-9ED-210-ENN</span>
|
||||
<p class="itemDesc"></p>
|
||||
<p class="itemPrice">
|
||||
$0.49
|
||||
|
||||
</p>
|
||||
<div class="clearfix">
|
||||
|
||||
</div>
|
||||
|
||||
<div class="clearfix">
|
||||
<div class="itemButtons clearfix">
|
||||
<a href="/rathi-dragon-sgl-mtg-9ed-210-enn/" id="ctl00_BannerBottom2_FeaturedBottom2_lvItems_ctrl0_ctl02_item_lnk3" class="btnWrapper" onclick="return HawkSearch.link(event,'54966a4b-5aca-48a6-bdc6-634cac18c27b',3,'99995',0);"><span class="btn">View Details</span></a>
|
||||
|
||||
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
</div>
|
||||
<div id="hawkbannerbottom2Mobile" class="bannerBottom2Mobile">
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
</div>
|
||||
|
||||
|
||||
<div id="hawkbreadcrumb"><div class="breadcrumbs"><div class="brmbwrpr"><span><a href="https://starcitygames.com/search">Home</a></span> > <span><a href="https://starcitygames.com/search?keyword=nosuchcardever"><b>nosuchcardever</b></a></span></div></div></div>
|
||||
|
||||
|
||||
<div id="hawktitle">
|
||||
<h1 class="hdng" id="pageHeading" >Search Results for Nosuchcardever</h1>
|
||||
</div>
|
||||
|
||||
|
||||
|
||||
|
||||
</div>
|
||||
|
||||
Loading…
Add table
Add a link
Reference in a new issue