Files
aura-crm/production/backend/internal/cartridge/handler_test.go
T

43 lines
1.4 KiB
Go

package cartridge
import (
"strings"
"testing"
)
func strPtr(s string) *string { return &s }
func TestItemInputValidate(t *testing.T) {
longShort := strings.Repeat("a", maxShortFieldLen+1)
longNote := strings.Repeat("a", maxLongFieldLen+1)
longPrice := strings.Repeat("1", maxPriceLen+1)
tests := []struct {
name string
item itemInput
wantErr bool
}{
{"valid minimal", itemInput{Model: "HP CF283A"}, false},
{"valid full", itemInput{Model: "HP CF283A", Color: "black", Tag: "A1", RefillCount: 3, Price: strPtr("450.00"), Note: "ok"}, false},
{"missing model", itemInput{Model: ""}, true},
{"model too long", itemInput{Model: longShort}, true},
{"color too long", itemInput{Model: "x", Color: longShort}, true},
{"tag too long", itemInput{Model: "x", Tag: longShort}, true},
{"note too long", itemInput{Model: "x", Note: longNote}, true},
{"refill_count negative", itemInput{Model: "x", RefillCount: -1}, true},
{"refill_count over cap", itemInput{Model: "x", RefillCount: 51}, true},
{"refill_count at cap", itemInput{Model: "x", RefillCount: 50}, false},
{"price too long", itemInput{Model: "x", Price: strPtr(longPrice)}, true},
{"price nil", itemInput{Model: "x", Price: nil}, false},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
got := tt.item.validate()
if (got != "") != tt.wantErr {
t.Errorf("validate() = %q, wantErr %v", got, tt.wantErr)
}
})
}
}