|
- package controller
-
- import (
- "testing"
-
- "github.com/QuantumNous/new-api/setting"
- "github.com/QuantumNous/new-api/setting/operation_setting"
- "github.com/stretchr/testify/require"
- )
-
- func TestStripeWebhookAvailabilityRequiresAllTopUpCredentials(t *testing.T) {
- oldAPI, oldWebhook, oldPrice := setting.StripeApiSecret, setting.StripeWebhookSecret, setting.StripePriceId
- t.Cleanup(func() {
- setting.StripeApiSecret, setting.StripeWebhookSecret, setting.StripePriceId = oldAPI, oldWebhook, oldPrice
- })
-
- setting.StripeApiSecret, setting.StripeWebhookSecret, setting.StripePriceId = "api", "webhook", "price"
- require.True(t, isStripeTopUpEnabled())
- require.True(t, isStripeWebhookEnabled())
-
- setting.StripeWebhookSecret = " "
- require.False(t, isStripeTopUpEnabled())
- require.False(t, isStripeWebhookEnabled())
- }
-
- func TestCreemWebhookAvailabilityRequiresProductsAndWebhookSecret(t *testing.T) {
- oldAPI, oldProducts, oldWebhook := setting.CreemApiKey, setting.CreemProducts, setting.CreemWebhookSecret
- t.Cleanup(func() {
- setting.CreemApiKey, setting.CreemProducts, setting.CreemWebhookSecret = oldAPI, oldProducts, oldWebhook
- })
-
- setting.CreemApiKey, setting.CreemProducts, setting.CreemWebhookSecret = "api", "[]", "webhook"
- require.False(t, isCreemTopUpEnabled())
- require.False(t, isCreemWebhookEnabled())
-
- setting.CreemProducts = `[{"id":"product"}]`
- require.True(t, isCreemTopUpEnabled())
- require.True(t, isCreemWebhookEnabled())
-
- setting.CreemWebhookSecret = ""
- require.False(t, isCreemWebhookEnabled())
- }
-
- func TestEpayWebhookAvailabilityRequiresPaymentMethod(t *testing.T) {
- oldAddress, oldID, oldKey, oldMethods := operation_setting.PayAddress, operation_setting.EpayId, operation_setting.EpayKey, operation_setting.PayMethods
- t.Cleanup(func() {
- operation_setting.PayAddress, operation_setting.EpayId, operation_setting.EpayKey, operation_setting.PayMethods = oldAddress, oldID, oldKey, oldMethods
- })
-
- operation_setting.PayAddress, operation_setting.EpayId, operation_setting.EpayKey = "https://pay.example", "merchant", "secret"
- operation_setting.PayMethods = nil
- require.True(t, isEpayTopUpEnabled())
- require.False(t, isEpayWebhookEnabled())
-
- operation_setting.PayMethods = []map[string]string{{"name": "alipay"}}
- require.True(t, isEpayWebhookEnabled())
- }
|