parser_test.go 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. package wordpress
  2. import (
  3. util "kkscrap-go/controllers/scraper/util"
  4. "testing"
  5. "github.com/stretchr/testify/assert"
  6. )
  7. func TestGetImages(t *testing.T) {
  8. body, err := util.Get("https://seoulknit.com/shop/collar-half-sleeved-top_blue/")
  9. assert.Equal(t, nil, err)
  10. imgs := getImages(body)
  11. assert.Equal(t, "https://seoulknit.com/wp-content/uploads/2021/05/abito_0594-scaled-454x681.jpg", imgs[0].Path)
  12. assert.Equal(t, "https://seoulknit.com/wp-content/uploads/2021/05/abito_0594-scaled-100x100.jpg", imgs[1].Path)
  13. body, err = util.Get("https://www.dollshecraft.com/product/amanda-beauty-26f-classic-maxi-65cm-special-package-2/")
  14. assert.Equal(t, nil, err)
  15. imgs = getImages(body)
  16. assert.Equal(t, "https://cdn.dollshecraft.com/wp-content/uploads/2018/08/Amanda-Beauty_558743_01.jpg", imgs[0].Path)
  17. body, err = util.Get("https://www.shoprootscience.com/shop/arctic-c-vitamin-c-serum")
  18. assert.Equal(t, nil, err)
  19. imgs = getImages(body)
  20. assert.Equal(t, "https://www.shoprootscience.com/wp-content/uploads/2020/10/Arctic-C-product-511x634.jpg", imgs[0].Path)
  21. assert.Equal(t, "https://www.shoprootscience.com/wp-content/uploads/2020/10/Arctic-C-product.jpg", imgs[1].Path)
  22. body, err = util.Get("https://strandbergguitars.com/product/boden-6-dr-titanium/")
  23. assert.Equal(t, nil, err)
  24. imgs = getImages(body)
  25. 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].Path)
  26. 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/")
  27. assert.Equal(t, nil, err)
  28. imgs = getImages(body)
  29. 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].Path)
  30. }
  31. func TestGetPrice(t *testing.T) {
  32. body, err := util.Get("https://seoulknit.com/shop/collar-half-sleeved-top_blue/")
  33. assert.Equal(t, nil, err)
  34. ret := getPrice(body)
  35. assert.Equal(t, "₩ 59,000", ret)
  36. body, err = util.Get("https://www.dollshecraft.com/product/amanda-beauty-26f-classic-maxi-65cm-special-package-2/")
  37. assert.Equal(t, nil, err)
  38. ret = getPrice(body)
  39. assert.Equal(t, "$1,450.00", ret)
  40. body, err = util.Get("https://www.shoprootscience.com/shop/arctic-c-vitamin-c-serum")
  41. assert.Equal(t, nil, err)
  42. ret = getPrice(body)
  43. assert.Equal(t, "$110.00", ret)
  44. body, err = util.Get("https://strandbergguitars.com/product/boden-6-dr-titanium/")
  45. assert.Equal(t, nil, err)
  46. ret = getPrice(body)
  47. assert.Equal(t, "$2,995.00", ret)
  48. }
  49. func TestGetWordPressProduct(t *testing.T) {
  50. body, err := util.Get("https://seoulknit.com/shop/collar-half-sleeved-top_blue/")
  51. assert.Equal(t, nil, err)
  52. ret := getProduct(body)
  53. assert.Equal(t, ret.Sku, float64(5677))
  54. body, err = util.Get("https://www.shoprootscience.com/shop/arctic-c-vitamin-c-serum")
  55. assert.Equal(t, nil, err)
  56. ret = getProduct(body)
  57. assert.Equal(t, ret.Sku, "FS-ARCC-30")
  58. body, err = util.Get("https://strandbergguitars.com/product/boden-6-dr-titanium/")
  59. assert.Equal(t, nil, err)
  60. ret = getProduct(body)
  61. assert.Equal(t, ret.Sku, "BD6CT-20DR-K-P-TI")
  62. }
  63. func TestGetCategories(t *testing.T) {
  64. body, err := util.Get("https://seoulknit.com/shop/collar-half-sleeved-top_blue/")
  65. assert.Equal(t, nil, err)
  66. ret := getCategories(body)
  67. assert.Equal(t, ret, "2021SS, Abito angelico, All, New arrivals, Top")
  68. body, err = util.Get("https://www.shoprootscience.com/shop/arctic-c-vitamin-c-serum")
  69. assert.Equal(t, nil, err)
  70. ret = getCategories(body)
  71. assert.Equal(t, ret, "Treatments")
  72. body, err = util.Get("https://shopkeeper.wp-theme.design/shop/hoodies/oversize-drawstring-sweatshirt/")
  73. assert.Equal(t, nil, err)
  74. ret = getCategories(body)
  75. assert.Equal(t, ret, "Hoodies, Jackets, Trousers")
  76. }
  77. func TestGetOptions(t *testing.T) {
  78. body, err := util.Get("https://seoulknit.com/shop/collar-half-sleeved-top_blue/")
  79. assert.Equal(t, nil, err)
  80. ret := getOptions(body)
  81. assert.EqualValues(t, ret, []string{"옵션을 선택하세요", "Small", "Midium"})
  82. body, err = util.Get("https://www.shoprootscience.com/shop/arctic-c-vitamin-c-serum")
  83. assert.Equal(t, nil, err)
  84. ret = getOptions(body)
  85. assert.EqualValues(t, ret, []string(nil))
  86. body, err = util.Get("https://shopkeeper.wp-theme.design/shop/hoodies/oversize-drawstring-sweatshirt/")
  87. assert.Equal(t, nil, err)
  88. ret = getOptions(body)
  89. assert.EqualValues(t, ret, []string{"Choose an option", "Camel", "Green", "Black", "White", "Choose an option", "XS", "S", "M", "L", "XL"})
  90. }