Files
platiparser/plati/goodscategory_test.go
dilap54 c4e71fca93
All checks were successful
Build and push image / deploy (push) Successful in 2m36s
add good_id
2024-01-03 01:01:56 +03:00

81 lines
3.3 KiB
Go
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

package plati
import (
"bytes"
"encoding/json"
"io"
"reflect"
"testing"
)
func Test_parseGoodsCategory(t *testing.T) {
type args struct {
body io.Reader
}
tests := []struct {
name string
args args
want []*Good
wantErr bool
}{
{
name: "final_fantasy",
args: args{
body: bytes.NewReader([]byte(`<span class="GoodsBlock_oneline" id="GoodsBlock_1298"><a name=1298></a><div class="table_header clearfix"><h2 class="games-header"> <span><i class="platiru-loader" id="loader_1298"></i></span></h2></div><div><table class="goods-table goods-table-category"><thead><tr><th colspan="3" class="product-title">Название товара</td><th class="product-merchant"><div class="nowrap">Продавец <span class="rating_title">рейтинг</span></div></td><th class="product-sold">Продано</td><th class="product-price"><select onchange="return Goods_C('0',0, 1298,9901,'','cntSellDESC', 1, 100, this.value);"><option value=USD >USD</option><option value=RUR selected>RUB</option><option value=EUR >EUR</option><option value=UAH >UAH</option></select></div></tr></thead><td class="product-checkbox"><div><a class="product-to-notepad" onclick="return noteItem(4026129,0)"><i id="n4026129" class="unchecked" title="В закладки"></i></a></div></td><td class="product-chat"><div><i data-tooltip="m=chat" class="chat_online" onclick="return PopUp(197847, 0);"></i></a></div></td><td class="product-title"><div><a href="/itm/final-fantasy-type-0-hd-steam-gift-ru/4026129" title="FINAL FANTASY TYPE-0 HD (Steam Gift Россия)">FINAL FANTASY TYPE-0 HD (Steam Gift Россия)</a></div></td><td class="product-merchant" data-th='Продавец' class="product-merchant"><div><a href="/seller/igorderish/197847">IgorDeRish</a> <span>582</span></div></td><td class="product-sold" data-th='Продано' class="product-sold"><div>1</div></td><td data-th='Цена' class="product-price"><div class="product-price-inner"><div>498 </span>руб. </div></div></td></tr></table><div class="sort_wrapper"><div class="pages_nav" style="height:25px"></div></div></div>`)),
},
want: []*Good{
{
Name: "FINAL FANTASY TYPE-0 HD (Steam Gift Россия)",
GoodLink: "/itm/final-fantasy-type-0-hd-steam-gift-ru/4026129",
Seller: "IgorDeRish",
SellerLink: "/seller/igorderish/197847",
SellerRating: 582,
Sold: 1,
Price: 498.0,
},
},
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
got, err := parseGoodsCategory(tt.args.body)
if (err != nil) != tt.wantErr {
t.Errorf("parseGoodsCategory() error = %v, wantErr %v", err, tt.wantErr)
return
}
if !reflect.DeepEqual(got, tt.want) {
gotJson, _ := json.Marshal(got)
wantJson, _ := json.Marshal(tt.want)
t.Errorf("parseGoodsCategory() = %s, want %s", string(gotJson), string(wantJson))
}
})
}
}
func TestGood_GoodID(t *testing.T) {
type fields struct {
GoodLink string
}
tests := []struct {
fields fields
want int
}{
{
fields: fields{
GoodLink: "/itm/mortal-kombat-1-ua-kz-auto-24-7/4107232",
},
want: 4107232,
},
}
for _, tt := range tests {
t.Run(tt.fields.GoodLink, func(t *testing.T) {
g := &Good{
GoodLink: tt.fields.GoodLink,
}
if got := g.GoodID(); got != tt.want {
t.Errorf("Good.GoodID() = %v, want %v", got, tt.want)
}
})
}
}