mirror of
https://github.com/binwiederhier/ntfy.git
synced 2024-11-23 11:49:19 +01:00
60 lines
1.6 KiB
Go
60 lines
1.6 KiB
Go
package user
|
|
|
|
import (
|
|
"github.com/stretchr/testify/require"
|
|
"testing"
|
|
)
|
|
|
|
func TestPermission(t *testing.T) {
|
|
require.Equal(t, PermissionReadWrite, NewPermission(true, true))
|
|
require.Equal(t, PermissionRead, NewPermission(true, false))
|
|
require.Equal(t, PermissionWrite, NewPermission(false, true))
|
|
require.Equal(t, PermissionDenyAll, NewPermission(false, false))
|
|
require.True(t, PermissionReadWrite.IsReadWrite())
|
|
require.True(t, PermissionReadWrite.IsRead())
|
|
require.True(t, PermissionReadWrite.IsWrite())
|
|
require.True(t, PermissionRead.IsRead())
|
|
require.True(t, PermissionWrite.IsWrite())
|
|
}
|
|
|
|
func TestParsePermission(t *testing.T) {
|
|
_, err := ParsePermission("no")
|
|
require.NotNil(t, err)
|
|
|
|
p, err := ParsePermission("read-write")
|
|
require.Nil(t, err)
|
|
require.Equal(t, PermissionReadWrite, p)
|
|
|
|
p, err = ParsePermission("rw")
|
|
require.Nil(t, err)
|
|
require.Equal(t, PermissionReadWrite, p)
|
|
|
|
p, err = ParsePermission("read-only")
|
|
require.Nil(t, err)
|
|
require.Equal(t, PermissionRead, p)
|
|
|
|
p, err = ParsePermission("WRITE")
|
|
require.Nil(t, err)
|
|
require.Equal(t, PermissionWrite, p)
|
|
|
|
p, err = ParsePermission("deny-all")
|
|
require.Nil(t, err)
|
|
require.Equal(t, PermissionDenyAll, p)
|
|
}
|
|
|
|
func TestAllowedTier(t *testing.T) {
|
|
require.False(t, AllowedTier(" no"))
|
|
require.True(t, AllowedTier("yes"))
|
|
}
|
|
|
|
func TestTierContext(t *testing.T) {
|
|
tier := &Tier{
|
|
ID: "ti_abc",
|
|
Code: "pro",
|
|
StripePriceID: "price_123",
|
|
}
|
|
context := tier.Context()
|
|
require.Equal(t, "ti_abc", context["tier_id"])
|
|
require.Equal(t, "pro", context["tier_code"])
|
|
require.Equal(t, "price_123", context["stripe_price_id"])
|
|
}
|