mirror of
https://github.com/hanzoai/commerce.git
synced 2026-10-30 15:08:42 +00:00
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
61 lines
1.3 KiB
Go
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/site", 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()
|
|
})
|