123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120 |
- package wordpress
- import (
- "commerce-crwaler/util"
- "github.com/stretchr/testify/assert"
- "os"
- "testing"
- )
- func TestGetImages(t *testing.T) {
- body, err := util.Get("https://seoulknit.com/shop/collar-half-sleeved-top_blue/")
- assert.Equal(t, nil, err)
- imgs := getImages(body)
- assert.Equal(t, "https://seoulknit.com/wp-content/uploads/2021/05/abito_0594-scaled-454x681.jpg", imgs[0])
- assert.Equal(t, "https://seoulknit.com/wp-content/uploads/2021/05/abito_0594-scaled-100x100.jpg", imgs[1])
- body, err = util.Get("https://www.dollshecraft.com/product/amanda-beauty-26f-classic-maxi-65cm-special-package-2/")
- assert.Equal(t, nil, err)
- imgs = getImages(body)
- assert.Equal(t, "https://cdn.dollshecraft.com/wp-content/uploads/2018/08/Amanda-Beauty_558743_01.jpg", imgs[0])
- body, err = util.Get("https://www.shoprootscience.com/shop/arctic-c-vitamin-c-serum")
- assert.Equal(t, nil, err)
- imgs = getImages(body)
- assert.Equal(t, "https://www.shoprootscience.com/wp-content/uploads/2020/10/Arctic-C-product-511x634.jpg", imgs[0])
- assert.Equal(t, "https://www.shoprootscience.com/wp-content/uploads/2020/10/Arctic-C-product.jpg", imgs[1])
- body, err = util.Get("https://strandbergguitars.com/product/boden-6-dr-titanium/")
- assert.Equal(t, nil, err)
- imgs = getImages(body)
- assert.Equal(t, "https://strandbergguitars.com/cdn-cgi/image/onerror=redirect,quality=85,format=auto,metadata=copyright,width=600,height=901,fit=cover/wp-content/uploads/2021/04/bd6ct-20dr-k-p-ti_6.png", imgs[0])
- body, err = util.Get("https://lanbelle.com/product/%EB%9E%91%EB%B2%A8-%EC%88%98%ED%8D%BC%EB%82%B4%EC%B8%84%EB%9F%B4-%ED%81%AC%EB%A6%BC/")
- assert.Equal(t, nil, err)
- imgs = getImages(body)
- assert.Equal(t, "https://strandbergguitars.com/cdn-cgi/image/onerror=redirect,quality=85,format=auto,metadata=copyright,width=600,height=901,fit=cover/wp-content/uploads/2021/04/bd6ct-20dr-k-p-ti_6.png", imgs[0])
- }
- func TestGetPrice(t *testing.T) {
- body, err := util.Get("https://seoulknit.com/shop/collar-half-sleeved-top_blue/")
- assert.Equal(t, nil, err)
- ret := getPrice(body)
- assert.Equal(t, "₩ 59,000", ret)
- body, err = util.Get("https://www.dollshecraft.com/product/amanda-beauty-26f-classic-maxi-65cm-special-package-2/")
- assert.Equal(t, nil, err)
- ret = getPrice(body)
- assert.Equal(t, "$1,450.00", ret)
- body, err = util.Get("https://www.shoprootscience.com/shop/arctic-c-vitamin-c-serum")
- assert.Equal(t, nil, err)
- ret = getPrice(body)
- assert.Equal(t, "$110.00", ret)
- body, err = util.Get("https://strandbergguitars.com/product/boden-6-dr-titanium/")
- assert.Equal(t, nil, err)
- ret = getPrice(body)
- assert.Equal(t, "$2,995.00", ret)
- }
- func TestGetWordPressProduct(t *testing.T) {
- body, err := util.Get("https://seoulknit.com/shop/collar-half-sleeved-top_blue/")
- assert.Equal(t, nil, err)
- ret := getProduct(body)
- assert.Equal(t, ret.Sku, float64(5677))
- body, err = util.Get("https://www.shoprootscience.com/shop/arctic-c-vitamin-c-serum")
- assert.Equal(t, nil, err)
- ret = getProduct(body)
- assert.Equal(t, ret.Sku, "FS-ARCC-30")
- body, err = util.Get("https://strandbergguitars.com/product/boden-6-dr-titanium/")
- assert.Equal(t, nil, err)
- ret = getProduct(body)
- assert.Equal(t, "BD6CT-20DRB-K-P-TI", ret.Sku)
- t.Run("상품설명", func(t *testing.T) {
- body, err := util.Get("https://www.mehisox.com/shop/sn388/")
- assert.Equal(t, nil, err)
- html := getProductDescription(body)
- os.WriteFile("c:\\temp\\test.html", []byte(html), 0644)
- assert.Equal(t, ``, html)
- })
- }
- func TestGetCategories(t *testing.T) {
- body, err := util.Get("https://seoulknit.com/shop/collar-half-sleeved-top_blue/")
- assert.Equal(t, nil, err)
- ret := getCategories(body)
- assert.Equal(t, ret, "2021SS, Abito angelico, All, New arrivals, Top")
- body, err = util.Get("https://www.shoprootscience.com/shop/arctic-c-vitamin-c-serum")
- assert.Equal(t, nil, err)
- ret = getCategories(body)
- assert.Equal(t, ret, "Treatments")
- body, err = util.Get("https://shopkeeper.wp-theme.design/shop/hoodies/oversize-drawstring-sweatshirt/")
- assert.Equal(t, nil, err)
- ret = getCategories(body)
- assert.Equal(t, ret, "Hoodies, Jackets, Trousers")
- }
- func TestGetOptions(t *testing.T) {
- body, err := util.Get("https://seoulknit.com/shop/collar-half-sleeved-top_blue/")
- assert.Equal(t, nil, err)
- ret := getOptions(body)
- assert.EqualValues(t, ret, []string{"옵션을 선택하세요", "Small", "Midium"})
- body, err = util.Get("https://www.shoprootscience.com/shop/arctic-c-vitamin-c-serum")
- assert.Equal(t, nil, err)
- ret = getOptions(body)
- assert.EqualValues(t, ret, []string(nil))
- body, err = util.Get("https://shopkeeper.wp-theme.design/shop/hoodies/oversize-drawstring-sweatshirt/")
- assert.Equal(t, nil, err)
- ret = getOptions(body)
- assert.EqualValues(t, ret, []string{"Choose an option", "Camel", "Green", "Black", "White", "Choose an option", "XS", "S", "M", "L", "XL"})
- }
|