common/structs/storage/provider-article_test.go
2024-08-31 18:27:17 +08:00

55 lines
1.1 KiB
Go

package storage
import (
"fmt"
"testing"
v2 "gitea.timerzz.com/kedaya_haitao/common/structs/v2"
"gorm.io/gorm"
)
var providerArticle = v2.ProviderArticle{
ArticleID: 1,
Brand: v2.Brand_Coach,
Cost: v2.ProviderPrice{
CalMark: "111",
FinalPrice: 1,
OriginalPrice: 0,
ProviderArticleID: 0,
},
HistoryPrice: []v2.ProviderPrice{
{
CalMark: "222",
},
},
}
func TestProviderArticleApi_Upsert(t *testing.T) {
db, err := GetDevDB()
if err != nil {
t.Fatal(err)
}
storage := NewStorage(db)
storage.ProviderArticle().Upsert(providerArticle)
}
func TestProviderArticleApi_FindInBatches(t *testing.T) {
db, err := GetDevDB()
if err != nil {
t.Fatal(err)
}
storage := NewStorage(db)
var results = make([]v2.ProviderArticle, 0)
err = storage.ProviderArticle().FindInBatches(&GetProviderArticleQuery{ProviderId: "1"}, &results, func(tx *gorm.DB, batch int) error {
for idx := range results {
results[idx].Link = fmt.Sprintf("test_%d", idx)
results[idx].SkuID = fmt.Sprintf("sku_%d", idx)
}
return db.Select("id", "link").Save(&results).Error
})
if err != nil {
t.Fatal(err)
}
}