testutil

package
v1.13.0 Latest Latest
Warning

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

Go to latest
Published: Mar 17, 2026 License: GPL-3.0 Imports: 16 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AuthenticatedContext

func AuthenticatedContext(user *model.User, profile *model.Profile) context.Context

AuthenticatedContext returns a context with user, profile, config, and CSRF token injected.

func CreateTestExpense

func CreateTestExpense(t *testing.T, db *sqlx.DB, spaceID, userID, desc string, amount decimal.Decimal, typ model.ExpenseType) *model.Expense

CreateTestExpense inserts an expense directly into the database.

func CreateTestInvitation

func CreateTestInvitation(t *testing.T, db *sqlx.DB, spaceID, inviterID, email string) *model.SpaceInvitation

CreateTestInvitation inserts a space invitation directly into the database.

func CreateTestListItem

func CreateTestListItem(t *testing.T, db *sqlx.DB, listID, name, createdBy string) *model.ListItem

CreateTestListItem inserts a list item directly into the database.

func CreateTestMoneyAccount

func CreateTestMoneyAccount(t *testing.T, db *sqlx.DB, spaceID, name, createdBy string) *model.MoneyAccount

CreateTestMoneyAccount inserts a money account directly into the database.

func CreateTestPaymentMethod

func CreateTestPaymentMethod(t *testing.T, db *sqlx.DB, spaceID, name string, typ model.PaymentMethodType, createdBy string) *model.PaymentMethod

CreateTestPaymentMethod inserts a payment method directly into the database.

func CreateTestProfile

func CreateTestProfile(t *testing.T, db *sqlx.DB, userID, name string) *model.Profile

CreateTestProfile inserts a profile directly into the database.

func CreateTestShoppingList

func CreateTestShoppingList(t *testing.T, db *sqlx.DB, spaceID, name string) *model.ShoppingList

CreateTestShoppingList inserts a shopping list directly into the database.

func CreateTestSpace

func CreateTestSpace(t *testing.T, db *sqlx.DB, ownerID, name string) *model.Space

CreateTestSpace inserts a space and adds the owner as a member.

func CreateTestTag

func CreateTestTag(t *testing.T, db *sqlx.DB, spaceID, name string, color *string) *model.Tag

CreateTestTag inserts a tag directly into the database.

func CreateTestToken

func CreateTestToken(t *testing.T, db *sqlx.DB, userID, tokenType, tokenString string, expiresAt time.Time) *model.Token

CreateTestToken inserts a token directly into the database.

func CreateTestTransfer

func CreateTestTransfer(t *testing.T, db *sqlx.DB, accountID string, amount decimal.Decimal, direction model.TransferDirection, createdBy string) *model.AccountTransfer

CreateTestTransfer inserts an account transfer directly into the database.

func CreateTestUser

func CreateTestUser(t *testing.T, db *sqlx.DB, email string, passwordHash *string) *model.User

CreateTestUser inserts a user directly into the database.

func CreateTestUserWithProfile

func CreateTestUserWithProfile(t *testing.T, db *sqlx.DB, email, name string) (*model.User, *model.Profile)

CreateTestUserWithProfile creates both a user and a profile.

func ForEachDB

func ForEachDB(t *testing.T, fn func(t *testing.T, dbi DBInfo))

ForEachDB runs the given test function against both SQLite and PostgreSQL. PostgreSQL tests are skipped when BUDGIT_TEST_POSTGRES_URL is unset.

func NewAuthenticatedRequest

func NewAuthenticatedRequest(t *testing.T, method, target string, user *model.User, profile *model.Profile, formValues url.Values) *http.Request

NewAuthenticatedRequest creates an HTTP request with auth context and optional form values. CSRF token is automatically added to form values for POST requests.

func NewHTMXRequest

func NewHTMXRequest(req *http.Request) *http.Request

NewHTMXRequest adds HX-Request header to a request.

func TestConfig

func TestConfig() *config.Config

TestConfig returns a minimal config for tests. No env vars needed.

Types

type DBInfo

type DBInfo struct {
	DB     *sqlx.DB
	Driver string
}

DBInfo holds a test database connection and its driver name.

Jump to

Keyboard shortcuts

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