Files
platform/inventory/inventory_test.go
T
2026-06-28 17:52:49 +02:00

48 lines
1004 B
Go

package inventory
import "testing"
func TestLevelFor(t *testing.T) {
const low = int64(5)
cases := []struct {
qty int64
want Level
}{
{-3, LevelNone},
{0, LevelNone},
{1, LevelLow},
{5, LevelLow}, // at the watermark is still low
{6, LevelHigh},
{1000, LevelHigh},
}
for _, c := range cases {
if got := LevelFor(c.qty, low); got != c.want {
t.Errorf("LevelFor(%d, %d) = %q, want %q", c.qty, low, got, c.want)
}
}
}
func TestLevelInStock(t *testing.T) {
if LevelNone.InStock() {
t.Error("none should not be in stock")
}
if !LevelLow.InStock() || !LevelHigh.InStock() {
t.Error("low and high should be in stock")
}
}
func TestLevelChangedRoundTrip(t *testing.T) {
in := LevelChanged{SKU: "ABC-1", Location: "se", Level: LevelLow}
raw, err := in.Encode()
if err != nil {
t.Fatalf("encode: %v", err)
}
out, err := Decode(raw)
if err != nil {
t.Fatalf("decode: %v", err)
}
if out != in {
t.Errorf("round-trip mismatch: got %+v, want %+v", out, in)
}
}