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:
@@ -0,0 +1,46 @@
|
||||
package sites
|
||||
|
||||
import (
|
||||
"context"
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"supermarket/internal/ai"
|
||||
"supermarket/internal/inventory"
|
||||
"supermarket/internal/profile"
|
||||
)
|
||||
|
||||
type recordingAI struct {
|
||||
out string
|
||||
prompt *string
|
||||
}
|
||||
|
||||
func (r recordingAI) Generate(_ context.Context, req ai.Request) (string, error) {
|
||||
*r.prompt = req.System + "\n" + req.Prompt
|
||||
return r.out, nil
|
||||
}
|
||||
|
||||
// A comparison is written with the competitor's prices as the owner
|
||||
// checked them, and a price checked long ago becomes a to-do.
|
||||
func TestComparisonUsesCheckedPrices(t *testing.T) {
|
||||
var prompt string
|
||||
c := &Composer{AI: recordingAI{out: `{"path":"/vs-zendesk/","title":"Us vs Zendesk","description":"d","sections_yaml":"- type: hero\n title: x\n","needs":[]}`, prompt: &prompt},
|
||||
Profile: &profile.Profile{Name: "Us", Description: "Help desks."}}
|
||||
z := &inventory.Entry{Name: "Zendesk", Relationship: inventory.Competitor, Description: "A help desk.", Prices: []inventory.Price{
|
||||
{Plan: "Suite Team", Amount: "$55", Per: "per agent per month", Checked: "2026-11-20", Source: "https://zendesk.com/pricing"},
|
||||
{Plan: "Support Team", Amount: "$19", Per: "per agent per month", Checked: "2025-01-10"},
|
||||
}}
|
||||
out, err := c.Compose(context.Background(), Inputs{Kind: "comparison", Competitor: z, Catalog: &Catalog{Types: []SectionType{{Name: "hero"}}}})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
for _, want := range []string{"- Suite Team: $55 per agent per month (checked Nov 2026, from https://zendesk.com/pricing)",
|
||||
"State a competitor's price only as listed, with the month it was checked"} {
|
||||
if !strings.Contains(prompt, want) {
|
||||
t.Errorf("prompt lacks %q", want)
|
||||
}
|
||||
}
|
||||
if len(out.Needs) != 1 || !strings.Contains(out.Needs[0], "Check Zendesk's price Support Team: $19 per agent per month: last checked 10 Jan 2025.") {
|
||||
t.Errorf("needs: %v", out.Needs)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user