Inventory: competitor prices, as checked

Each Inventory entry can hold its plans' prices: the plan, the price,
what it's per, when it was checked and where. Comparison and alternative
pages, and new sections, state a competitor's price only as entered,
with the month it was checked; a missing one is left out and listed as a
to-do. A price checked more than six months ago is flagged on the entry
and adds a to-do to every page that names the competitor. Prices go out
and come back with the Inventory's YAML.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-11-24 08:18:31 -07:00
co-authored by Claude Opus 5.5
parent e0e74af86c
commit f5d87164ac
10 changed files with 357 additions and 4 deletions
+34
View File
@@ -0,0 +1,34 @@
package web
import (
"net/http"
"net/url"
"strconv"
"strings"
"testing"
"supermarket/internal/inventory"
)
func TestInventoryPrices(t *testing.T) {
s, h := newTestServer(t, nil)
form := url.Values{"name": {"Zendesk"}, "relationship": {"competitor"}, "mention_policy": {"name"},
"price_plan": {"Suite Team", ""}, "price_amount": {"$55", ""}, "price_per": {"per agent per month", ""},
"price_checked": {"2026-11-20", "2026-11-24"}, "price_source": {"https://zendesk.com/pricing", ""}}
if rec := postForm(h, "/inventory/save", form); rec.Code != http.StatusSeeOther {
t.Fatalf("save: %d %s", rec.Code, rec.Body.String())
}
es, _ := inventory.List(s.DB, "")
if len(es) != 1 || len(es[0].Prices) != 1 || es[0].Prices[0].Amount != "$55" {
t.Fatalf("saved: %+v", es)
}
body := do(h, http.MethodGet, "/inventory/"+strconv.FormatInt(es[0].ID, 10), nil, nil).Body.String()
if !strings.Contains(body, `name="price_amount" value="$55"`) || !strings.Contains(body, "Their prices") {
t.Errorf("edit page: %s", body)
}
form.Set("price_checked", "")
form["price_checked"] = []string{"", ""}
if rec := postForm(h, "/inventory/save", form); !strings.Contains(rec.Body.String(), "say when you checked the price $55") && !strings.Contains(rec.Body.String(), "Say when you checked the price $55") {
t.Errorf("a price without its date was saved: %d", rec.Code)
}
}