Files
zeekay 1943f1c093 Hanzo Commerce
Multi-tenant commerce and billing: orders, subscriptions, invoices, plans,
usage metering and a credit ledger. One Go binary. MIT OR Apache-2.0.

Claude-Session: https://claude.ai/code/session_01SAtaDFm8VDiWrhYHNNtxMw
2026-09-23 21:52:16 -07:00

61 lines
1.3 KiB
Go

package test
import (
"net/http"
"testing"
"github.com/hanzoai/commerce/api"
"github.com/hanzoai/commerce/datastore"
"github.com/hanzoai/commerce/models/fixtures"
"github.com/hanzoai/commerce/models/organization"
"github.com/hanzoai/commerce/util/test/ae"
"github.com/hanzoai/commerce/util/test/zipclient"
"github.com/hanzoai/commerce/util/zipctx"
. "github.com/hanzoai/commerce/util/test/ginkgo"
)
func Test(t *testing.T) {
Setup("api/store", t)
}
var (
ctx ae.Context
db *datastore.Datastore
org *organization.Organization
cl *zipclient.Client
)
// Setup test context
var _ = BeforeSuite(func() {
// Create new test context
ctx = ae.NewContext()
// Mock gin context that we can use with fixtures
c := zipctx.New(ctx)
// Run default fixtures to setup organization and default store
org = fixtures.Organization(c).(*organization.Organization)
accessToken, _ := org.GetTokenByName("test-secret-key")
org.MustUpdate()
// Save namespaced db
db = datastore.New(org.Namespaced(ctx))
// Create client so we can make requests
cl = zipclient.New(ctx)
// Set authorization header for subsequent requests
cl.Defaults(func(r *http.Request) {
r.Header.Set("Authorization", accessToken.String)
})
// Add API routes to client
api.Route(cl.Router)
})
// Tear-down test context
var _ = AfterSuite(func() {
ctx.Close()
})