Documentation
¶
Index ¶
- func Get(t *testing.T, url string) (*http.Response, error)
- func NewMockShopwareServer(t *testing.T) *httptest.Server
- func NewRequest(t *testing.T, method, url string, body io.Reader) *http.Request
- func Post(t *testing.T, url, contentType string, body io.Reader) (*http.Response, error)
- type TestEnv
- func (e *TestEnv) AuthRequest(t *testing.T, method, path, token string) *http.Request
- func (e *TestEnv) SeedEnvironment(t *testing.T, orgID string, shopID int, name, url string) int
- func (e *TestEnv) SeedMember(t *testing.T, orgID, userID, role string)
- func (e *TestEnv) SeedNotification(t *testing.T, userID, key, level, title, message string) int
- func (e *TestEnv) SeedOrganization(t *testing.T, orgID, name, slug, userID string)
- func (e *TestEnv) SeedShop(t *testing.T, orgID, name string) int
- func (e *TestEnv) SeedUser(t *testing.T, id, name, email, role string) string
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Get ¶
Get performs a context-aware GET, replacing http.Get in tests so requests carry the test's context (and satisfy the noctx linter).
func NewMockShopwareServer ¶
NewMockShopwareServer creates a mock Shopware API server that handles OAuth token and info endpoints.
func NewRequest ¶
NewRequest builds a context-aware request, replacing http.NewRequest in tests.
Types ¶
type TestEnv ¶
type TestEnv struct {
Pool *pgxpool.Pool
Queries *queries.Queries
Handler *handler.Handler
Server *httptest.Server
Cfg *config.Config
// Mail captures every email sent during the test, in place of real
// delivery. Use the mailertest assertion helpers against it.
Mail *mailertest.RecordingTransport
}
TestEnv holds all test dependencies.
func Setup ¶
Setup creates a new TestEnv using shared Postgres and Redis containers. Each test gets a clean database via TRUNCATE. Optional cfgFn modifiers are applied to the config before building the handler.
func (*TestEnv) AuthRequest ¶
AuthRequest creates a new HTTP request with the session token set.
func (*TestEnv) SeedEnvironment ¶
SeedEnvironment creates a test environment in an organization/shop. It also sets the environment as the shop's default if none is set.
func (*TestEnv) SeedMember ¶
SeedMember adds a user to an existing organization with an explicit role. SeedOrganization always creates an owner, so this is what makes role-gated behaviour (member vs owner/admin) testable.
func (*TestEnv) SeedNotification ¶
SeedNotification creates a test notification for a user.
func (*TestEnv) SeedOrganization ¶
SeedOrganization creates a test organization and adds the user as a member.