init parser

This commit is contained in:
2023-12-20 00:36:49 +03:00
commit 872217d845
9 changed files with 477 additions and 0 deletions

View File

@ -0,0 +1,53 @@
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))
}
})
}
}