mirror of
https://ids-dev.idsbuybuybuy.com/ids-ecommerce/ids-svc-product.git
synced 2026-11-29 16:57:41 +08:00
62 lines
2.0 KiB
Go
62 lines
2.0 KiB
Go
package server
|
|
|
|
import (
|
|
"context"
|
|
"testing"
|
|
|
|
"google.golang.org/grpc/codes"
|
|
"google.golang.org/grpc/status"
|
|
|
|
commonv1 "llms.idsbuybuybuy.com/ecommerce/ids-proto/gen/go/ids/common/v1"
|
|
productv1 "llms.idsbuybuybuy.com/ecommerce/ids-proto/gen/go/ids/product/v1"
|
|
"llms.idsbuybuybuy.com/ecommerce/ids-svc-product/internal/repository"
|
|
)
|
|
|
|
func TestRequireStoreScopeMissing(t *testing.T) {
|
|
_, err := requireStoreScope(&productv1.GetProductRequest{ProductId: "1"})
|
|
if status.Code(err) != codes.FailedPrecondition {
|
|
t.Fatalf("code = %v, want FailedPrecondition", status.Code(err))
|
|
}
|
|
}
|
|
|
|
func TestGetProductBySkuRequiresStoreContext(t *testing.T) {
|
|
s := NewProductServer(nil, nil, nil, nil)
|
|
_, err := s.GetProductBySku(context.Background(), &productv1.GetProductBySkuRequest{})
|
|
if status.Code(err) != codes.FailedPrecondition {
|
|
t.Fatalf("err = %v, want FailedPrecondition", err)
|
|
}
|
|
}
|
|
|
|
func TestGetProductBySkuRequiresID(t *testing.T) {
|
|
s := NewProductServer(nil, nil, nil, nil)
|
|
_, err := s.GetProductBySku(context.Background(), &productv1.GetProductBySkuRequest{
|
|
StoreContext: &commonv1.StoreContext{TenantId: "10", StoreId: "20"},
|
|
})
|
|
if status.Code(err) != codes.InvalidArgument {
|
|
t.Fatalf("err = %v, want InvalidArgument", err)
|
|
}
|
|
}
|
|
|
|
func TestProductCopyMaterialMapRequiresExactCoverage(t *testing.T) {
|
|
product := &repository.ProductRecord{ImageIDs: []string{"100"}}
|
|
skus := []repository.SKURecord{{ImageIDs: []string{"200", "100"}}}
|
|
|
|
mappings, err := productCopyMaterialMap(product, skus, []*productv1.MaterialIDMapping{
|
|
{SourceMaterialId: "100", TargetMaterialId: "300"},
|
|
{SourceMaterialId: "200", TargetMaterialId: "400"},
|
|
})
|
|
if err != nil {
|
|
t.Fatalf("productCopyMaterialMap() error = %v", err)
|
|
}
|
|
if mappings["100"] != "300" || mappings["200"] != "400" {
|
|
t.Fatalf("mappings = %#v", mappings)
|
|
}
|
|
|
|
_, err = productCopyMaterialMap(product, skus, []*productv1.MaterialIDMapping{
|
|
{SourceMaterialId: "100", TargetMaterialId: "300"},
|
|
})
|
|
if err == nil {
|
|
t.Fatal("productCopyMaterialMap() error = nil, want missing mapping error")
|
|
}
|
|
}
|