muyu-apiserver/rpc/inventory/internal/logic/batch_helpers_test.go
kae_mihara e3f6fa236d
feat:improve product yarn ratio workflow (#5)
* feat: support product yarn batches

* feat: improve product yarn ratio workflow

* Potential fix for pull request finding

Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>

* Potential fix for pull request finding

Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>

* Potential fix for pull request finding

Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>

* Potential fix for pull request finding

Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>

---------

Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
2026-07-05 08:06:28 +09:00

57 lines
1.2 KiB
Go

package logic
import "testing"
func TestValidateYarnRatio(t *testing.T) {
tests := []struct {
name string
raw string
wantErr bool
}{
{
name: "empty ratio is valid",
raw: "",
wantErr: false,
},
{
name: "both sides add up to ten",
raw: `{"warp":[{"yarn_id":"y1","ratio":6},{"yarn_id":"y2","ratio":4}],"weft":[{"yarn_id":"y3","ratio":10}]}`,
wantErr: false,
},
{
name: "one empty side is valid",
raw: `{"warp":[{"yarn_id":"y1","ratio":10}],"weft":[]}`,
wantErr: false,
},
{
name: "side with yarn must add up to ten",
raw: `{"warp":[{"yarn_id":"y1","ratio":9}],"weft":[]}`,
wantErr: true,
},
{
name: "ratio must be integer",
raw: `{"warp":[{"yarn_id":"y1","ratio":9.5}],"weft":[]}`,
wantErr: true,
},
{
name: "yarn id is required",
raw: `{"warp":[{"ratio":10}],"weft":[]}`,
wantErr: true,
},
{
name: "invalid json is rejected",
raw: `{warp}`,
wantErr: true,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
err := validateYarnRatio(tt.raw)
if (err != nil) != tt.wantErr {
t.Fatalf("validateYarnRatio() error = %v, wantErr %v", err, tt.wantErr)
}
})
}
}