test: added gtmstore test

This commit is contained in:
Felipe Martin Garcia 2022-08-07 12:06:19 +02:00
parent c71c9b0517
commit cf94a590b7
Signed by: fmartingr
GPG Key ID: 716BC147715E716F
3 changed files with 224 additions and 2 deletions

File diff suppressed because one or more lines are too long

View File

@ -2,7 +2,6 @@ package gtmstore
import (
"fmt"
"log"
"net/url"
"strconv"
"strings"
@ -42,7 +41,6 @@ func (s *GTMStoreShop) Get(u *url.URL) (*models.Product, error) {
s.Find(".woocommerce-product-gallery__wrapper div").Each(func(i int, s *goquery.Selection) {
imageURL, exists := s.Find("a").Attr("href")
if exists {
log.Println(imageURL)
imageURLs = append(imageURLs, imageURL)
}
})

View File

@ -0,0 +1,32 @@
package gtmstore_test
import (
"net/url"
"testing"
"github.com/fmartingr/bazaar/pkg/clients"
"github.com/fmartingr/bazaar/pkg/models"
"github.com/fmartingr/bazaar/pkg/shop/gtmstore"
"github.com/stretchr/testify/assert"
)
func TestGtmStore_Ok(t *testing.T) {
shop := gtmstore.NewGTMStoreShopFactory()(models.NewShopOptions(clients.NewMockClient()))
testUrl, _ := url.Parse("https://www.gtm-store.com/test/")
product, err := shop.Get(testUrl)
if err != nil {
t.Error(err)
return
}
t.Log(product)
assert.NotEmpty(t, product.Description)
assert.Equal(t, "Metroid: Misión Omega", product.Name)
assert.Equal(t, "https://www.gtm-store.com/wp-content/uploads/2022/07/GTM-Metroid-4.jpeg", product.ImageURL)
assert.Equal(t, 8.99, product.Price)
assert.Equal(t, "8,99", product.PriceText)
assert.Equal(t, testUrl.String(), product.URL)
}