Files

36 lines
752 B
Go
Raw Permalink Normal View History

package woocommerce
import (
"encoding/json"
"testing"
)
func TestExtractItemCategories(t *testing.T) {
meta, _ := json.Marshal([]map[string]any{
{"key": "categories", "value": []any{"Shoes", "Men"}},
{"key": "foo", "value": "bar"},
})
item := OrderLineItem{MetaData: meta}
got := extractItemCategories(item)
if len(got) != 2 {
t.Fatalf("expected 2 categories, got %#v", got)
}
}
func TestParseWooTime(t *testing.T) {
if parseWooTime("2024-01-02T03:04:05") == nil {
t.Fatal("expected parsed time")
}
if parseWooTime("") != nil {
t.Fatal("expected nil")
}
}
func TestClampPerPage(t *testing.T) {
if clampPerPage(0) != defaultListPerPage {
t.Fatal("default")
}
if clampPerPage(500) != maxListPerPage {
t.Fatal("max")
}
}