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) } }