Everything the user sees says Market: the sidebar, titles, breadcrumbs, help text, messages, suggestions and the agent tool's description; the export downloads as supermarket-market.yaml. Its pages live under /market, and the old /inventory addresses redirect there (308, so a form's POST stays a POST). The YAML format (inventory:), the database and the code's names are unchanged, so exported files still import. A breadcrumb no longer repeats the page's own title. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
50 lines
2.1 KiB
Go
50 lines
2.1 KiB
Go
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, "/market/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, "/market/"+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, "/market/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)
|
|
}
|
|
}
|
|
|
|
// The Market was the Inventory: its old addresses lead to the new ones,
|
|
// keeping the query and a form's POST.
|
|
func TestMarketMoved(t *testing.T) {
|
|
_, h := newTestServer(t, nil)
|
|
for old, want := range map[string]string{"/inventory": "/market", "/inventory/3?x=1": "/market/3?x=1", "/inventory/import": "/market/import"} {
|
|
rec := do(h, http.MethodGet, old, nil, nil)
|
|
if rec.Code != http.StatusPermanentRedirect || rec.Header().Get("Location") != want {
|
|
t.Errorf("%s: %d %s", old, rec.Code, rec.Header().Get("Location"))
|
|
}
|
|
}
|
|
if rec := postForm(h, "/inventory/save", url.Values{"name": {"X"}}); rec.Code != http.StatusPermanentRedirect || rec.Header().Get("Location") != "/market/save" {
|
|
t.Errorf("post: %d %s", rec.Code, rec.Header().Get("Location"))
|
|
}
|
|
}
|