add export as yml_catalog
This commit is contained in:
81
internal/export/itemsmarket_test.go
Normal file
81
internal/export/itemsmarket_test.go
Normal file
@ -0,0 +1,81 @@
|
||||
package export
|
||||
|
||||
import (
|
||||
"encoding/xml"
|
||||
"os"
|
||||
"testing"
|
||||
|
||||
"github.com/brianvoe/gofakeit/v6"
|
||||
)
|
||||
|
||||
func TestYMLSerialize(t *testing.T) {
|
||||
faker := gofakeit.New(0)
|
||||
|
||||
categories := make([]Category, faker.Rand.Intn(4))
|
||||
knownCategory := map[int]struct{}{}
|
||||
categoryIDs := make([]int, 0, 10)
|
||||
for i := range categories {
|
||||
categories[i].ID = faker.Rand.Int()
|
||||
categories[i].Name = faker.HipsterWord()
|
||||
categories[i].ParentID = faker.Rand.Int()
|
||||
|
||||
if _, ok := knownCategory[categories[i].ID]; ok {
|
||||
continue
|
||||
}
|
||||
|
||||
knownCategory[categories[i].ID] = struct{}{}
|
||||
categoryIDs = append(categoryIDs, categories[i].ID)
|
||||
}
|
||||
|
||||
offers := make([]Offer, faker.Rand.Intn(5)+1)
|
||||
for i := range offers {
|
||||
offer := &offers[i]
|
||||
offer.ID = faker.Int64()
|
||||
offer.Type = "vendor.model"
|
||||
offer.Available = true
|
||||
offer.URL = faker.URL()
|
||||
offer.Price = int(faker.Price(10, 1000))
|
||||
offer.CurrencyID = "RUR"
|
||||
offer.CategoryID = categoryIDs[faker.Rand.Intn(len(categoryIDs))]
|
||||
for i := 0; i < faker.Rand.Intn(3); i++ {
|
||||
offer.PictureURLs = append(offer.PictureURLs, faker.ImageURL(128, 128))
|
||||
}
|
||||
offer.Vendor = faker.Company()
|
||||
offer.Model = faker.CarModel()
|
||||
offer.VendorCode = faker.Rand.Int()
|
||||
offer.TypePrefix = faker.ProductName()
|
||||
offer.Description = faker.Sentence(12)
|
||||
offer.ManufacturerWarrany = true
|
||||
for i := 0; i < faker.Rand.Intn(8); i++ {
|
||||
offer.Params = append(offer.Params, Param{
|
||||
Name: faker.AdjectiveProper(),
|
||||
Value: faker.Digit(),
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
var catalog YmlCatalog
|
||||
catalog.Shop = Shop{
|
||||
Name: faker.ProductName(),
|
||||
URL: faker.URL(),
|
||||
Company: faker.Company(),
|
||||
Platform: "BSM/Yandex/Market",
|
||||
Version: faker.AppVersion(),
|
||||
Currencies: []Currency{{
|
||||
ID: "RUR",
|
||||
Rate: 1,
|
||||
}},
|
||||
Categories: categories,
|
||||
Offers: offers,
|
||||
}
|
||||
catalog.Date = faker.Date()
|
||||
|
||||
container := YmlContainer{
|
||||
YmlCatalog: catalog,
|
||||
}
|
||||
enc := xml.NewEncoder(os.Stdout)
|
||||
enc.Indent("", " ")
|
||||
_ = enc.Encode(container)
|
||||
println()
|
||||
t.FailNow()
|
||||
}
|
||||
Reference in New Issue
Block a user