add document service and acitons
This commit is contained in:
@@ -0,0 +1,65 @@
|
||||
package node
|
||||
|
||||
import (
|
||||
"context"
|
||||
"testing"
|
||||
|
||||
"mediarr/document"
|
||||
"mediarr/ident"
|
||||
"mediarr/identity"
|
||||
)
|
||||
|
||||
func TestNodeDocuments(t *testing.T) {
|
||||
t.Chdir(t.TempDir())
|
||||
|
||||
err, node := NewNode(NewNodeParams{DatabaseName: "documents"})
|
||||
if err != nil {
|
||||
t.Fatalf("NewNode : %v", err)
|
||||
}
|
||||
t.Cleanup(func() {
|
||||
if err := node.Close(); err != nil {
|
||||
t.Errorf("Close : %v", err)
|
||||
}
|
||||
})
|
||||
|
||||
if err := node.Up(); err != nil {
|
||||
t.Fatalf("Up : %v", err)
|
||||
}
|
||||
|
||||
ctx := context.Background()
|
||||
owner, err := node.Identity().CreatePrincipal(ctx, identity.CreatePrincipalParams{
|
||||
Kind: identity.KindUser,
|
||||
Name: "alice",
|
||||
})
|
||||
if err != nil {
|
||||
t.Fatalf("CreatePrincipal : %v", err)
|
||||
}
|
||||
|
||||
policyID := ident.MustParse("00000000-0000-7000-8000-000000000101")
|
||||
|
||||
library, err := node.Documents().CreateLibrary(ctx, document.CreateLibraryParams{
|
||||
OwnerID: owner.ID,
|
||||
CreatedBy: owner.ID,
|
||||
Name: "Photos",
|
||||
PolicyID: policyID,
|
||||
})
|
||||
if err != nil {
|
||||
t.Fatalf("CreateLibrary : %v", err)
|
||||
}
|
||||
if library.Kind != document.KindLibrary {
|
||||
t.Fatalf("kind = %q, attendu %q", library.Kind, document.KindLibrary)
|
||||
}
|
||||
|
||||
folder, err := node.Documents().CreateFolder(ctx, document.CreateFolderParams{
|
||||
OwnerID: owner.ID,
|
||||
CreatedBy: owner.ID,
|
||||
ParentID: library.ID,
|
||||
Name: "Vacances",
|
||||
})
|
||||
if err != nil {
|
||||
t.Fatalf("CreateFolder : %v", err)
|
||||
}
|
||||
if folder.ParentID == nil || *folder.ParentID != library.ID {
|
||||
t.Fatalf("parent = %v, attendu %s", folder.ParentID, library.ID)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user