ListReferencedPlants(includeRemoved=true) returned every plant the garden has ever held, so drawing one season loaded a decade of catalog on a decade-old garden. It also meant the plant list and the plop list were selected by different rules, which is the kind of near-miss that stays correct only by accident. It now takes the same year the plops do, so the two selections always agree. Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]> Claude-Session: https://claude.ai/code/session_01H3zbym8Doka2d7D48maSgZ
This commit is contained in:
@@ -432,3 +432,59 @@ func TestSeasonYearIsBounded(t *testing.T) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// TestSeasonPlantsAreScopedToTheYear — the plant list has to match the plops it
|
||||
// is there to render. A garden with a decade of history shouldn't load a decade
|
||||
// of catalog to draw one season, and a season shouldn't carry plants that had
|
||||
// nothing in the ground that year.
|
||||
func TestSeasonPlantsAreScopedToTheYear(t *testing.T) {
|
||||
s := newTestService(t, openConfig())
|
||||
owner := seedUser(t, s, "[email protected]")
|
||||
g := seedGarden(t, s, owner)
|
||||
bed := seedBed(t, s, owner, g.ID)
|
||||
ctx := context.Background()
|
||||
|
||||
oldPlant := seedOwnPlant(t, s, owner, 15)
|
||||
newPlant, err := s.CreatePlant(ctx, owner, PlantInput{
|
||||
Name: "Later", Category: domain.CategoryHerb, SpacingCM: 20, Color: "#4a7c3f", Icon: "🌱",
|
||||
})
|
||||
if err != nil {
|
||||
t.Fatalf("CreatePlant: %v", err)
|
||||
}
|
||||
|
||||
plant2020, err := s.CreatePlanting(ctx, owner, bed.ID, PlantingInput{
|
||||
PlantID: oldPlant.ID, XCM: -40, YCM: 0, RadiusCM: 20, PlantedAt: strPtr("2020-04-01"),
|
||||
})
|
||||
if err != nil {
|
||||
t.Fatalf("CreatePlanting: %v", err)
|
||||
}
|
||||
if _, err := s.UpdatePlanting(ctx, owner, plant2020.ID, PlantingPatch{
|
||||
SetRemovedAt: true, RemovedAt: strPtr("2020-09-01"),
|
||||
}, plant2020.Version); err != nil {
|
||||
t.Fatalf("remove: %v", err)
|
||||
}
|
||||
if _, err := s.CreatePlanting(ctx, owner, bed.ID, PlantingInput{
|
||||
PlantID: newPlant.ID, XCM: 40, YCM: 0, RadiusCM: 20, PlantedAt: strPtr("2026-04-01"),
|
||||
}); err != nil {
|
||||
t.Fatalf("CreatePlanting: %v", err)
|
||||
}
|
||||
|
||||
names := func(year int) []string {
|
||||
t.Helper()
|
||||
full, err := s.GardenFull(ctx, owner, g.ID, &year)
|
||||
if err != nil {
|
||||
t.Fatalf("GardenFull(%d): %v", year, err)
|
||||
}
|
||||
out := []string{}
|
||||
for _, p := range full.Plants {
|
||||
out = append(out, p.Name)
|
||||
}
|
||||
return out
|
||||
}
|
||||
if got := names(2020); len(got) != 1 || got[0] != oldPlant.Name {
|
||||
t.Errorf("2020 plants = %v, want just %q", got, oldPlant.Name)
|
||||
}
|
||||
if got := names(2026); len(got) != 1 || got[0] != "Later" {
|
||||
t.Errorf("2026 plants = %v, want just \"Later\"", got)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user