Files
photoprism/internal/entity/auth_client_add_test.go
2025-02-05 00:30:45 +01:00

58 lines
988 B
Go

package entity
import (
"testing"
"github.com/stretchr/testify/assert"
"github.com/photoprism/photoprism/internal/form"
)
func Test_AddClient(t *testing.T) {
t.Run("Success", func(t *testing.T) {
m := form.Client{
ClientName: "test",
AuthProvider: "client_credentials",
AuthMethod: "oauth2",
AuthScope: "all",
}
c, err := AddClient(m)
if err != nil {
t.Fatal(err)
}
assert.Equal(t, "test", c.ClientName)
})
t.Run("ClientNameEmpty", func(t *testing.T) {
m := form.Client{
ClientName: "",
AuthProvider: "client_credentials",
AuthMethod: "oauth2",
AuthScope: "all",
}
c, err := AddClient(m)
if err == nil {
t.Fatal("error expected")
}
assert.Equal(t, "", c.ClientName)
})
t.Run("ExistingClient", func(t *testing.T) {
m := form.Client{
ClientID: "cs5cpu17n6gj2qo5",
}
c, err := AddClient(m)
if err == nil {
t.Fatal("error expected")
}
assert.Equal(t, "Monitoring", c.ClientName)
})
}