Files
fm_be/internal/domain/helicopter/model_test.go
2026-07-16 22:16:45 +07:00

54 lines
1.9 KiB
Go

package helicopter
import "testing"
func TestHelicopterEnforceAOGInactive(t *testing.T) {
cases := []struct {
name string
airOnGround bool
initActive bool
want bool
}{
{name: "aog forces inactive", airOnGround: true, initActive: true, want: false},
{name: "aog stays inactive", airOnGround: true, initActive: false, want: false},
{name: "not aog keeps manual active", airOnGround: false, initActive: true, want: true},
{name: "not aog keeps manual inactive", airOnGround: false, initActive: false, want: false},
}
for _, tc := range cases {
t.Run(tc.name, func(t *testing.T) {
h := Helicopter{AirOnGround: tc.airOnGround, IsActive: tc.initActive}
h.EnforceAOGInactive()
if h.IsActive != tc.want {
t.Fatalf("IsActive = %v, want %v", h.IsActive, tc.want)
}
})
}
}
func TestHelicopterDeriveStatus(t *testing.T) {
cases := []struct {
name string
airOnGround bool
mcf bool
isInUse bool
want string
}{
{name: "available when idle", airOnGround: false, mcf: false, isInUse: false, want: StatusAvailable},
{name: "booked when in use", airOnGround: false, mcf: false, isInUse: true, want: StatusBooked},
{name: "mcf when mcf flagged", airOnGround: false, mcf: true, isInUse: false, want: StatusMCF},
{name: "mcf outranks booked", airOnGround: false, mcf: true, isInUse: true, want: StatusMCF},
{name: "aog when on ground", airOnGround: true, mcf: false, isInUse: false, want: StatusAOG},
{name: "aog outranks booked", airOnGround: true, mcf: false, isInUse: true, want: StatusAOG},
{name: "mcf outranks aog", airOnGround: true, mcf: true, isInUse: false, want: StatusMCF},
}
for _, tc := range cases {
t.Run(tc.name, func(t *testing.T) {
h := Helicopter{AirOnGround: tc.airOnGround}
if got := h.DeriveStatus(StatusInput{IsBook: tc.isInUse, IsMCF: tc.mcf}); got != tc.want {
t.Fatalf("DeriveStatus() = %q, want %q", got, tc.want)
}
})
}
}