53 lines
1.4 KiB
Go
53 lines
1.4 KiB
Go
package api
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"gardomatic.kleiax.de/internal/storage"
|
|
)
|
|
|
|
func TestSpeciesInputAppliesAndClearsDimensions(t *testing.T) {
|
|
heightFrom, heightTo, widthFrom, widthTo := 20, 80, 30, 60
|
|
species := storage.Species{
|
|
HeightCMFrom: &heightFrom,
|
|
HeightCMTo: &heightTo,
|
|
WidthCMFrom: &widthFrom,
|
|
WidthCMTo: &widthTo,
|
|
}
|
|
newHeightFrom, newWidthTo := 40, 70
|
|
|
|
speciesInput{
|
|
HeightCMFrom: &newHeightFrom,
|
|
ClearHeightCMTo: true,
|
|
ClearWidthCMFrom: true,
|
|
WidthCMTo: &newWidthTo,
|
|
}.apply(&species)
|
|
|
|
if species.HeightCMFrom == nil || *species.HeightCMFrom != 40 {
|
|
t.Fatalf("height from = %v, want 40", species.HeightCMFrom)
|
|
}
|
|
if species.HeightCMTo != nil {
|
|
t.Fatalf("height to = %v, want nil", species.HeightCMTo)
|
|
}
|
|
if species.WidthCMFrom != nil {
|
|
t.Fatalf("width from = %v, want nil", species.WidthCMFrom)
|
|
}
|
|
if species.WidthCMTo == nil || *species.WidthCMTo != 70 {
|
|
t.Fatalf("width to = %v, want 70", species.WidthCMTo)
|
|
}
|
|
}
|
|
|
|
func TestSpeciesInputAcceptsDeprecatedHeight(t *testing.T) {
|
|
height := 90
|
|
var species storage.Species
|
|
|
|
speciesInput{HeightCM: &height}.apply(&species)
|
|
|
|
if species.HeightCMTo == nil || *species.HeightCMTo != height {
|
|
t.Fatalf("height to = %v, want %d", species.HeightCMTo, height)
|
|
}
|
|
if species.HeightCM == nil || *species.HeightCM != height {
|
|
t.Fatalf("deprecated height alias = %v, want %d", species.HeightCM, height)
|
|
}
|
|
}
|