fixtures

package
v1.13.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 14, 2022 License: Apache-2.0 Imports: 22 Imported by: 0

Documentation

Index

Constants

View Source
const SupportedVersions = 0

SupportedVersions is the version number of the fixture template the CLI supports

Variables

View Source
var Events = map[string]string{
	"account.application.deauthorized":         "triggers/account.application.deauthorized.json",
	"account.updated":                          "triggers/account.updated.json",
	"balance.available":                        "triggers/balance.available.json",
	"charge.captured":                          "triggers/charge.captured.json",
	"charge.dispute.created":                   "triggers/charge.disputed.created.json",
	"charge.failed":                            "triggers/charge.failed.json",
	"charge.refunded":                          "triggers/charge.refunded.json",
	"charge.refund.updated":                    "triggers/charge.refund.updated.json",
	"charge.succeeded":                         "triggers/charge.succeeded.json",
	"checkout.session.async_payment_failed":    "triggers/checkout.session.async_payment_failed.json",
	"checkout.session.async_payment_succeeded": "triggers/checkout.session.async_payment_succeeded.json",
	"checkout.session.completed":               "triggers/checkout.session.completed.json",
	"customer.created":                         "triggers/customer.created.json",
	"customer.deleted":                         "triggers/customer.deleted.json",
	"customer.updated":                         "triggers/customer.updated.json",
	"customer.source.created":                  "triggers/customer.source.created.json",
	"customer.source.updated":                  "triggers/customer.source.updated.json",
	"customer.subscription.created":            "triggers/customer.subscription.created.json",
	"customer.subscription.deleted":            "triggers/customer.subscription.deleted.json",
	"customer.subscription.updated":            "triggers/customer.subscription.updated.json",
	"invoice.created":                          "triggers/invoice.created.json",
	"invoice.finalized":                        "triggers/invoice.finalized.json",
	"invoice.paid":                             "triggers/invoice.paid.json",
	"invoice.payment_action_required":          "triggers/invoice.payment_action_required.json",
	"invoice.payment_failed":                   "triggers/invoice.payment_failed.json",
	"invoice.payment_succeeded":                "triggers/invoice.payment_succeeded.json",
	"invoice.updated":                          "triggers/invoice.updated.json",
	"issuing_authorization.request":            "triggers/issuing_authorization.request.json",
	"issuing_card.created":                     "triggers/issuing_card.created.json",
	"issuing_cardholder.created":               "triggers/issuing_cardholder.created.json",
	"payment_intent.amount_capturable_updated": "triggers/payment_intent.amount_capturable_updated.json",
	"payment_intent.created":                   "triggers/payment_intent.created.json",
	"payment_intent.payment_failed":            "triggers/payment_intent.payment_failed.json",
	"payment_intent.succeeded":                 "triggers/payment_intent.succeeded.json",
	"payment_intent.canceled":                  "triggers/payment_intent.canceled.json",
	"payment_link.created":                     "triggers/payment_link.created.json",
	"payment_link.updated":                     "triggers/payment_link.updated.json",
	"payment_intent.partially_funded":          "triggers/payment_intent.partially_funded.json",
	"payment_intent.requires_action":           "triggers/payment_intent.requires_action.json",
	"payment_method.attached":                  "triggers/payment_method.attached.json",
	"payout.created":                           "triggers/payout.created.json",
	"payout.updated":                           "triggers/payout.updated.json",
	"plan.created":                             "triggers/plan.created.json",
	"plan.deleted":                             "triggers/plan.deleted.json",
	"plan.updated":                             "triggers/plan.updated.json",
	"price.created":                            "triggers/price.created.json",
	"price.updated":                            "triggers/price.updated.json",
	"product.created":                          "triggers/product.created.json",
	"product.deleted":                          "triggers/product.deleted.json",
	"product.updated":                          "triggers/product.updated.json",
	"reporting.report_run.succeeded":           "triggers/reporting.report_run.succeeded.json",
	"setup_intent.canceled":                    "triggers/setup_intent.canceled.json",
	"setup_intent.created":                     "triggers/setup_intent.created.json",
	"setup_intent.setup_failed":                "triggers/setup_intent.setup_failed.json",
	"setup_intent.succeeded":                   "triggers/setup_intent.succeeded.json",
	"subscription_schedule.canceled":           "triggers/subscription_schedule.canceled.json",
	"subscription_schedule.created":            "triggers/subscription_schedule.created.json",
	"subscription_schedule.released":           "triggers/subscription_schedule.released.json",
	"subscription_schedule.updated":            "triggers/subscription_schedule.updated.json",
	"quote.created":                            "triggers/quote.created.json",
	"quote.canceled":                           "triggers/quote.canceled.json",
	"quote.finalized":                          "triggers/quote.finalized.json",
	"quote.accepted":                           "triggers/quote.accepted.json",
}

Events is a mapping of pre-built trigger events and the corresponding json file

Functions

func EventList

func EventList() string

EventList prints out a padded list of supported trigger events for printing the help file

func EventNames

func EventNames() []string

EventNames returns an array of all the event names

func MatchFixtureQuery added in v1.13.0

func MatchFixtureQuery(value string) (*regexp.Regexp, bool)

MatchFixtureQuery will attempt to find matches for a fixture query pattern returning a *Regexp which can be used to further parse and a boolean indicating a match was found.

func Trigger added in v1.6.0

func Trigger(ctx context.Context, event string, stripeAccount string, baseURL string, apiKey string, skip, override, add, remove []string, raw string, apiVersion string) ([]string, error)

