You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

58 lines
2.2 KiB

  1. package controller
  2. import (
  3. "testing"
  4. "github.com/QuantumNous/new-api/setting"
  5. "github.com/QuantumNous/new-api/setting/operation_setting"
  6. "github.com/stretchr/testify/require"
  7. )
  8. func TestStripeWebhookAvailabilityRequiresAllTopUpCredentials(t *testing.T) {
  9. oldAPI, oldWebhook, oldPrice := setting.StripeApiSecret, setting.StripeWebhookSecret, setting.StripePriceId
  10. t.Cleanup(func() {
  11. setting.StripeApiSecret, setting.StripeWebhookSecret, setting.StripePriceId = oldAPI, oldWebhook, oldPrice
  12. })
  13. setting.StripeApiSecret, setting.StripeWebhookSecret, setting.StripePriceId = "api", "webhook", "price"
  14. require.True(t, isStripeTopUpEnabled())
  15. require.True(t, isStripeWebhookEnabled())
  16. setting.StripeWebhookSecret = " "
  17. require.False(t, isStripeTopUpEnabled())
  18. require.False(t, isStripeWebhookEnabled())
  19. }
  20. func TestCreemWebhookAvailabilityRequiresProductsAndWebhookSecret(t *testing.T) {
  21. oldAPI, oldProducts, oldWebhook := setting.CreemApiKey, setting.CreemProducts, setting.CreemWebhookSecret
  22. t.Cleanup(func() {
  23. setting.CreemApiKey, setting.CreemProducts, setting.CreemWebhookSecret = oldAPI, oldProducts, oldWebhook
  24. })
  25. setting.CreemApiKey, setting.CreemProducts, setting.CreemWebhookSecret = "api", "[]", "webhook"
  26. require.False(t, isCreemTopUpEnabled())
  27. require.False(t, isCreemWebhookEnabled())
  28. setting.CreemProducts = `[{"id":"product"}]`
  29. require.True(t, isCreemTopUpEnabled())
  30. require.True(t, isCreemWebhookEnabled())
  31. setting.CreemWebhookSecret = ""
  32. require.False(t, isCreemWebhookEnabled())
  33. }
  34. func TestEpayWebhookAvailabilityRequiresPaymentMethod(t *testing.T) {
  35. oldAddress, oldID, oldKey, oldMethods := operation_setting.PayAddress, operation_setting.EpayId, operation_setting.EpayKey, operation_setting.PayMethods
  36. t.Cleanup(func() {
  37. operation_setting.PayAddress, operation_setting.EpayId, operation_setting.EpayKey, operation_setting.PayMethods = oldAddress, oldID, oldKey, oldMethods
  38. })
  39. operation_setting.PayAddress, operation_setting.EpayId, operation_setting.EpayKey = "https://pay.example", "merchant", "secret"
  40. operation_setting.PayMethods = nil
  41. require.True(t, isEpayTopUpEnabled())
  42. require.False(t, isEpayWebhookEnabled())
  43. operation_setting.PayMethods = []map[string]string{{"name": "alipay"}}
  44. require.True(t, isEpayWebhookEnabled())
  45. }