1
0
Fork 0
mirror of https://github.com/binwiederhier/ntfy.git synced 2024-12-23 10:12:38 +01:00
ntfy/cmd/tier_test.go

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

68 lines
2.4 KiB
Go
Raw Normal View History

2023-02-07 18:02:25 +01:00
package cmd
import (
"github.com/stretchr/testify/require"
"github.com/urfave/cli/v2"
"heckel.io/ntfy/server"
"heckel.io/ntfy/test"
"testing"
)
func TestCLI_Tier_AddListChangeDelete(t *testing.T) {
s, conf, port := newTestServerWithAuth(t)
defer test.StopServer(t, s, port)
app, _, _, stderr := newTestApp()
require.Nil(t, runTierCommand(app, conf, "add", "--name", "Pro", "--message-limit", "1234", "pro"))
require.Contains(t, stderr.String(), "tier added\n\ntier pro (id: ti_")
err := runTierCommand(app, conf, "add", "pro")
require.NotNil(t, err)
require.Equal(t, "tier pro already exists", err.Error())
app, _, _, stderr = newTestApp()
require.Nil(t, runTierCommand(app, conf, "list"))
require.Contains(t, stderr.String(), "tier pro (id: ti_")
require.Contains(t, stderr.String(), "- Name: Pro")
require.Contains(t, stderr.String(), "- Message limit: 1234")
app, _, _, stderr = newTestApp()
2023-02-09 21:24:12 +01:00
require.Nil(t, runTierCommand(app, conf, "change",
"--message-limit=999",
2023-02-27 20:34:05 +01:00
"--message-expiry-duration=2d",
2023-02-09 21:24:12 +01:00
"--email-limit=91",
"--reservation-limit=98",
"--attachment-file-size-limit=100m",
2023-02-27 20:34:05 +01:00
"--attachment-expiry-duration=1d",
2023-02-09 21:24:12 +01:00
"--attachment-total-size-limit=10G",
"--attachment-bandwidth-limit=100G",
2023-02-22 04:44:30 +01:00
"--stripe-monthly-price-id=price_991",
"--stripe-yearly-price-id=price_992",
2023-02-09 21:24:12 +01:00
"pro",
))
2023-02-07 18:02:25 +01:00
require.Contains(t, stderr.String(), "- Message limit: 999")
2023-02-27 20:34:05 +01:00
require.Contains(t, stderr.String(), "- Message expiry duration: 48h")
2023-02-09 21:24:12 +01:00
require.Contains(t, stderr.String(), "- Email limit: 91")
require.Contains(t, stderr.String(), "- Reservation limit: 98")
require.Contains(t, stderr.String(), "- Attachment file size limit: 100.0 MB")
2023-02-27 20:34:05 +01:00
require.Contains(t, stderr.String(), "- Attachment expiry duration: 24h")
2023-02-09 21:24:12 +01:00
require.Contains(t, stderr.String(), "- Attachment total size limit: 10.0 GB")
2023-02-22 04:44:30 +01:00
require.Contains(t, stderr.String(), "- Stripe prices (monthly/yearly): price_991 / price_992")
2023-02-07 18:02:25 +01:00
app, _, _, stderr = newTestApp()
require.Nil(t, runTierCommand(app, conf, "remove", "pro"))
require.Contains(t, stderr.String(), "tier pro removed")
}
func runTierCommand(app *cli.App, conf *server.Config, args ...string) error {
userArgs := []string{
"ntfy",
2023-02-08 21:20:44 +01:00
"--log-level=ERROR",
2023-02-07 18:02:25 +01:00
"tier",
2023-02-08 21:20:44 +01:00
"--config=" + conf.File, // Dummy config file to avoid lookups of real file
2023-02-07 18:02:25 +01:00
"--auth-file=" + conf.AuthFile,
"--auth-default-access=" + conf.AuthDefault.String(),
}
return app.Run(append(userArgs, args...))
}