Phase 4 part 1: the full Stripe sync, and margins per product
Customers, invoices with all their lines (both of Stripe's line shapes), credit notes, refunds (with their customer) and products: a backfill, then the Events API every hour, and a new backfill when events have expired. Metrics page with sync status. Gross margin per product: a default (60%) and overrides, with names from Stripe's products or the invoice lines. Schemas 18 and 19. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -58,3 +58,21 @@ func TestEnginesPage(t *testing.T) {
|
||||
t.Error("the ping isn't listed")
|
||||
}
|
||||
}
|
||||
|
||||
func TestMarginsForm(t *testing.T) {
|
||||
s, h := newTestServer(t, nil)
|
||||
s.DB.Exec(`INSERT INTO stripe_invoice_lines (invoice, id, status, currency, amount, period_start, product, description)
|
||||
VALUES ('in_1', 'il_1', 'paid', 'usd', 4900, strftime('%s', 'now'), 'prod_core', '1 × Federated Core (at $49.00 / month)')`)
|
||||
if body := do(h, http.MethodGet, "/metrics", nil, nil).Body.String(); !strings.Contains(body, "Federated Core") || !strings.Contains(body, `placeholder="60"`) {
|
||||
t.Fatal("the margin table isn't shown")
|
||||
}
|
||||
if rec := postForm(h, "/metrics/margins", url.Values{"default": {"55%"}, "margin:prod_core": {"70"}}); rec.Code != http.StatusSeeOther {
|
||||
t.Fatalf("save: %d %s", rec.Code, rec.Body)
|
||||
}
|
||||
if body := do(h, http.MethodGet, "/metrics", nil, nil).Body.String(); !strings.Contains(body, `name="margin:prod_core" value="70"`) || !strings.Contains(body, `name="default" value="55"`) {
|
||||
t.Error("the margins weren't saved")
|
||||
}
|
||||
if rec := postForm(h, "/metrics/margins", url.Values{"default": {"abc"}}); !strings.Contains(rec.Body.String(), "percentage") {
|
||||
t.Error("a bad default was accepted")
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user