Trigger triggers a Stripe event.

Types

type Fixture

type Fixture struct {
	Fs            afero.Fs
	APIKey        string
	StripeAccount string
	Skip          []string
	Overrides     map[string]interface{}
	Additions     map[string]interface{}
	Removals      map[string]interface{}
	BaseURL       string
	Responses     map[string]gjson.Result
	FixtureData   FixtureData
}

Fixture contains a mapping of an individual fixtures responses for querying

func BuildFromFixtureFile added in v1.7.5

func BuildFromFixtureFile(fs afero.Fs, apiKey, stripeAccount, apiBaseURL, jsonFile string, skip, override, add, remove []string) (*Fixture, error)

BuildFromFixtureFile creates a new fixture struct for a file

func BuildFromFixtureString added in v1.7.5

func BuildFromFixtureString(fs afero.Fs, apiKey, stripeAccount, apiBaseURL, raw string) (*Fixture, error)

BuildFromFixtureString creates a new fixture from a string

func NewFixtureFromFile added in v1.7.5

func NewFixtureFromFile(fs afero.Fs, apiKey, stripeAccount, baseURL, file string, skip, override, add, remove []string) (*Fixture, error)

NewFixtureFromFile creates a to later run steps for populating test data

func NewFixtureFromRawString added in v1.7.5

func NewFixtureFromRawString(fs afero.Fs, apiKey, stripeAccount, baseURL, raw string) (*Fixture, error)

NewFixtureFromRawString creates fixtures from user inputted string

func (*Fixture) Add added in v1.7.2

func (fxt *Fixture) Add(additions []string) error

Add safely only adds any missing fields that do not already exist. If the field is already on the fixture, it does not get copied over. For that, `Override` should be used

func (*Fixture) Execute

func (fxt *Fixture) Execute(ctx context.Context, apiVersion string) ([]string, error)

Execute takes the parsed fixture file and runs through all the requests defined to populate the user's account

func (*Fixture) GetFixtureFileContent added in v1.7.5

func (fxt *Fixture) GetFixtureFileContent() string

GetFixtureFileContent returns the file content of the given fixture file name

func (*Fixture) Override added in v1.7.2

func (fxt *Fixture) Override(overrides []string) error

Override forcefully overrides fields with existing data on a fixture

func (*Fixture) ParseArray added in v1.13.0

func (fxt *Fixture) ParseArray(params []interface{}, parent string) ([]string, error)

ParseArray is similar to parseMap but doesn't have to build the multi-depth keys. Form data arrays contain brackets with nothing inside the bracket to designate an array instead of a key value pair.

func (*Fixture) ParseInterface added in v1.13.0

func (fxt *Fixture) ParseInterface(params interface{}) ([]string, error)

ParseInterface is the primary entrypoint into building the request data for fixtures. The data will always be provided as an interface{} and this will need to use reflection to determine how to proceed. There are two primary paths here, `parseMap` and `ParseArray`, which will recursively traverse and convert the data

This returns an array of clean form data to make the request.

func (*Fixture) ParseMap added in v1.13.0

func (fxt *Fixture) ParseMap(params map[string]interface{}, parent string, index int) ([]string, error)

ParseMap recursively parses a map of string => interface{} until each leaf node has a terminal type (String, Int, etc) that can no longer be recursively traversed.

func (*Fixture) ParsePath added in v1.13.0

func (fxt *Fixture) ParsePath(http FixtureRequest) (string, error)

ParsePath will inspect the path to see if it has a query in the path for requests that operate on specific objects (for example, GET /v1/customers/:id or POST /v1/subscriptions/:id)

If a query is found, this returns the path with the value already in place. If there is no query, it returns the old path as-is.

func (*Fixture) ParseQuery added in v1.13.0

func (fxt *Fixture) ParseQuery(queryString string) (string, error)

ParseQuery checks strings for possible queries and replaces the corresponding value in its place. The supported query format is:

$<name of fixture>:dot.path.to.field

func (*Fixture) Remove added in v1.7.2

func (fxt *Fixture) Remove(removals []string) error

Remove removes fields from the fixture

func (*Fixture) UpdateEnv

func (fxt *Fixture) UpdateEnv() error

UpdateEnv uses the results of the fixtures command just executed and updates a local .env with the resulting data

type FixtureData added in v1.13.0

type FixtureData struct {
	Meta     MetaFixture       `json:"_meta"`
	Requests []FixtureRequest  `json:"fixtures"`
	Env      map[string]string `json:"env"`
}

FixtureData contains the whole fixture file

type FixtureQuery added in v1.13.0

type FixtureQuery struct {
	Match        string // The substring that matched the query pattern regex
	Name         string
	Query        string
	DefaultValue string
}

FixtureQuery describes the query in fixture request

func ToFixtureQuery added in v1.13.0

func ToFixtureQuery(value string) (FixtureQuery, bool)

ToFixtureQuery will parse a string into a fixtureQuery struct, additionally returning a bool indicating the value did contain a fixtureQuery.

type FixtureRequest added in v1.13.0

type FixtureRequest struct {
	Name              string                 `json:"name"`
	ExpectedErrorType string                 `json:"expected_error_type"`
	Path              string                 `json:"path"`
	Method            string                 `json:"method"`
	Params            map[string]interface{} `json:"params"`
}

FixtureRequest is the individual request payload

type MetaFixture added in v1.13.0

type MetaFixture struct {
	Version         int  `json:"template_version"`
	ExcludeMetadata bool `json:"exclude_metadata"`
}

MetaFixture contains fixture metadata

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL