43 lines
1.2 KiB
Go
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)
|
||
|
|
}
|
||
|
|
}
|