mirror of
https://github.com/photoprism/photoprism.git
synced 2025-12-12 00:34:13 +01:00
Tests: Add unit tests
This commit is contained in:
28
internal/commands/clients_add_test.go
Normal file
28
internal/commands/clients_add_test.go
Normal file
@@ -0,0 +1,28 @@
|
||||
package commands
|
||||
|
||||
import (
|
||||
"github.com/photoprism/photoprism/pkg/capture"
|
||||
"github.com/stretchr/testify/assert"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestClientsAddCommand(t *testing.T) {
|
||||
t.Run("AddClient", func(t *testing.T) {
|
||||
var err error
|
||||
|
||||
ctx := NewTestContext([]string{"add", "--name=Clara Client", "--scope=photos albums", "--expires=5000", "--tokens=2", "clara"})
|
||||
|
||||
// Run command with test context.
|
||||
output := capture.Output(func() {
|
||||
err = ClientsAddCommand.Run(ctx)
|
||||
})
|
||||
|
||||
// Check command output for plausibility.
|
||||
// t.Logf(output)
|
||||
assert.NoError(t, err)
|
||||
assert.Contains(t, output, "Clara Client")
|
||||
assert.Contains(t, output, "client")
|
||||
assert.Contains(t, output, "albums photos")
|
||||
assert.Contains(t, output, "Client Secret")
|
||||
})
|
||||
}
|
||||
48
internal/commands/clients_remove_test.go
Normal file
48
internal/commands/clients_remove_test.go
Normal file
@@ -0,0 +1,48 @@
|
||||
package commands
|
||||
|
||||
import (
|
||||
"github.com/photoprism/photoprism/pkg/capture"
|
||||
"github.com/stretchr/testify/assert"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestCientsRemoveCommand(t *testing.T) {
|
||||
t.Run("RemoveClient", func(t *testing.T) {
|
||||
var err error
|
||||
|
||||
ctx0 := NewTestContext([]string{"show", "cs7pvt5h8rw9aaqj"})
|
||||
|
||||
output0 := capture.Output(func() {
|
||||
err = ClientsShowCommand.Run(ctx0)
|
||||
})
|
||||
|
||||
//t.Logf(output0)
|
||||
assert.NoError(t, err)
|
||||
assert.NotContains(t, output0, "| DeletedAt | time.Date")
|
||||
assert.Contains(t, output0, "| DeletedAt | <nil>")
|
||||
|
||||
// Create test context with flags and arguments.
|
||||
ctx := NewTestContext([]string{"rm", "--force", "cs7pvt5h8rw9aaqj"})
|
||||
|
||||
// Run command with test context.
|
||||
output := capture.Output(func() {
|
||||
err = ClientsRemoveCommand.Run(ctx)
|
||||
})
|
||||
|
||||
// Check command output for plausibility.
|
||||
//t.Logf(output)
|
||||
assert.NoError(t, err)
|
||||
assert.Empty(t, output)
|
||||
|
||||
ctx2 := NewTestContext([]string{"show", "cs7pvt5h8rw9aaqj"})
|
||||
|
||||
output2 := capture.Output(func() {
|
||||
err = ClientsShowCommand.Run(ctx2)
|
||||
})
|
||||
|
||||
//t.Logf(output2)
|
||||
assert.NoError(t, err)
|
||||
assert.Contains(t, output2, "| DeletedAt | time.Date")
|
||||
assert.NotContains(t, output2, "| DeletedAt | <nil>")
|
||||
})
|
||||
}
|
||||
@@ -115,6 +115,24 @@ var ClientFixtures = ClientMap{
|
||||
LastActive: 0,
|
||||
DeletedAt: TimePointer(),
|
||||
},
|
||||
"analytics": {
|
||||
ClientUID: "cs7pvt5h8rw9aaqj",
|
||||
UserUID: "",
|
||||
UserName: "",
|
||||
user: nil,
|
||||
ClientName: "Analytics",
|
||||
ClientRole: acl.RoleClient.String(),
|
||||
ClientType: authn.ClientConfidential,
|
||||
ClientURL: "",
|
||||
CallbackURL: "",
|
||||
AuthProvider: authn.ProviderClientCredentials.String(),
|
||||
AuthMethod: authn.MethodOAuth2.String(),
|
||||
AuthScope: "statistics",
|
||||
AuthExpires: UnixHour,
|
||||
AuthTokens: 2,
|
||||
AuthEnabled: true,
|
||||
LastActive: 0,
|
||||
},
|
||||
}
|
||||
|
||||
// CreateClientFixtures inserts known entities into the database for testing.
|
||||
|
||||
@@ -204,6 +204,23 @@ var SessionFixtures = SessionMap{
|
||||
PreviewToken: "py2xrgr3",
|
||||
DownloadToken: "vgln2ffb",
|
||||
},
|
||||
"client_analytics": {
|
||||
authToken: "9d8b8801ffa23eb52e08ca7766283799ddfd8dd368212123",
|
||||
ID: rnd.SessionID("9d8b8801ffa23eb52e08ca7766283799ddfd8dd368212123"),
|
||||
RefID: "sessgh6123yt",
|
||||
SessTimeout: 0,
|
||||
SessExpires: UnixTime() + UnixWeek,
|
||||
AuthScope: clean.Scope("statistics"),
|
||||
AuthProvider: authn.ProviderClientCredentials.String(),
|
||||
AuthMethod: authn.MethodOAuth2.String(),
|
||||
ClientUID: ClientFixtures.Get("analytics").ClientUID,
|
||||
ClientName: ClientFixtures.Get("analytics").ClientName,
|
||||
user: nil,
|
||||
UserUID: "",
|
||||
UserName: "",
|
||||
PreviewToken: "py2123yt",
|
||||
DownloadToken: "vgl123yt",
|
||||
},
|
||||
}
|
||||
|
||||
// CreateSessionFixtures inserts known entities into the database for testing.
|
||||
|
||||
Reference in New Issue
Block a user