Documentation
¶
Overview ¶
Package world builds the rows a test needs through the functions the console itself calls: identity and organization queries, the provisioning step that gives a workspace its pool, the catalog queries, the rule-change function, the conferral queries, and the plan fixtures (prices, price mappings, issued grants, subscriptions and their scheduled changes), billing accounts, invoices and their lines, payments, the Stripe mappings of billing rows and of products, and the grant, tier and subscription acts (an extension, a reorder, a tier's removal, a subscription's end and its suspension), organization members and a second pool. Every method fails the test on any error. It suffixes the organization, product, set and ladder names, subjects and emails it writes with the World's suffix, and deletes nothing. Workspace reads the default pool of the organization it is given.
A World holds the testing.TB it was built with, so it belongs to the test or subtest that built it.
Index ¶
- type Account
- type Grant
- type Invoice
- type InvoiceOpts
- type IssueOpts
- type Ladder
- type Org
- type Payment
- type PaymentOpts
- type Person
- type Price
- type Product
- type SubOpts
- type Subscription
- type Workspace
- type World
- func (w *World) AddTier(l Ladder, p Product)
- func (w *World) BareSubscription(a Account, start, end time.Time) Subscription
- func (w *World) BillingAccount(o Org, name string) Account
- func (w *World) CancelAtPeriodEnd(sub Subscription)
- func (w *World) Confer(o Org, p Product) Grant
- func (w *World) ConferOn(o Org, poolID string, p Product) Grant
- func (w *World) ConferUnprojected(o Org, p Product) string
- func (w *World) ConferUnprojectedSuspended(o Org, p Product) string
- func (w *World) DefaultLadder(orgType string, l Ladder)
- func (w *World) Draft(p Product)
- func (w *World) EditProduct(p Product, edit func(*billing.UpdateProductParams))
- func (w *World) EndSubscription(sub Subscription)
- func (w *World) Extend(g Grant, until time.Time) Grant
- func (w *World) Floor(o Org)
- func (w *World) ForeignPause(s Subscription)
- func (w *World) Invoice(a Account, o InvoiceOpts) Invoice
- func (w *World) Issue(o Org, p Product, opts IssueOpts) Grant
- func (w *World) Ladder(name string, tiers ...Product) Ladder
- func (w *World) Lifecycle(p Product, status string)
- func (w *World) LineItem(inv Invoice, price Price, description string, cents int32, ...)
- func (w *World) MapAccount(a Account)
- func (w *World) MapAccountIn(a Account, live bool)
- func (w *World) MapInvoice(inv Invoice)
- func (w *World) MapInvoiceIn(inv Invoice, live bool)
- func (w *World) MapPayment(p Payment)
- func (w *World) MapPaymentIn(p Payment, live bool)
- func (w *World) MapPrice(price Price)
- func (w *World) MapPriceIn(price Price, live bool)
- func (w *World) MapProduct(p Product)
- func (w *World) MapProductIn(p Product, live bool)
- func (w *World) MapSubscription(s Subscription)
- func (w *World) MapSubscriptionIn(s Subscription, live bool)
- func (w *World) Member(o Org, p Person)
- func (w *World) OneTimePrice(p Product, cents int32) Price
- func (w *World) Org(name, orgType string, owner Person) Org
- func (w *World) OrgType(name string) string
- func (w *World) PauseCollection(s Subscription)
- func (w *World) Payment(inv Invoice, o PaymentOpts) Payment
- func (w *World) Person(name string) Person
- func (w *World) Pool(o Org, name, poolType string) string
- func (w *World) Price(p Product, cents int32) Price
- func (w *World) Product(name string) Product
- func (w *World) Providers(srcs ...integration.ProviderSource)
- func (w *World) RecurringPrice(p Product, cents int32, currency, interval string) Price
- func (w *World) RemoveTier(l Ladder, p Product)
- func (w *World) ReorderTiers(l Ladder, tiers ...Product)
- func (w *World) Retire(p Product)
- func (w *World) Revoke(g Grant)
- func (w *World) Rule(p Product, r entitlements.RuleFields)
- func (w *World) RuleChange(p Product, r entitlements.RuleFields, by Person, note string)
- func (w *World) ScheduleCancellation(sub Subscription, at time.Time)
- func (w *World) ScheduleDowngrade(sub Subscription, price Price, at time.Time)
- func (w *World) SortOrder(l Ladder, n int32)
- func (w *World) Subscribe(o Org, opts SubOpts, products ...Product) Subscription
- func (w *World) Suspend(sub Subscription, status string)
- func (w *World) Use(ws Workspace, key string, n int)
- func (w *World) WithoutSet(p Product)
- func (w *World) Workspace(o Org, name string) Workspace
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type InvoiceOpts ¶
type InvoiceOpts struct {
Number string
Status string
AmountDue int32
AmountPaid int32
DueDate time.Time
PeriodStart time.Time
PeriodEnd time.Time
IssuedAt time.Time
PaidAt time.Time
}
InvoiceOpts shapes an invoice. Status is "open" and AmountDue 1000 cents when zero; IssuedAt is now when zero. Number is the invoice number as written; when empty, the account's counter assigns it, as the invoice reconcile does.
type IssueOpts ¶
type IssueOpts struct {
Marked bool
Note string
Reason string
By Person
ValidFrom time.Time
ValidUntil time.Time
}
IssueOpts shapes an issued grant: whether it is marked to resume after a plan supersedes it, its reason ("complimentary" when empty), the person who issues it (the organization's owner when zero), and its bounds (unbounded, and starting now, when zero).
type PaymentOpts ¶
PaymentOpts shapes a payment: Status "succeeded" when empty, paid at At (now when zero); a "failed" payment fails at At instead.
type SubOpts ¶
type SubOpts struct {
PeriodEnd time.Time
NullPeriodEnd bool
CommitmentEnd time.Time
Policy string
}
SubOpts shapes a subscription: its period end (12:00 UTC, 29 days out, by default; NULL when NullPeriodEnd), and a commitment ending at CommitmentEnd under the early-termination Policy ("block", "allow" or "fee"), which the schema requires beside it.
type Subscription ¶
type Subscription struct {
ID string
BillingAccountID string
// contains filtered or unexported fields
}
Subscription is a subscription on the organization's billing account.
type Workspace ¶
Workspace is a workspace with its primary assignment to the organization's default pool.
type World ¶
type World struct {
TB testing.TB
Ctx context.Context
DB *sql.DB
Sfx string // suffix of every name the World writes
}
World is one test's builder over a database.
func (*World) AddTier ¶
AddTier appends p to l as its last tier. It inserts the tier row only: unlike the operator's add-tier form it does not align the product's live provisions to the new rung, so it is for a product no pool holds.
func (*World) BareSubscription ¶
func (w *World) BareSubscription(a Account, start, end time.Time) Subscription
BareSubscription creates an active subscription row on a and nothing else: no item, no conferral, no pool provision. The reconcile writes those beside the row; a billing list reads only the row and its Stripe mapping. start and end are its current period, NULL when zero.
func (*World) BillingAccount ¶
BillingAccount creates an active billing account of o, as provisioning does when an organization first buys.
func (*World) CancelAtPeriodEnd ¶
func (w *World) CancelAtPeriodEnd(sub Subscription)
CancelAtPeriodEnd sets the flag the subscription projection writes when Stripe reports a cancellation at the period end, keeping every other field.
func (*World) Confer ¶
Confer records a manual grant of p to o, made by o's owner, and confers it on o's default pool. It does not materialize the pool, so the pool keeps the rows the test wrote beside it.
func (*World) ConferOn ¶
ConferOn is Confer into the pool poolID, which Pool made. The console confers only into an organization's default pool, so it writes a state the app does not produce.
func (*World) ConferUnprojected ¶
ConferUnprojected confers p on o's pool from a subscription id that names no row, as the reconcile does before it has projected the subscription (pool_provisions.subscription_id carries no foreign key), and returns the provision id.
func (*World) ConferUnprojectedSuspended ¶
ConferUnprojectedSuspended confers p as ConferUnprojected does, then suspends the provision, and returns the provision id. The reconcile never writes this state, because it projects the subscription before it suspends; the state is the payment-due default a position whose subscription row is missing reads as. The subscription id names no row, so no status is written.
func (*World) DefaultLadder ¶
DefaultLadder makes l the default plan of orgType, as the operator's org type page does.
func (*World) Draft ¶
Draft returns p to the draft lifecycle. The create form writes published and no act moves a product back, so the builder writes the column in one statement.
func (*World) EditProduct ¶
func (w *World) EditProduct(p Product, edit func(*billing.UpdateProductParams))
EditProduct changes p through the operator's edit form: edit receives the product's current fields and the call writes what it leaves.
func (*World) EndSubscription ¶
func (w *World) EndSubscription(sub Subscription)
EndSubscription ends sub as the subscription reconcile's terminal branch does when Stripe reports it canceled, in one materializing transaction: the row is canceled and ended now, every live provision it backs is ended, the grants it replaced and marked to resume deliver again when that ended something, the floor runs on a vacant pool, the pool is materialized, and its pending scheduled changes are closed.
func (*World) Extend ¶
Extend moves g's Valid until to until through the Manage act, as the operator's Manage form does when only the bound changes: a delivering grant continues its position as a transfer, a waiting one gets a waiting successor. The note and the mark stay as they are. It returns the extension.
func (*World) Floor ¶
Floor restores the organization type's default plan into o's pool when the pool holds no rung, as provisioning does.
func (*World) ForeignPause ¶
func (w *World) ForeignPause(s Subscription)
ForeignPause records a collection pause on s without the console's marker, as a pause made in the Dashboard reads.
func (*World) Invoice ¶
func (w *World) Invoice(a Account, o InvoiceOpts) Invoice
Invoice creates an invoice on a in US dollars through the query the invoice reconcile writes with, the number and the row in one transaction.
func (*World) Issue ¶
Issue issues a grant of p to o and confers it, as the operator's Issue grant act does, made by opts.By, or by o's owner when that is zero.
func (*World) Ladder ¶
Ladder creates an active plan ladder and appends tiers to it in argument order, so the first has rank 0, in one materializing transaction, as the operator's add-tier form does.
func (*World) Lifecycle ¶
Lifecycle sets p's lifecycle status to status ("draft", "published" or "retired"). The create form writes published and no act changes the column, so draft and retired are states the console never writes; the builder writes the column in one statement.
func (*World) LineItem ¶
func (w *World) LineItem(inv Invoice, price Price, description string, cents int32, start, end time.Time)
LineItem adds a line of quantity 1 at price to inv, as the invoice reconcile writes each line it reads back.
func (*World) MapAccount ¶
MapAccount gives a a synced Stripe customer mapping with no recorded environment, which every key mode shows; see MapInvoice. The Stripe id is a's id behind "cus_".
func (*World) MapAccountIn ¶
MapAccountIn gives a a synced Stripe customer mapping recorded in the live environment when live is true and in the test environment otherwise. The Stripe id is a's id behind "cus_".
func (*World) MapInvoice ¶
MapInvoice gives inv a synced Stripe invoice mapping with no recorded environment, which every key mode shows; the console stamps every mapping it writes, so only a row from before the stamp has this state. The Stripe id is inv's id behind "in_".
func (*World) MapInvoiceIn ¶
MapInvoiceIn gives inv a synced Stripe invoice mapping recorded in the live environment when live is true and in the test environment otherwise. The Stripe id is inv's id behind "in_".
func (*World) MapPayment ¶
MapPayment gives p a synced Stripe payment mapping with no recorded environment; see MapInvoice. Its charge is p's id behind "ch_" and its payment intent p's id behind "pi_".
func (*World) MapPaymentIn ¶
MapPaymentIn gives p a synced Stripe payment mapping recorded in the live environment when live is true and in the test environment otherwise. Its charge is p's id behind "ch_" and its payment intent p's id behind "pi_".
func (*World) MapPrice ¶
MapPrice gives price a synced Stripe price mapping with no recorded environment, which every key mode reaches.
func (*World) MapPriceIn ¶
MapPriceIn gives price a synced Stripe price mapping recorded in the live environment when live is true and in the test environment otherwise.
func (*World) MapProduct ¶
MapProduct gives p a synced Stripe product mapping with no recorded environment, which every key mode reaches. The Stripe id is p's id behind "prod_".
func (*World) MapProductIn ¶
MapProductIn gives p a synced Stripe product mapping recorded in the live environment when live is true and in the test environment otherwise.
func (*World) MapSubscription ¶
func (w *World) MapSubscription(s Subscription)
MapSubscription gives s a synced Stripe subscription mapping with no recorded environment; see MapInvoice. The Stripe id is s's id behind "sub_".
func (*World) MapSubscriptionIn ¶
func (w *World) MapSubscriptionIn(s Subscription, live bool)
MapSubscriptionIn gives s a synced Stripe subscription mapping recorded in the live environment when live is true and in the test environment otherwise. The Stripe id is s's id behind "sub_".
func (*World) Member ¶
Member adds p to o as a member with the member role. The console adds only an organization's owner, with the owner role, at provisioning, so a member-role member is a state the app does not produce.
func (*World) OneTimePrice ¶
OneTimePrice creates a one-time price of p in US dollars.
func (*World) Org ¶
Org creates an organization of orgType owned by owner, with its default pool, in one materializing transaction. It does not give the organization a default plan, so a fixture does not inherit one another package committed.
func (*World) OrgType ¶
OrgType creates an active organization type with no default plan and returns its key: name, a hyphen and the last twelve digits of the World's suffix. The column holds twenty characters, so name is at most seven; the tail keeps two Worlds from colliding on the key. It is the one raw INSERT among the builders, because no console act creates an organization type.
func (*World) PauseCollection ¶
func (w *World) PauseCollection(s Subscription)
PauseCollection stands for the reconcile's record of the console's own collection pause on s: behavior void and the console's marker.
func (*World) Payment ¶
func (w *World) Payment(inv Invoice, o PaymentOpts) Payment
Payment records a payment of inv's amount due, as the payment reconcile does.
func (*World) Pool ¶
Pool creates a pool of the given type in o and returns its id. The console writes only an organization's default pool, so a second pool is a state the app does not produce.
func (*World) Price ¶
Price creates a monthly, recurring price of p in US dollars, as the operator's create form does. The first price of a product is its default.
func (*World) Product ¶
Product creates a published, public product and its own active set, as the operator's create form does.
func (*World) Providers ¶
func (w *World) Providers(srcs ...integration.ProviderSource)
Providers registers the providers as boot does and then ensures the System tenant, so the provider, resource-key and connection rows exist before a fixture names them.
func (*World) RecurringPrice ¶
RecurringPrice creates a recurring price of p in the given currency and interval ("month" or "year"); Price is RecurringPrice in usd, monthly.
func (*World) RemoveTier ¶
RemoveTier removes p's tier from l and renumbers the tiers left from 0, as the operator's remove does for a tier no organization holds. A tier with holders goes through the removal act and its dispositions, which this does not write, so it fails the test.
func (*World) ReorderTiers ¶
ReorderTiers gives l's tiers the ranks of their order in tiers, from 0, as the operator's reorder renumbers a ladder no organization type defaults to: every rank is parked below zero, then set. The reorder of a default ladder also runs the dispositions its preview asks for, which this does not.
func (*World) Retire ¶
Retire takes p out of the member catalog by deactivating it, as the operator's edit form does. Its tiers and the rungs held on it stay.
func (*World) Revoke ¶
Revoke ends the grant through the revoke act, which re-materializes the pool as production does, so a boolean entitlement it delivered lapses.
func (*World) Rule ¶
func (w *World) Rule(p Product, r entitlements.RuleFields)
Rule adds r to p's set through the rule-change function, the only write path to a set's rules.
func (*World) RuleChange ¶
func (w *World) RuleChange(p Product, r entitlements.RuleFields, by Person, note string)
RuleChange adds r to p's set as the operator's rule-change form commits it: one rule-added delta through the batch commit, made by the person by with the note, which settles the pools carrying the set in the commit. Rule is the system's path and leaves the carrying pools unsettled.
func (*World) ScheduleCancellation ¶
func (w *World) ScheduleCancellation(sub Subscription, at time.Time)
ScheduleCancellation records a cancellation of sub taking effect at at, at a commitment's boundary, as the cancel does under a block commitment.
func (*World) ScheduleDowngrade ¶
func (w *World) ScheduleDowngrade(sub Subscription, price Price, at time.Time)
ScheduleDowngrade records a downgrade of sub to price taking effect at the period end at, as the switch does.
func (*World) Subscribe ¶
func (w *World) Subscribe(o Org, opts SubOpts, products ...Product) Subscription
Subscribe creates a subscription on o's billing account, making the account when o has none, and confers each product from it in turn, as reconcile does for a purchase and then for each switch. The subscription's one item is the last product's default price.
func (*World) Suspend ¶
func (w *World) Suspend(sub Subscription, status string)
Suspend writes the pair the subscription reconcile writes for a suspending status: the subscription's status, then the suspension of the provisions sub confers and the settlement of the pool. status is past_due, unpaid or paused, and the row keeps its period, cancellation, cancelled and ended fields.
func (*World) Use ¶
Use sets the usage of key against the pool of ws's primary assignment to n, as the key's owner writes it: an absolute figure, never an increment. It fails the test when the write changes no row, because the pool has no usage row for the key; only the materializer creates one.
func (*World) WithoutSet ¶
WithoutSet clears p's entitlement set, as the operator's edit form does when it is saved with no set chosen on a product that is no plan tier. A tier's set cannot be cleared once migration 00035 is in place (chk_products_tier_keeps_set), so the kit clears it only on a product no ladder holds. A product in this state confers nothing: a grant or a subscription to it is refused or left out.