mirror of
https://github.com/hanzoai/commerce.git
synced 2026-10-30 15:08:42 +00:00
EmbedConfig.Ceiling is declared by the host as Born is: Test where the network holds no real money, "" or Live for no cap, and any other value caps at Test. Under a Test ceiling TestMode is true for every org, a record marked Live included, so it charges sandbox credentials, writes the test books and publishes the sandbox application. TestMode is the one reading of the mode: the ledger, balance, transaction, library, account and Authorize.Net paths, StripeToken and PayPal read it instead of org.Live, so the ceiling holds on each of them. Co-authored-by: Hanzo Dev <[email protected]>
59 lines
1.5 KiB
Go
59 lines
1.5 KiB
Go
package organization
|
|
|
|
import "testing"
|
|
|
|
// ceiling caps every org at k for one test and restores the cap after.
|
|
func ceiling(t *testing.T, k Kind) {
|
|
t.Helper()
|
|
prev := Ceiling
|
|
Ceiling = k
|
|
t.Cleanup(func() { Ceiling = prev })
|
|
}
|
|
|
|
// Undeclared, there is no cap: the record decides.
|
|
func TestCeilingUndeclaredIsNoCap(t *testing.T) {
|
|
if Ceiling != Live {
|
|
t.Fatalf("Ceiling = %q with nothing declared, want %q (no cap)", Ceiling, Live)
|
|
}
|
|
o := Organization{}
|
|
o.Live = true
|
|
if o.TestMode() {
|
|
t.Fatal("a live org is in test mode with no ceiling declared")
|
|
}
|
|
}
|
|
|
|
// A Test ceiling puts a record marked Live in test, on every reading of the
|
|
// mode: TestMode, the Square environment, In(Live) and the Stripe token.
|
|
func TestCeilingTestCapsALiveRecord(t *testing.T) {
|
|
ceiling(t, Test)
|
|
|
|
o := Organization{}
|
|
o.Live = true
|
|
o.Stripe.Live.AccessToken = "sk_live_hostile"
|
|
o.Stripe.Test.AccessToken = "sk_test_ok"
|
|
|
|
if !o.TestMode() {
|
|
t.Fatal("TestMode = false for a live record under a Test ceiling")
|
|
}
|
|
if got := o.SquareEnvironment(); got != "sandbox" {
|
|
t.Fatalf("SquareEnvironment = %q, want sandbox", got)
|
|
}
|
|
if !o.In(Live).TestMode() {
|
|
t.Fatal("In(Live) lifted the ceiling")
|
|
}
|
|
if got := o.StripeToken(); got != "sk_test_ok" {
|
|
t.Fatalf("StripeToken = %q under a Test ceiling, want the test token", got)
|
|
}
|
|
}
|
|
|
|
// A ceiling nobody recognises caps, never lifts.
|
|
func TestCeilingUnknownCaps(t *testing.T) {
|
|
ceiling(t, Kind("staging"))
|
|
|
|
o := Organization{}
|
|
o.Live = true
|
|
if !o.TestMode() {
|
|
t.Fatal("an unrecognised ceiling let a live record transact live")
|
|
}
|
|
}
|