common/structs/storage/article_test.go

71 lines
1.5 KiB
Go

package storage
import (
"fmt"
"testing"
v2 "gitea.timerzz.com/kedaya_haitao/common/structs/v2"
"gorm.io/driver/postgres"
"gorm.io/gorm"
)
func GetDevDB() (*gorm.DB, error) {
dsn := fmt.Sprintf("host=%s user=%s password=%s dbname=%s port=%s sslmode=disable TimeZone=Asia/Shanghai", "192.168.31.55", "timerzz", "zhhg1997", "kedaya_dev", "5432")
return gorm.Open(postgres.Open(dsn), &gorm.Config{})
}
var article = v2.Article{
Name: "test2",
EnglishName: "test2",
Pid: "111",
Brand: "col",
Desc: "desc",
Image: "http://123",
Available: false,
CostPrice: 321,
Providers: []v2.ProviderArticle{
{
ID: 1,
Pid: "111",
Brand: "col",
Link: "http://123",
ProviderId: "coach2",
SkuID: "sku2",
Cost: v2.ProviderPrice{
OriginalPrice: 222,
FinalPrice: 222,
CalMark: "aaa",
},
HistoryPrice: []v2.ProviderPrice{
{
OriginalPrice: 222,
FinalPrice: 222,
CalMark: "uuuuu",
},
},
},
},
SellPrice: 222,
Sellers: []v2.SellerArticle{},
Rate: 222,
Remark: "222",
}
func TestUpsetArticle(t *testing.T) {
db, _ := GetDevDB()
storage := NewStorage(db)
err := db.AutoMigrate(&v2.Article{}, &v2.ProviderArticle{}, &v2.ProviderPrice{}, &v2.SellerArticle{}, &v2.SellerPrice{})
if err != nil {
t.Fatal(err)
}
if err = storage.Article().Upsert(article); err != nil {
t.Fatal(err)
}
}
func TestArticleApi_Update(t *testing.T) {
db, _ := GetDevDB()
articleApi := NewArticleApi(db)
articleApi.Update(article)
}