Account: Refactor access token API and request forms #808 #4114

Signed-off-by: Michael Mayer <michael@photoprism.app>
This commit is contained in:
Michael Mayer
2024-04-05 14:46:11 +02:00
parent 8208f80be5
commit fdc2062d33
92 changed files with 1659 additions and 1085 deletions

View File

@@ -0,0 +1,44 @@
package form
import (
"testing"
"github.com/stretchr/testify/assert"
)
func TestPasscode_HasPassword(t *testing.T) {
t.Run("True", func(t *testing.T) {
form := &Passcode{Type: "totp", Password: "passwd1234", Code: "123456"}
assert.Equal(t, true, form.HasPassword())
})
t.Run("False", func(t *testing.T) {
form := &Passcode{Type: "totp", Password: "", Code: "123456"}
assert.Equal(t, false, form.HasPassword())
})
}
func TestPasscode_HasPasscode(t *testing.T) {
t.Run("True", func(t *testing.T) {
form := &Passcode{Type: "totp", Password: "passwd1234", Code: "123456"}
assert.Equal(t, true, form.HasPasscode())
})
t.Run("False", func(t *testing.T) {
form := &Passcode{Type: "totp", Password: "passwd1234", Code: ""}
assert.Equal(t, false, form.HasPasscode())
})
}
func TestPasscode_Passcode(t *testing.T) {
t.Run("Valid", func(t *testing.T) {
form := &Passcode{Type: "totp", Password: "passwd1234", Code: "123456"}
assert.Equal(t, "123456", form.Passcode())
})
t.Run("Recovery", func(t *testing.T) {
form := &Passcode{Type: "totp", Password: "passwd1234", Code: " A23 456 H7l pwf"}
assert.Equal(t, "a23456h7lpwf", form.Passcode())
})
t.Run("Empty", func(t *testing.T) {
form := &Passcode{Type: "totp", Password: "passwd1234", Code: ""}
assert.Equal(t, "", form.Passcode())
})
}