tier_test.go 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. package cmd
  2. import (
  3. "github.com/stretchr/testify/require"
  4. "github.com/urfave/cli/v2"
  5. "heckel.io/ntfy/v2/server"
  6. "heckel.io/ntfy/v2/test"
  7. "testing"
  8. )
  9. func TestCLI_Tier_AddListChangeDelete(t *testing.T) {
  10. s, conf, port := newTestServerWithAuth(t)
  11. defer test.StopServer(t, s, port)
  12. app, _, _, stderr := newTestApp()
  13. require.Nil(t, runTierCommand(app, conf, "add", "--name", "Pro", "--message-limit", "1234", "pro"))
  14. require.Contains(t, stderr.String(), "tier added\n\ntier pro (id: ti_")
  15. err := runTierCommand(app, conf, "add", "pro")
  16. require.NotNil(t, err)
  17. require.Equal(t, "tier pro already exists", err.Error())
  18. app, _, _, stderr = newTestApp()
  19. require.Nil(t, runTierCommand(app, conf, "list"))
  20. require.Contains(t, stderr.String(), "tier pro (id: ti_")
  21. require.Contains(t, stderr.String(), "- Name: Pro")
  22. require.Contains(t, stderr.String(), "- Message limit: 1234")
  23. app, _, _, stderr = newTestApp()
  24. require.Nil(t, runTierCommand(app, conf, "change",
  25. "--message-limit=999",
  26. "--message-expiry-duration=2d",
  27. "--email-limit=91",
  28. "--reservation-limit=98",
  29. "--attachment-file-size-limit=100m",
  30. "--attachment-expiry-duration=1d",
  31. "--attachment-total-size-limit=10G",
  32. "--attachment-bandwidth-limit=100G",
  33. "--stripe-monthly-price-id=price_991",
  34. "--stripe-yearly-price-id=price_992",
  35. "pro",
  36. ))
  37. require.Contains(t, stderr.String(), "- Message limit: 999")
  38. require.Contains(t, stderr.String(), "- Message expiry duration: 48h")
  39. require.Contains(t, stderr.String(), "- Email limit: 91")
  40. require.Contains(t, stderr.String(), "- Reservation limit: 98")
  41. require.Contains(t, stderr.String(), "- Attachment file size limit: 100.0 MB")
  42. require.Contains(t, stderr.String(), "- Attachment expiry duration: 24h")
  43. require.Contains(t, stderr.String(), "- Attachment total size limit: 10.0 GB")
  44. require.Contains(t, stderr.String(), "- Stripe prices (monthly/yearly): price_991 / price_992")
  45. app, _, _, stderr = newTestApp()
  46. require.Nil(t, runTierCommand(app, conf, "remove", "pro"))
  47. require.Contains(t, stderr.String(), "tier pro removed")
  48. }
  49. func runTierCommand(app *cli.App, conf *server.Config, args ...string) error {
  50. userArgs := []string{
  51. "ntfy",
  52. "--log-level=ERROR",
  53. "tier",
  54. "--config=" + conf.File, // Dummy config file to avoid lookups of real file
  55. "--auth-file=" + conf.AuthFile,
  56. "--auth-default-access=" + conf.AuthDefault.String(),
  57. }
  58. return app.Run(append(userArgs, args...))
  59. }