Files
descrybe/apps/api/internal/woocommerce/sync_scope_test.go
T
greeneclipse 8580c996c3 Initial commit of Descrybe v2 without local scratch artifacts.
Drop one-shot tmp/axe scripts and agent i18n scratch so the Gitea tree is deployable.
2026-08-09 22:47:43 +02:00

43 lines
1.2 KiB
Go

package woocommerce
import (
"errors"
"strings"
"testing"
"github.com/google/uuid"
)
func TestApplyProductSyncScope(t *testing.T) {
opt := SyncOptions{SyncLimit: defaultSyncLimit}
id := uuid.New().String()
err := applyProductSyncScope(&opt, ProductSyncScope{
Limit: 25,
Status: "needs_review",
Category: "Sofas",
ProductIDs: []string{id},
})
if err != nil {
t.Fatal(err)
}
if opt.SyncLimit != 25 || opt.SyncFilterStatus != "needs_review" || opt.SyncFilterCategory != "Sofas" {
t.Fatalf("opt=%#v", opt)
}
if len(opt.SyncOnlyIDs) != 1 || opt.SyncOnlyIDs[0] != id {
t.Fatalf("ids=%v", opt.SyncOnlyIDs)
}
if err := applyProductSyncScope(&opt, ProductSyncScope{Status: "bad"}); !errors.Is(err, ErrInvalidSyncScope) {
t.Fatalf("err=%v", err)
}
if err := applyProductSyncScope(&opt, ProductSyncScope{Category: strings.Repeat("x", maxCategoryFilterLen+1)}); !errors.Is(err, ErrInvalidSyncScope) {
t.Fatalf("category length err=%v", err)
}
tooMany := make([]string, maxSyncOnlyIDs+1)
for i := range tooMany {
tooMany[i] = uuid.New().String()
}
if err := applyProductSyncScope(&opt, ProductSyncScope{ProductIDs: tooMany}); !errors.Is(err, ErrInvalidSyncScope) {
t.Fatalf("product_ids max err=%v", err)
}
}