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